openvidu/openvidu-browser/lib/OpenVidu/Session.d.ts

294 lines
15 KiB
TypeScript
Raw Normal View History

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';
import { Subscriber } from './Subscriber';
2018-07-11 11:47:53 +02:00
import { Capabilities } from '../OpenViduInternal/Interfaces/Public/Capabilities';
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';
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-07-11 11:47:53 +02:00
/**
* Object defining the methods that the client is able to call. These are defined by the role of the token used to connect to the Session.
* This object is only defined after [[Session.connect]] has been successfully resolved
*/
capabilities: Capabilities;
2018-04-26 15:33:47 +02:00
/**
* @hidden
*/
remoteStreamsCreated: ObjMap<boolean>;
2018-12-14 14:01:16 +01:00
/**
* @hidden
*/
isFirstIonicIosSubscriber: boolean;
/**
* @hidden
*/
countDownForIonicIosSubscribers: boolean;
2018-04-26 15:33:47 +02:00
/**
* @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.
2018-07-11 11:47:53 +02:00
* Call `event.preventDefault()` upon event `sessionDisconnected` to avoid this behavior and take care of disposing and cleaning all the Subscriber objects yourself.
2018-06-01 14:39:38 +02:00
* 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.
2018-07-11 11:47:53 +02:00
* Call `event.preventDefault()` upon 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()`
2018-06-01 14:39:38 +02:00
* 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.
2018-07-11 11:47:53 +02:00
* Call `event.preventDefault()` upon event `streamDestroyed` to avoid this default behavior and take care of disposing and cleaning the Subscriber object yourself.
2018-06-01 14:39:38 +02:00
* 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.
2018-07-11 11:47:53 +02:00
* Call `event.preventDefault()` upon 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.
2018-07-11 11:47:53 +02:00
* Call `event.preventDefault()` upon event `streamDestroyed` to avoid this default behavior 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-07-11 11:47:53 +02:00
/**
* Forces some user to leave the session
*
* #### Events dispatched
*
* The behavior is the same as when some user calls [[Session.disconnect]], but `reason` property in all events will be `"forceDisconnectByUser"`.
*
* The [[Session]] object of every participant will dispatch a `streamDestroyed` event if the evicted user was publishing a stream, with property `reason` set to `"forceDisconnectByUser"`.
* The [[Session]] object of every participant except the evicted one will dispatch a `connectionDestroyed` event for the evicted user, with property `reason` set to `"forceDisconnectByUser"`.
*
* If any, the [[Publisher]] object of the evicted participant will also dispatch a `streamDestroyed` event with property `reason` set to `"forceDisconnectByUser"`.
* The [[Session]] object of the evicted participant will dispatch a `sessionDisconnected` event with property `reason` set to `"forceDisconnectByUser"`.
*
* See [[StreamEvent]], [[ConnectionEvent]] and [[SessionDisconnectedEvent]] to learn more.
*
* @returns A Promise (to which you can optionally subscribe to) that is resolved only after the participant has been successfully evicted from the session and rejected with an Error object if not
*/
forceDisconnect(connection: Connection): Promise<any>;
/**
* Forces some user to unpublish a Stream
*
* #### Events dispatched
*
* The behavior is the same as when some user calls [[Session.unpublish]], but `reason` property in all events will be `"forceUnpublishByUser"`
*
* The [[Session]] object of every participant will dispatch a `streamDestroyed` event with property `reason` set to `"forceDisconnectByUser"`
*
* The [[Publisher]] object of the affected participant will also dispatch a `streamDestroyed` event with property `reason` set to `"forceDisconnectByUser"`
*
* See [[StreamEvent]] to learn more.
*
* @returns A Promise (to which you can optionally subscribe to) that is resolved only after the remote Stream has been successfully unpublished from the session and rejected with an Error object if not
*/
forceUnpublish(stream: Stream): Promise<any>;
2018-04-26 15:33:47 +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
*
* @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
*/
signal(signal: SignalOptions): Promise<any>;
2018-04-26 15:33:47 +02:00
/**
* See [[EventDispatcher.on]]
*/
on(type: string, handler: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent) => void): EventDispatcher;
2018-04-26 15:33:47 +02:00
/**
* See [[EventDispatcher.once]]
*/
once(type: string, handler: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent) => void): Session;
2018-04-26 15:33:47 +02:00
/**
* See [[EventDispatcher.off]]
*/
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;
2018-07-11 11:47:53 +02:00
/**
* @hidden
*/
onStreamPropertyChanged(msg: any): void;
2018-04-26 15:33:47 +02:00
/**
* @hidden
*/
recvIceCandidate(msg: any): void;
/**
* @hidden
*/
onSessionClosed(msg: any): void;
/**
* @hidden
*/
onLostConnection(): void;
2018-07-11 11:47:53 +02:00
/**
* @hidden
*/
onRecoveredConnection(): void;
2018-04-26 15:33:47 +02:00
/**
* @hidden
*/
onMediaError(params: any): void;
/**
* @hidden
*/
onRecordingStarted(response: any): void;
/**
* @hidden
*/
onRecordingStopped(response: any): void;
/**
* @hidden
* response = {connectionId: string, streamId: string, type: string, data: Object}
*/
onFilterEventDispatched(response: any): void;
2018-04-26 15:33:47 +02:00
/**
* @hidden
*/
emitEvent(type: string, eventArray: any[]): void;
/**
* @hidden
*/
leave(forced: boolean, reason: string): void;
private connectAux;
2018-07-11 11:47:53 +02:00
private stopPublisherStream;
private stringClientMetadata;
private getConnection;
private getRemoteConnection;
private processToken;
2018-04-26 15:33:47 +02:00
}