2018-05-08 13:01:34 +02:00
|
|
|
import { Connection } from './Connection';
|
|
|
|
import { OpenVidu } from './OpenVidu';
|
|
|
|
import { Publisher } from './Publisher';
|
|
|
|
import { Stream } from './Stream';
|
2018-06-01 14:39:38 +02:00
|
|
|
import { StreamManager } from './StreamManager';
|
2018-05-08 13:01:34 +02:00
|
|
|
import { Subscriber } from './Subscriber';
|
2018-04-26 15:33:47 +02:00
|
|
|
import { EventDispatcher } from '../OpenViduInternal/Interfaces/Public/EventDispatcher';
|
|
|
|
import { SignalOptions } from '../OpenViduInternal/Interfaces/Public/SignalOptions';
|
|
|
|
import { SubscriberProperties } from '../OpenViduInternal/Interfaces/Public/SubscriberProperties';
|
|
|
|
import { ConnectionOptions } from '../OpenViduInternal/Interfaces/Private/ConnectionOptions';
|
|
|
|
import { ObjMap } from '../OpenViduInternal/Interfaces/Private/ObjMap';
|
|
|
|
import { SessionOptions } from '../OpenViduInternal/Interfaces/Private/SessionOptions';
|
|
|
|
import { ConnectionEvent } from '../OpenViduInternal/Events/ConnectionEvent';
|
|
|
|
import { PublisherSpeakingEvent } from '../OpenViduInternal/Events/PublisherSpeakingEvent';
|
2018-04-27 11:08:03 +02:00
|
|
|
import { RecordingEvent } from '../OpenViduInternal/Events/RecordingEvent';
|
2018-04-26 15:33:47 +02:00
|
|
|
import { SessionDisconnectedEvent } from '../OpenViduInternal/Events/SessionDisconnectedEvent';
|
|
|
|
import { SignalEvent } from '../OpenViduInternal/Events/SignalEvent';
|
|
|
|
import { StreamEvent } from '../OpenViduInternal/Events/StreamEvent';
|
|
|
|
/**
|
|
|
|
* Represents a video call. It can also be seen as a videoconference room where multiple users can connect.
|
2018-06-01 14:39:38 +02:00
|
|
|
* Participants who publish their videos to a session can be seen by the rest of users connected to that specific session.
|
2018-04-26 15:33:47 +02:00
|
|
|
* Initialized with [[OpenVidu.initSession]] method
|
|
|
|
*/
|
|
|
|
export declare class Session implements EventDispatcher {
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
connection: Connection;
|
|
|
|
/**
|
2018-06-01 14:39:38 +02:00
|
|
|
* Unique identifier of the Session
|
2018-04-26 15:33:47 +02:00
|
|
|
*/
|
|
|
|
sessionId: string;
|
2018-06-01 14:39:38 +02:00
|
|
|
/**
|
|
|
|
* Collection of all StreamManagers of this Session ([[Publisher]] and [[Subscriber]])
|
|
|
|
*/
|
|
|
|
streamManagers: StreamManager[];
|
2018-04-26 15:33:47 +02:00
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
remoteStreamsCreated: ObjMap<boolean>;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
remoteConnections: ObjMap<Connection>;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
openvidu: OpenVidu;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
options: SessionOptions;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
speakingEventsEnabled: boolean;
|
|
|
|
private ee;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
2018-05-03 11:48:57 +02:00
|
|
|
constructor(openvidu: OpenVidu);
|
2018-04-26 15:33:47 +02:00
|
|
|
connect(token: string): Promise<any>;
|
|
|
|
connect(token: string, metadata: any): Promise<any>;
|
|
|
|
/**
|
|
|
|
* 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)
|
2018-06-01 14:39:38 +02:00
|
|
|
* and also deletes any HTML video element associated to each Subscriber (only those [created by OpenVidu Browser](/docs/how-do-i/manage-videos/#let-openvidu-take-care-of-the-video-players)).
|
|
|
|
* For every video removed, each Subscriber object will dispatch a `videoElementDestroyed` event.
|
|
|
|
* Call `event.preventDefault()` uppon event `sessionDisconnected` to avoid this behaviour and take care of disposing and cleaning all the Subscriber objects yourself.
|
|
|
|
* See [[SessionDisconnectedEvent]] and [[VideoElementEvent]] to learn more to learn more.
|
2018-04-26 15:33:47 +02:00
|
|
|
*
|
|
|
|
* The [[Publisher]] object of the local participant will dispatch a `streamDestroyed` event if there is a [[Publisher]] object publishing to the session.
|
2018-06-01 14:39:38 +02:00
|
|
|
* This event will automatically stop all media tracks and delete any HTML video element associated to it (only those [created by OpenVidu Browser](/docs/how-do-i/manage-videos/#let-openvidu-take-care-of-the-video-players)).
|
|
|
|
* For every video removed, the Publisher object will dispatch a `videoElementDestroyed` event.
|
|
|
|
* Call `event.preventDefault()` uppon event `streamDestroyed` if you want to clean the Publisher object on your own 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]] and [[VideoElementEvent]] to learn more.
|
2018-04-26 15:33:47 +02:00
|
|
|
*
|
|
|
|
* 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)
|
2018-06-01 14:39:38 +02:00
|
|
|
* and also deletes any HTML video element associated to that Subscriber (only those [created by OpenVidu Browser](/docs/how-do-i/manage-videos/#let-openvidu-take-care-of-the-video-players)).
|
|
|
|
* For every video removed, the Subscriber object will dispatch a `videoElementDestroyed` event.
|
|
|
|
* Call `event.preventDefault()` uppon event `streamDestroyed` to avoid this default behaviour and take care of disposing and cleaning the Subscriber object yourself.
|
|
|
|
* See [[StreamEvent]] and [[VideoElementEvent]] to learn more.
|
2018-04-26 15:33:47 +02:00
|
|
|
*
|
|
|
|
* The [[Session]] object of every other participant connected to the session will dispatch a `connectionDestroyed` event in any case. See [[ConnectionEvent]] to learn more.
|
|
|
|
*/
|
|
|
|
disconnect(): void;
|
|
|
|
subscribe(stream: Stream, targetElement: string | HTMLElement): Subscriber;
|
|
|
|
subscribe(stream: Stream, targetElement: string | HTMLElement, properties: SubscriberProperties): Subscriber;
|
|
|
|
subscribe(stream: Stream, targetElement: string | HTMLElement, completionHandler: (error: Error | undefined) => void): Subscriber;
|
|
|
|
subscribe(stream: Stream, targetElement: string | HTMLElement, properties: SubscriberProperties, completionHandler: (error: Error | undefined) => void): Subscriber;
|
|
|
|
/**
|
|
|
|
* Promisified version of [[Session.subscribe]]
|
|
|
|
*/
|
|
|
|
subscribeAsync(stream: Stream, targetElement: string | HTMLElement): Promise<Subscriber>;
|
|
|
|
subscribeAsync(stream: Stream, targetElement: string | HTMLElement, properties: SubscriberProperties): Promise<Subscriber>;
|
|
|
|
/**
|
2018-06-01 14:39:38 +02:00
|
|
|
* Unsubscribes from `subscriber`, automatically removing its associated HTML video elements.
|
2018-04-26 15:33:47 +02:00
|
|
|
*
|
|
|
|
* #### Events dispatched
|
|
|
|
*
|
2018-06-01 14:39:38 +02:00
|
|
|
* The [[Subscriber]] object will dispatch a `videoElementDestroyed` event for each video associated to it that was removed from DOM.
|
|
|
|
* Only videos [created by OpenVidu Browser](/docs/how-do-i/manage-videos/#let-openvidu-take-care-of-the-video-players)) will be automatically removed
|
|
|
|
*
|
|
|
|
* See [[VideoElementEvent]] to learn more
|
2018-04-26 15:33:47 +02:00
|
|
|
*/
|
|
|
|
unsubscribe(subscriber: Subscriber): void;
|
|
|
|
/**
|
2018-06-01 14:39:38 +02:00
|
|
|
* Publishes to the Session the Publisher object
|
2018-04-26 15:33:47 +02:00
|
|
|
*
|
|
|
|
* #### Events dispatched
|
|
|
|
*
|
|
|
|
* The local [[Publisher]] object will dispatch a `streamCreated` event upon successful termination of this method. See [[StreamEvent]] to learn more.
|
|
|
|
*
|
2018-06-01 14:39:38 +02:00
|
|
|
* The local [[Publisher]] object will dispatch a `streamPlaying` once the media stream starts playing. See [[StreamManagerEvent]] to learn more.
|
2018-04-26 15:33:47 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2018-06-01 14:39:38 +02:00
|
|
|
* @returns A Promise (to which you can optionally subscribe to) that is resolved only after the publisher was successfully published and rejected with an Error object if not
|
2018-04-26 15:33:47 +02:00
|
|
|
*/
|
|
|
|
publish(publisher: Publisher): Promise<any>;
|
|
|
|
/**
|
2018-06-01 14:39:38 +02:00
|
|
|
* Unpublishes from the Session the Publisher object.
|
2018-04-26 15:33:47 +02:00
|
|
|
*
|
|
|
|
* #### Events dispatched
|
|
|
|
*
|
|
|
|
* The [[Publisher]] object of the local participant will dispatch a `streamDestroyed` event.
|
2018-06-01 14:39:38 +02:00
|
|
|
* This event will automatically stop all media tracks and delete any HTML video element associated to this Publisher
|
|
|
|
* (only those videos [created by OpenVidu Browser](/docs/how-do-i/manage-videos/#let-openvidu-take-care-of-the-video-players)).
|
|
|
|
* For every video removed, the Publisher object will dispatch a `videoElementDestroyed` event.
|
|
|
|
* Call `event.preventDefault()` uppon event `streamDestroyed` if you want to clean the Publisher object on your own or re-publish it in a different Session.
|
2018-04-26 15:33:47 +02:00
|
|
|
*
|
|
|
|
* The [[Session]] object of every other participant connected to the session will dispatch a `streamDestroyed` event.
|
2018-06-01 14:39:38 +02:00
|
|
|
* This event will automatically unsubscribe the Subscriber object from the session (this includes closing the WebRTCPeer connection and disposing all MediaStreamTracks) and
|
|
|
|
* delete any HTML video element associated to it (only those [created by OpenVidu Browser](/docs/how-do-i/manage-videos/#let-openvidu-take-care-of-the-video-players)).
|
|
|
|
* For every video removed, the Subscriber object will dispatch a `videoElementDestroyed` event.
|
|
|
|
* Call `event.preventDefault()` uppon event `streamDestroyed` to avoid this default behaviour and take care of disposing and cleaning the Subscriber object on your own.
|
2018-04-26 15:33:47 +02:00
|
|
|
*
|
2018-06-01 14:39:38 +02:00
|
|
|
* See [[StreamEvent]] and [[VideoElementEvent]] to learn more.
|
2018-04-26 15:33:47 +02:00
|
|
|
*/
|
|
|
|
unpublish(publisher: Publisher): void;
|
|
|
|
/**
|
2018-05-08 10:40:46 +02:00
|
|
|
* Sends one signal. `signal` object has the following optional properties:
|
|
|
|
* ```json
|
|
|
|
* {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.
|
2018-04-26 15:33:47 +02:00
|
|
|
*
|
2018-05-08 10:40:46 +02:00
|
|
|
* @returns 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._
|
2018-04-26 15:33:47 +02:00
|
|
|
*/
|
2018-05-08 10:40:46 +02:00
|
|
|
signal(signal: SignalOptions): Promise<any>;
|
2018-04-26 15:33:47 +02:00
|
|
|
/**
|
|
|
|
* See [[EventDispatcher.on]]
|
|
|
|
*/
|
2018-04-27 11:08:03 +02:00
|
|
|
on(type: string, handler: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent) => void): EventDispatcher;
|
2018-04-26 15:33:47 +02:00
|
|
|
/**
|
|
|
|
* See [[EventDispatcher.once]]
|
|
|
|
*/
|
2018-04-27 11:08:03 +02:00
|
|
|
once(type: string, handler: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent) => void): Session;
|
2018-04-26 15:33:47 +02:00
|
|
|
/**
|
|
|
|
* See [[EventDispatcher.off]]
|
|
|
|
*/
|
2018-04-27 11:08:03 +02:00
|
|
|
off(type: string, handler?: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent) => void): Session;
|
2018-04-26 15:33:47 +02:00
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
onParticipantJoined(response: ConnectionOptions): void;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
onParticipantLeft(msg: any): void;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
onParticipantPublished(response: ConnectionOptions): void;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
onParticipantUnpublished(msg: any): void;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
onParticipantEvicted(msg: any): void;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
onNewMessage(msg: any): void;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
recvIceCandidate(msg: any): void;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
onSessionClosed(msg: any): void;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
onLostConnection(): void;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
onMediaError(params: any): void;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
onRecordingStarted(response: any): void;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
onRecordingStopped(response: any): void;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
emitEvent(type: string, eventArray: any[]): void;
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
leave(forced: boolean, reason: string): void;
|
2018-06-04 14:33:57 +02:00
|
|
|
private connectAux;
|
|
|
|
private stringClientMetadata;
|
|
|
|
private getConnection;
|
|
|
|
private getRemoteConnection;
|
|
|
|
private processToken;
|
2018-04-26 15:33:47 +02:00
|
|
|
}
|