<commit_before># BuddyTok

An OpenTok 1-to-1 solution focussed on adding presence to an application


## Installation

1. Clone the repository.

2. Copy the `config/development/opentok.php.sample` file to `config/development/opentok.php` and
   replace the `key` and `secret` settings with your OpenTok API key and secret, from the [TokBox
   Dashboard](https://dashboard.tokbox.com). Also, generate one relayed session (you may use the
   Project Tools in the Dashboard) and use the Session ID to replace the`presenceSession` setting.

3. Use [Composer](https://getcomposer.org/) to install dependencies: `composer install`

4. Set the document root for your web server (such as Apache, nginx, etc.) to the `web` directory
   of this project. In the case of Apache, the provided `web\.htaccess` file handles URL rewriting.
   See the [Slim Route URL Rewriting Guide](http://docs.slimframework.com/#Route-URL-Rewriting)
   for more details.

## Usage

1. Visit the URL mapped to the application by your web server.

2. Input a name to be identified with. You will now see a list of available users, which will start
   as empty.

3. Have another user (possibly in another window or tab) visit the same URL, and input a new user
   name.

   Each of the users will see one another in the Buddies list.

4. In order to start a chat with an available user, click the camera icon next to the user's name.

   A user who has sent an invitation cannot receive invitations from other users. Unavailable users
   do not have a camera icon next to their name in the Buddies list.

   While waiting for a response to an invitation, the user can use the "cancel" button to stop the
   invitation.

5. An invited user receives an invitation to chat, which they can either accept or decline.
   If accepted, the chat begins. If declined, the invitation disappears.

   An invited user can continue to receive invitations from other users. If the user accepts an
   invitation, all other invitations are automatically declined.

6. Once either of the users chooses to "end chat," both users will return to being available.

## Code and Conceptual Walkthrough

### Technologies

This application uses some of the same frameworks and libraries as the
[HelloWorld](https://github.com/opentok/OpenTok-PHP-SDK/tree/master/sample/HelloWorld) sample. If
you have not already gotten familiar with the code in that project, consider doing so before
continuing. Slim is a minimalistic PHP framework, so its patterns can be applied to other
frameworks and even other languages.

In addition, the app uses [Backbone.js](http://documentcloud.github.io/backbone/) library for
client-side functionality. It is a basic MV* library, and while it's helpful in laying some
groundwork for the client, the same functionality could be achieved with other libraries and
frameworks or even with no framework at all. Along with Backbone, the client makes use of its
dependencies: [jQuery](http://jquery.com/), and [Lodash](http://lodash.com/). Lodash is a library
that is compatible with Underscore.js but has better performance, and it is also used for view
templating.

Lastly, the app uses [Bootstrap](http://getbootstrap.com/) is used to help style the UI and for
reusable components, such as buttons and modals.

### Concepts

Each user needs to be aware of the state of each of the other users -- this is known as _presence_.
This application approaches this from a distributed point of view, which means there is no central
authority required and there's less overhead in storing each user's state. The implementation
requires a basic messaging channel where each user and the whole group can be addressed. OpenTok
includes that exact functionality for clients via the signaling API. This application uses a
**presence session**, a global session which every client connects to in order to communicate
presence information. No video streaming is done in this session.

Each client uses the presence session to build a list of the other users and keep it synchronized
as users' states change. A **remote user** is the representation of another user and its state.
This list of remote users is called the **buddies list**. When a user joins the app (adding a user
name), that client sends a signal to the presence session with details about the user. Each other
user stores the remote user's data and state.

A **local user** is the user who is using the application in the local browser.<commit_msg>Minor docs edit.<commit_after># BuddyTok

An OpenTok 1-to-1 solution focussed on adding presence to an application


## Installation

1. Clone the repository.

2. Copy the `config/development/opentok.php.sample` file to `config/development/opentok.php` and
   replace the `key` and `secret` settings with your OpenTok API key and secret, from the [TokBox
   Dashboard](https://dashboard.tokbox.com). Also, generate one relayed session (you may use the
   Project Tools in the Dashboard) and use the Session ID to replace the`presenceSession` setting.

3. Use [Composer](https://getcomposer.org/) to install dependencies: `composer install`

4. Set the document root for your web server (such as Apache, nginx, etc.) to the `web` directory
   of this project. In the case of Apache, the provided `web\.htaccess` file handles URL rewriting.
   See the [Slim Route URL Rewriting Guide](http://docs.slimframework.com/#Route-URL-Rewriting)
   for more details.

## Usage

1. Visit the URL mapped to the application by your web server.

2. Input a name to be identified with. You will now see a list of available users, which will start
   as empty.

3. Have another user (possibly in another window or tab) visit the same URL, and input a new user
   name.

   Each of the users will see one another in the Buddies list.

4. In order to start a chat with an available user, click the camera icon next to the user's name.

   A user who has sent an invitation cannot receive invitations from other users. Unavailable users
   do not have a camera icon next to their name in the Buddies list.

   While waiting for a response to an invitation, the user can use the "cancel" button to stop the
   invitation.

5. An invited user receives an invitation to chat, which they can either accept or decline.
   If accepted, the chat begins. If declined, the invitation disappears.

   An invited user can continue to receive invitations from other users. If the user accepts an
   invitation, all other invitations are automatically declined.

6. Once either of the users chooses to "end chat," both users will return to being available.

## Code and Conceptual Walkthrough

### Technologies

This application uses some of the same frameworks and libraries as the
[HelloWorld](https://github.com/opentok/OpenTok-PHP-SDK/tree/master/sample/HelloWorld) sample. If
you have not already gotten familiar with the code in that project, consider doing so before
continuing. Slim is a minimalistic PHP framework, so its patterns can be applied to other
frameworks and even other languages.

In addition, the app uses [Backbone.js](http://documentcloud.github.io/backbone/) library for
client-side functionality. It is a basic MV* library, and while it's helpful in laying some
groundwork for the client, the same functionality could be achieved with other libraries and
frameworks or even with no framework at all. Along with Backbone, the client makes use of its
dependencies: [jQuery](http://jquery.com/), and [Lodash](http://lodash.com/). Lodash is a library
that is compatible with Underscore.js but has better performance, and it is also used for view
templating.

Lastly, the app uses [Bootstrap](http://getbootstrap.com/) to help style the UI and for reusable
components, such as buttons and modals.

### Concepts

Each user needs to be aware of the state of each of the other users -- this is known as _presence_.
This application approaches this from a distributed point of view, which means there is no central
authority required and there's less overhead in storing each user's state. The implementation
requires a basic messaging channel where each user and the whole group can be addressed. OpenTok
includes that exact functionality for clients via the signaling API. This application uses a
**presence session**, a global session which every client connects to in order to communicate
presence information. No video streaming is done in this session.

Each client uses the presence session to build a list of the other users and keep it synchronized
as users' states change. A **remote user** is the representation of another user and its state.
This list of remote users is called the **buddies list**. When a user joins the app (adding a user
name), that client sends a signal to the presence session with details about the user. Each other
user stores the remote user's data and state.

A **local user** is the user who is using the application in the local browser.
{'fraction_non_alphanumeric': 0.05589783801949143, 'fraction_numerical': 0.002688473171278145, 'mean_word_length': 4.166666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3032863', 'n_tokens_mistral': 2276, 'n_tokens_neox': 2204, 'n_words': 1343}