<commit_before># Session

A Session object can be thought of as a collection of streams on which you may operate (publish or subscribe), or more simply as a "room". 
You can construct this object using [opentok.createSession(props)](opentok.md#createsessionprops). A [sessionId can be dynamically created](http://www.tokbox.com/opentok/api/tools/js/documentation/overview/session_creation.html) by your backend web service.
This object is analogous to the [JS API Session](http://www.tokbox.com/opentok/api/tools/js/documentation/api/Session.html) object.

<nav>
  <table>
    <tr>
      <th>Methods</th>
      <th>Properties</th>
      <th>Events</th>
    </tr>
    <tr>
      <td><a href="#connectapikey-token">connect(apiKey, token)</a></td>
      <td><a href="#sessionid">sessionId</a></td>
      <td><a href="#sessionconnected">sessionConnected</a></td>
    </tr>
    <tr>
      <td><a href="#disconnect">disconnect()</a></td>
      <td><a href="#streams">streams</a></td>
      <td><a href="#sessiondisconnected">sessionDisconnected</a></td>
    </tr>
    <tr>
      <td><a href="#publishprops">publish(props)</a></td>
      <td><a href="#sessionconnectionstatus">sessionConnectionStatus</a></td>
      <td><a href="#sessionfailed">sessionFailed</a></td>
    </tr>
    <tr>
      <td><a href="#unpublish">unpublish()</a></td>
      <td><a href="#connectioncount">connectionCount</a></td>
      <td><a href="#streamcreated">streamCreated</a></td>
    </tr>
    <tr>
      <td><a href="#subscribestream-props">subscribe(stream, props)</a></td>
      <td><a href="#environment">environment</a></td>
      <td><a href="#streamdestroyed">streamDestroyed</a></td>
    </tr>
  </table>
</nav>

## Methods

### connect(_apiKey_, _token_)

Connect to an OpenTok session. This must be done before you can do anything else with a session.

Parameters:
*  _apiKey_ (String) _required_ - OpenTok API Key. Get one [here](http://www.tokbox.com/opentok/api/tools/js/apikey)
*  _token_ (String) _required_ - User Token. This is generated by a server-side SDK.

Returns: (void)

### disconnect()

Disconnect to an OpenTok session.

Returns: (void)

### publish(_props_)

Begin publishing video data from the device's camera to the Session. When the publisher begins streaming data, the Session dispatches
a ["streamCreated"](#streamcreated) event. You can compare the [connection.connectionId](connection.md#connectionid) property of the Session object with the stream.connection.connectionId
property of the "streamCreated" event object. If they match, the stream is published from your own connection.

Note that multiple publishers are not supported.

Parameters:
*  _props_ (Dictionary) _optional_:
   *  _name_ (String) _optional_ - A name for the stream being created in the Session. The name is readable to others connected to the Session. Defaults to device name.
   *  _publishAudio_ (Boolean) _optional_ - Whether or not the publisher sends audio. Defaults to true.
   *  _publishVideo_ (Boolean) _optional_ - Whether or not the publisher sends video. Defaults to true.

Returns: (Publisher)

### unpublish()

Stop publishing to the session.

Returns: (void)

### subscribe(_stream_, _props_)

Begin receiving video data from another device's camera who is publishing to the Session.

Parameters:
*  _stream_ (Stream) _required_ - A Stream object that refers to the video or audio data from a device.
*  _props_ (Dictionary) _optional_:
   *  _subscribeToAudio_ (Boolean) _optional_ - Whether or not to subscribe to the audio data. Defaults to true.
   *  _subscribeToVideo_ (Boolean) _optional_ - Whether or not to subscribe to the video data. Defaults to true.

Returns: (Subscriber)

## Properties

### sessionId

(String) The Session ID for this Session object. This is only writable before [session.connect(_apiKey_, _token_)](#connectapikey-token) is called.

### streams

(Array < Stream >) A collection of all the Streams currently in the Session. _Read Only_

### sessionConnectionStatus

(String) The state of the session. Possible values: "connected", "connecting", "disconnected", "failed". _Read Only_

### connectionCount

(Number) The number of connections in the Session. _Read Only_

### environment

(String) The OpenTok environment that the session will connect to. This is only writable when the [sessionConnectionStatus](#sessionconnectionstatus) is "disconnected".

## Events

### "sessionConnected"

This event is fired when the [session.connect(_apiKey_, _token_)](#connectapikey-token) call has resulted in a successful connection.

### "sessionDisconnected"<commit_msg>updates documentation to remove environment<commit_after># Session

A Session object can be thought of as a collection of streams on which you may operate (publish or subscribe), or more simply as a "room". 
You can construct this object using [opentok.createSession(props)](opentok.md#createsessionprops). A [sessionId can be dynamically created](http://www.tokbox.com/opentok/api/tools/js/documentation/overview/session_creation.html) by your backend web service.
This object is analogous to the [JS API Session](http://www.tokbox.com/opentok/api/tools/js/documentation/api/Session.html) object.

<nav>
  <table>
    <tr>
      <th>Methods</th>
      <th>Properties</th>
      <th>Events</th>
    </tr>
    <tr>
      <td><a href="#connectapikey-token">connect(apiKey, token)</a></td>
      <td><a href="#sessionid">sessionId</a></td>
      <td><a href="#sessionconnected">sessionConnected</a></td>
    </tr>
    <tr>
      <td><a href="#disconnect">disconnect()</a></td>
      <td><a href="#streams">streams</a></td>
      <td><a href="#sessiondisconnected">sessionDisconnected</a></td>
    </tr>
    <tr>
      <td><a href="#publishprops">publish(props)</a></td>
      <td><a href="#sessionconnectionstatus">sessionConnectionStatus</a></td>
      <td><a href="#sessionfailed">sessionFailed</a></td>
    </tr>
    <tr>
      <td><a href="#unpublish">unpublish()</a></td>
      <td><a href="#connectioncount">connectionCount</a></td>
      <td><a href="#streamcreated">streamCreated</a></td>
    </tr>
    <tr>
      <td><a href="#subscribestream-props">subscribe(stream, props)</a></td>
      <td><a href="#streamdestroyed">streamDestroyed</a></td>
    </tr>
  </table>
</nav>

## Methods

### connect(_apiKey_, _token_)

Connect to an OpenTok session. This must be done before you can do anything else with a session.

Parameters:
*  _apiKey_ (String) _required_ - OpenTok API Key. Get one [here](http://www.tokbox.com/opentok/api/tools/js/apikey)
*  _token_ (String) _required_ - User Token. This is generated by a server-side SDK.

Returns: (void)

### disconnect()

Disconnect to an OpenTok session.

Returns: (void)

### publish(_props_)

Begin publishing video data from the device's camera to the Session. When the publisher begins streaming data, the Session dispatches
a ["streamCreated"](#streamcreated) event. You can compare the [connection.connectionId](connection.md#connectionid) property of the Session object with the stream.connection.connectionId
property of the "streamCreated" event object. If they match, the stream is published from your own connection.

Note that multiple publishers are not supported.

Parameters:
*  _props_ (Dictionary) _optional_:
   *  _name_ (String) _optional_ - A name for the stream being created in the Session. The name is readable to others connected to the Session. Defaults to device name.
   *  _publishAudio_ (Boolean) _optional_ - Whether or not the publisher sends audio. Defaults to true.
   *  _publishVideo_ (Boolean) _optional_ - Whether or not the publisher sends video. Defaults to true.

Returns: (Publisher)

### unpublish()

Stop publishing to the session.

Returns: (void)

### subscribe(_stream_, _props_)

Begin receiving video data from another device's camera who is publishing to the Session.

Parameters:
*  _stream_ (Stream) _required_ - A Stream object that refers to the video or audio data from a device.
*  _props_ (Dictionary) _optional_:
   *  _subscribeToAudio_ (Boolean) _optional_ - Whether or not to subscribe to the audio data. Defaults to true.
   *  _subscribeToVideo_ (Boolean) _optional_ - Whether or not to subscribe to the video data. Defaults to true.

Returns: (Subscriber)

## Properties

### sessionId

(String) The Session ID for this Session object. This is only writable before [session.connect(_apiKey_, _token_)](#connectapikey-token) is called.

### streams

(Array < Stream >) A collection of all the Streams currently in the Session. _Read Only_

### sessionConnectionStatus

(String) The state of the session. Possible values: "connected", "connecting", "disconnected", "failed". _Read Only_

### connectionCount

(Number) The number of connections in the Session. _Read Only_

## Events

### "sessionConnected"

This event is fired when the [session.connect(_apiKey_, _token_)](#connectapikey-token) call has resulted in a successful connection.

### "sessionDisconnected"
{'fraction_non_alphanumeric': 0.12456824512534818, 'fraction_numerical': 0.0, 'mean_word_length': 4.4072289156626505, 'pattern_counts': {'":': 0, '<': 165, '<?xml version=': 0, '>': 165, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '628069', 'n_tokens_mistral': 2652, 'n_tokens_neox': 2588, 'n_words': 891}