Represents a video call. It can also be seen as a videoconference room where multiple users can connect. Participants who publish their videos to a session will be seen by the rest of users connected to that specific session. Initialized with OpenVidu.initSession method

### Hierarchy

- Session

### Implements

- EventDispatcher

## Index

### Properties

- connection
- sessionId

### Methods

- connect
- disconnect
- off
- on
- once
- publish
- signal
- subscribe
- subscribeAsync
- unpublish
- unsubscribe

## Properties

### connection

connection: Connection

- Defined in OpenVidu/Session.ts:49

Local connection to the Session. This object is defined only after Session.connect has been successfully executed, and can be retrieved subscribing to `connectionCreated` event

### sessionId

sessionId: string

- Defined in OpenVidu/Session.ts:54

Unique identifier of the Session. This is the same value you pass when calling OpenVidu.initSession

## Methods

### connect

- connect(token: string): Promise<any>
- connect(token: string, metadata: any): Promise<any>
- connect(token: string, metadata?: any, callback?: any): void

- - Defined in OpenVidu/Session.ts:88

  Connects to the session using `token`. Parameter `metadata` allows you to pass extra data to share with other users when they receive `streamCreated` event. The structure of `metadata` string is up to you (maybe some standarized format as JSON or XML is a good idea), the only restriction is a maximum length of 10000 chars.

  This metadata is not considered secure, as it is generated in the client side. To pass securized data, add it as a parameter in the token generation operation (through the API REST, openvidu-java-client or openvidu-node-client).

  Only after the returned Promise is successfully resolved Session.connection object will be available and properly defined.

  #### Events dispatched

  The Session object of the local participant will first dispatch one or more `connectionCreated` events upon successful termination of this method:

  - First one for your own local Connection object, so you can retrieve Session.connection property.
  - Then one for each remote Connection previously connected to the Session, if any. Any other remote user connecting to the Session after you have successfully connected will also dispatch a `connectionCreated` event when they do so.

  The Session object of the local participant will also dispatch a `streamCreated` event for each remote active Publisher after dispatching all remote `connectionCreated` events.

  The Session object of every other participant connected to the session will dispatch a `connectionCreated` event.

  See ConnectionEvent and StreamEvent to learn more.

  #### Parameters

  - ##### token: string

  #### Returns Promise<any>

  A Promise to which you must subscribe that is resolved if the recording successfully started and rejected with an Error object if not

- - Defined in OpenVidu/Session.ts:89

  Connects to the session using `token`. Parameter `metadata` allows you to pass extra data to share with other users when they receive `streamCreated` event. The structure of `metadata` string is up to you (maybe some standarized format as JSON or XML is a good idea), the only restriction is a maximum length of 10000 chars.

  This metadata is not considered secure, as it is generated in the client side. To pass securized data, add it as a parameter in the token generation operation (through the API REST, openvidu-java-client or openvidu-node-client).

  Only after the returned Promise is successfully resolved Session.connection object will be available and properly defined.

  #### Events dispatched

  The Session object of the local participant will first dispatch one or more `connectionCreated` events upon successful termination of this method:

  - First one for your own local Connection object, so you can retrieve Session.connection property.
  - Then one for each remote Connection previously connected to the Session, if any. Any other remote user connecting to the Session after you have successfully connected will also dispatch a `connectionCreated` event when they do so.

  The Session object of the local participant will also dispatch a `streamCreated` event for each remote active Publisher after dispatching all remote `connectionCreated` events.

  The Session object of every other participant connected to the session will dispatch a `connectionCreated` event.

  See ConnectionEvent and StreamEvent to learn more.

  #### Parameters

  - ##### token: string

  - ##### metadata: any

  #### Returns Promise<any>

  A Promise to which you must subscribe that is resolved if the recording successfully started and rejected with an Error object if not

- - Defined in OpenVidu/Session.ts:99

  ## DEPRECATED

  Use promisified version of the method

  #### Parameters

  - ##### token: string

  - ##### Optional metadata: any

  - ##### Optional callback: any

  #### Returns void

  A Promise to which you must subscribe that is resolved if the recording successfully started and rejected with an Error object if not

### disconnect

- disconnect(): void

- - Defined in OpenVidu/Session.ts:181

  Leaves the session, destroying all streams and deleting the user as a participant.

  #### Events dispatched

  The Session object of the local participant will dispatch a `sessionDisconnected` event. This event will automatically unsubscribe the leaving participant from every Subscriber object of the session (this includes closing the WebRTCPeer connection and disposing all MediaStreamTracks) and also delete the HTML video element associated to it. Call `event.preventDefault()` to avoid this beahviour and take care of disposing and cleaning all the Subscriber objects yourself. See SessionDisconnectedEvent to learn more.

  The Publisher object of the local participant will dispatch a `streamDestroyed` event if there is a Publisher object publishing to the session. This event will automatically stop all media tracks and delete the HTML video element associated to it. Call `event.preventDefault()` if you want clean the Publisher object yourself or re-publish it in a different Session (to do so it is a mandatory requirement to call `Session.unpublish()` or/and `Session.disconnect()` in the previous session). See StreamEvent to learn more.

  The Session object of every other participant connected to the session will dispatch a `streamDestroyed` event if the disconnected participant was publishing. This event will automatically unsubscribe the Subscriber object from the session (this includes closing the WebRTCPeer connection and disposing all MediaStreamTracks) and delete the HTML video element associated to it. Call `event.preventDefault()` to avoid this default behaviour and take care of disposing and cleaning the Subscriber object yourself. See StreamEvent to learn more.

  The Session object of every other participant connected to the session will dispatch a `connectionDestroyed` event in any case. See ConnectionEvent to learn more.

  #### Returns void

### off

- off(type: string, handler?: function): Session

- - Defined in OpenVidu/Session.ts:525

  See EventDispatcher.off

  #### Parameters

  - ##### type: string

  - ##### Optional handler: function

    - - (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent): void

      - #### Parameters

        - ##### event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent

        #### Returns void

  #### Returns Session

### on

- on(type: string, handler: function): EventDispatcher

- - Defined in OpenVidu/Session.ts:467

  See EventDispatcher.on

  #### Parameters

  - ##### type: string

  - ##### handler: function

    - - (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent): void

      - #### Parameters

        - ##### event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent

        #### Returns void

  #### Returns EventDispatcher

### once

- once(type: string, handler: function): Session

- - Defined in OpenVidu/Session.ts:496

  See EventDispatcher.once

  #### Parameters

  - ##### type: string

  - ##### handler: function

    - - (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent): void

      - #### Parameters

        - ##### event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent

        #### Returns void

  #### Returns Session

### publish

- publish(publisher: Publisher): Promise<any>

- - Defined in OpenVidu/Session.ts:320

  Publishes the participant's audio-video stream contained in `publisher` object to the session

  #### Events dispatched

  The local Publisher object will dispatch a `streamCreated` event upon successful termination of this method. See StreamEvent to learn more.

  The local Publisher object will dispatch a `remoteVideoPlaying` event only if Publisher.subscribeToRemote was called before this method, once the remote video starts playing. See VideoElementEvent to learn more.

  The Session object of every other participant connected to the session will dispatch a `streamCreated` event so they can subscribe to it. See StreamEvent to learn more.

  #### Parameters

  - ##### publisher: Publisher

  #### Returns Promise<any>

  A Promise (to which you can optionally subscribe to) that is resolved if the publisher was successfully published and rejected with an Error object if not

### signal

- signal(signal: SignalOptions): Promise<any>
- signal(signal: SignalOptions, callback?: any): void

- - Defined in OpenVidu/Session.ts:403

  Sends one signal. `signal` object has the following optional properties:

      {data:string, to:Connection[], type:string}

  All users subscribed to that signal (`session.on('signal:type', ...)` or `session.on('signal', ...)` for all signals) and whose Connection objects are in `to` array will receive it. Their local Session objects will dispatch a `signal` or `signal:type` event. See SignalEvent to learn more.

  #### Parameters

  - ##### signal: SignalOptions

  #### Returns Promise<any>

  A Promise (to which you can optionally subscribe to) that is resolved if the message successfully reached openvidu-server and rejected with an Error object if not. This doesn't mean that openvidu-server could resend the message to all the listed receivers.

- - Defined in OpenVidu/Session.ts:412

  ## DEPRECATED

  Use promisified version of the method

  #### Parameters

  - ##### signal: SignalOptions

  - ##### Optional callback: any

  #### Returns void

  A Promise (to which you can optionally subscribe to) that is resolved if the message successfully reached openvidu-server and rejected with an Error object if not. This doesn't mean that openvidu-server could resend the message to all the listed receivers.

### subscribe

- subscribe(stream: Stream, targetElement: string | HTMLElement): Subscriber
- subscribe(stream: Stream, targetElement: string | HTMLElement, properties: SubscriberProperties): Subscriber
- subscribe(stream: Stream, targetElement: string | HTMLElement, completionHandler: function): Subscriber
- subscribe(stream: Stream, targetElement: string | HTMLElement, properties: SubscriberProperties, completionHandler: function): Subscriber

- - Defined in OpenVidu/Session.ts:185

  Subscribes to a `stream`, adding a new HTML video element to DOM with `subscriberProperties` settings. This method is usually called in the callback of `streamCreated` event.

  #### Events dispatched

  The Subscriber object will dispatch a `videoElementCreated` event once the HTML video element has been added to DOM (if targetElement not null or undefined)

  The Subscriber object will dispatch a `videoPlaying` event once the remote video starts playing (only if `videoElementCreated` event has been previously dispatched)

  See VideoElementEvent to learn more.

  #### Parameters

  - ##### stream: Stream

    Stream object to subscribe to

  - ##### targetElement: string | HTMLElement

    HTML DOM element (or its `id` attribute) in which the video element of the Subscriber will be inserted (see SubscriberProperties.insertMode). If null or undefined no default video will be created for this Subscriber (you can always access the native MediaStream object by calling Subscriber.stream.getMediaStream() and use it as srcObject of any HTML video element)

  #### Returns Subscriber

- - Defined in OpenVidu/Session.ts:186

  Subscribes to a `stream`, adding a new HTML video element to DOM with `subscriberProperties` settings. This method is usually called in the callback of `streamCreated` event.

  #### Events dispatched

  The Subscriber object will dispatch a `videoElementCreated` event once the HTML video element has been added to DOM (if targetElement not null or undefined)

  The Subscriber object will dispatch a `videoPlaying` event once the remote video starts playing (only if `videoElementCreated` event has been previously dispatched)

  See VideoElementEvent to learn more.

  #### Parameters

  - ##### stream: Stream

    Stream object to subscribe to

  - ##### targetElement: string | HTMLElement

    HTML DOM element (or its `id` attribute) in which the video element of the Subscriber will be inserted (see SubscriberProperties.insertMode). If null or undefined no default video will be created for this Subscriber (you can always access the native MediaStream object by calling Subscriber.stream.getMediaStream() and use it as srcObject of any HTML video element)

  - ##### properties: SubscriberProperties

  #### Returns Subscriber

- - Defined in OpenVidu/Session.ts:187

  Subscribes to a `stream`, adding a new HTML video element to DOM with `subscriberProperties` settings. This method is usually called in the callback of `streamCreated` event.

  #### Events dispatched

  The Subscriber object will dispatch a `videoElementCreated` event once the HTML video element has been added to DOM (if targetElement not null or undefined)

  The Subscriber object will dispatch a `videoPlaying` event once the remote video starts playing (only if `videoElementCreated` event has been previously dispatched)

  See VideoElementEvent to learn more.

  #### Parameters

  - ##### stream: Stream

    Stream object to subscribe to

  - ##### targetElement: string | HTMLElement

    HTML DOM element (or its `id` attribute) in which the video element of the Subscriber will be inserted (see SubscriberProperties.insertMode). If null or undefined no default video will be created for this Subscriber (you can always access the native MediaStream object by calling Subscriber.stream.getMediaStream() and use it as srcObject of any HTML video element)

  - ##### completionHandler: function

    `error` parameter is null if `subscribe` succeeds, and is defined if it fails.

    - - (error: Error | undefined): void

      - #### Parameters

        - ##### error: Error | undefined

        #### Returns void

  #### Returns Subscriber

- - Defined in OpenVidu/Session.ts:188

  Subscribes to a `stream`, adding a new HTML video element to DOM with `subscriberProperties` settings. This method is usually called in the callback of `streamCreated` event.

  #### Events dispatched

  The Subscriber object will dispatch a `videoElementCreated` event once the HTML video element has been added to DOM (if targetElement not null or undefined)

  The Subscriber object will dispatch a `videoPlaying` event once the remote video starts playing (only if `videoElementCreated` event has been previously dispatched)

  See VideoElementEvent to learn more.

  #### Parameters

  - ##### stream: Stream

    Stream object to subscribe to

  - ##### targetElement: string | HTMLElement

    HTML DOM element (or its `id` attribute) in which the video element of the Subscriber will be inserted (see SubscriberProperties.insertMode). If null or undefined no default video will be created for this Subscriber (you can always access the native MediaStream object by calling Subscriber.stream.getMediaStream() and use it as srcObject of any HTML video element)

  - ##### properties: SubscriberProperties

  - ##### completionHandler: function

    `error` parameter is null if `subscribe` succeeds, and is defined if it fails.

    - - (error: Error | undefined): void

      - #### Parameters

        - ##### error: Error | undefined

        #### Returns void

  #### Returns Subscriber

### subscribeAsync

- subscribeAsync(stream: Stream, targetElement: string | HTMLElement): Promise<Subscriber>
- subscribeAsync(stream: Stream, targetElement: string | HTMLElement, properties: SubscriberProperties): Promise<Subscriber>

- - Defined in OpenVidu/Session.ts:252

  Promisified version of Session.subscribe

  #### Parameters

  - ##### stream: Stream

  - ##### targetElement: string | HTMLElement

  #### Returns Promise<Subscriber>

- - Defined in OpenVidu/Session.ts:253

  #### Parameters

  - ##### stream: Stream

  - ##### targetElement: string | HTMLElement

  - ##### properties: SubscriberProperties

  #### Returns Promise<Subscriber>

### unpublish

- unpublish(publisher: Publisher): void

- - Defined in OpenVidu/Session.ts:370

  Unpublishes the participant's audio-video stream contained in `publisher` object.

  #### Events dispatched

  The Publisher object of the local participant will dispatch a `streamDestroyed` event. This event will automatically stop all media tracks and delete the HTML video element associated to it. Call `event.preventDefault()` if you want clean the Publisher object yourself or re-publish it in a different Session.

  The Session object of every other participant connected to the session will dispatch a `streamDestroyed` event. This event will automatically unsubscribe the Subscriber object from the session (this includes closing the WebRTCPeer connection and disposing all MediaStreamTracks) and delete the HTML video element associated to it. Call `event.preventDefault()` to avoid this default behaviour and take care of disposing and cleaning the Subscriber object yourself.

  See StreamEvent to learn more.

  #### Parameters

  - ##### publisher: Publisher

  #### Returns void

### unsubscribe

- unsubscribe(subscriber: Subscriber): void

- - Defined in OpenVidu/Session.ts:285

  Unsubscribes from `subscriber`, automatically removing its HTML video element.

  #### Events dispatched

  The Subscriber object will dispatch a `videoElementDestroyed` event (only if it previously dispatched a `videoElementCreated` event). See VideoElementEvent to learn more

  #### Parameters

  - ##### subscriber: Subscriber

  #### Returns void

Generated using TypeDoc