@techsee/techsee-media-service 999.0.2-switch → 999.0.3-alpha2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/LocalStreamManager.d.ts +12 -0
- package/lib/LocalStreamManager.d.ts.map +1 -1
- package/lib/LocalStreamManager.js +440 -283
- package/lib/LocalStreamManager.js.map +1 -1
- package/lib/MediaConstants.d.ts +14 -4
- package/lib/MediaConstants.d.ts.map +1 -1
- package/lib/MediaConstants.js +83 -38
- package/lib/MediaConstants.js.map +1 -1
- package/lib/MediaContracts.d.ts +17 -14
- package/lib/MediaContracts.d.ts.map +1 -1
- package/lib/MediaContracts.js +3 -3
- package/lib/MediaContracts.js.map +1 -1
- package/lib/MediaPublisher.d.ts +3 -3
- package/lib/MediaPublisher.d.ts.map +1 -1
- package/lib/MediaPublisher.js +46 -35
- package/lib/MediaPublisher.js.map +1 -1
- package/lib/MediaServiceBase.d.ts +21 -7
- package/lib/MediaServiceBase.d.ts.map +1 -1
- package/lib/MediaServiceBase.js +924 -586
- package/lib/MediaServiceBase.js.map +1 -1
- package/lib/MediaSession/MediaServer.d.ts +45 -0
- package/lib/MediaSession/MediaServer.d.ts.map +1 -0
- package/lib/MediaSession/MediaServer.js +538 -0
- package/lib/MediaSession/MediaServer.js.map +1 -0
- package/lib/MediaSession/MediaSessionBase.d.ts +10 -1
- package/lib/MediaSession/MediaSessionBase.d.ts.map +1 -1
- package/lib/MediaSession/MediaSessionBase.js +128 -66
- package/lib/MediaSession/MediaSessionBase.js.map +1 -1
- package/lib/MediaSession/SessionOpentok.d.ts +11 -9
- package/lib/MediaSession/SessionOpentok.d.ts.map +1 -1
- package/lib/MediaSession/SessionOpentok.js +500 -352
- package/lib/MediaSession/SessionOpentok.js.map +1 -1
- package/lib/MediaSession/SessionTurn.d.ts +4 -1
- package/lib/MediaSession/SessionTurn.d.ts.map +1 -1
- package/lib/MediaSession/SessionTurn.js +611 -422
- package/lib/MediaSession/SessionTurn.js.map +1 -1
- package/lib/MediaSession/TurnConstants.js +31 -30
- package/lib/MediaSession/TurnConstants.js.map +1 -1
- package/lib/MediaSubscriber.d.ts +11 -11
- package/lib/MediaSubscriber.d.ts.map +1 -1
- package/lib/MediaSubscriber.js +236 -192
- package/lib/MediaSubscriber.js.map +1 -1
- package/lib/MediaUtils/Compatibility.d.ts +2 -1
- package/lib/MediaUtils/Compatibility.d.ts.map +1 -1
- package/lib/MediaUtils/Compatibility.js +130 -85
- package/lib/MediaUtils/Compatibility.js.map +1 -1
- package/lib/MediaUtils/MediaDomUtils.d.ts +3 -2
- package/lib/MediaUtils/MediaDomUtils.d.ts.map +1 -1
- package/lib/MediaUtils/MediaDomUtils.js +235 -174
- package/lib/MediaUtils/MediaDomUtils.js.map +1 -1
- package/lib/MediaUtils/MediaTracer.js +9 -4
- package/lib/MediaUtils/MediaTracer.js.map +1 -1
- package/lib/MediaUtils/index.d.ts +1 -0
- package/lib/MediaUtils/index.d.ts.map +1 -0
- package/lib/MediaUtils/index.js +16 -0
- package/lib/MediaUtils/index.js.map +1 -0
- package/lib/MultiParty/Contracts.d.ts +16 -0
- package/lib/MultiParty/Contracts.d.ts.map +1 -0
- package/lib/MultiParty/Contracts.js +6 -0
- package/lib/MultiParty/Contracts.js.map +1 -0
- package/lib/MultiParty/DetectWebRtcService.d.ts +16 -0
- package/lib/MultiParty/DetectWebRtcService.d.ts.map +1 -0
- package/lib/MultiParty/DetectWebRtcService.js +79 -0
- package/lib/MultiParty/DetectWebRtcService.js.map +1 -0
- package/lib/MultiParty/MediaCapabilitiesService.d.ts +23 -0
- package/lib/MultiParty/MediaCapabilitiesService.d.ts.map +1 -0
- package/lib/MultiParty/MediaCapabilitiesService.js +369 -0
- package/lib/MultiParty/MediaCapabilitiesService.js.map +1 -0
- package/lib/MultiParty/MediaCapabilitiesUtils.d.ts +5 -0
- package/lib/MultiParty/MediaCapabilitiesUtils.d.ts.map +1 -0
- package/lib/MultiParty/MediaCapabilitiesUtils.js +305 -0
- package/lib/MultiParty/MediaCapabilitiesUtils.js.map +1 -0
- package/lib/MultiParty/MultiPartyService.d.ts +40 -0
- package/lib/MultiParty/MultiPartyService.d.ts.map +1 -0
- package/lib/MultiParty/MultiPartyService.js +70 -0
- package/lib/MultiParty/MultiPartyService.js.map +1 -0
- package/lib/MultiParty/MultiPartyServiceFactory.d.ts +3 -0
- package/lib/MultiParty/MultiPartyServiceFactory.d.ts.map +1 -0
- package/lib/MultiParty/MultiPartyServiceFactory.js +21 -0
- package/lib/MultiParty/MultiPartyServiceFactory.js.map +1 -0
- package/lib/MultiParty/OpentokMultiPartyService.d.ts +29 -0
- package/lib/MultiParty/OpentokMultiPartyService.d.ts.map +1 -0
- package/lib/MultiParty/OpentokMultiPartyService.js +888 -0
- package/lib/MultiParty/OpentokMultiPartyService.js.map +1 -0
- package/lib/MultiParty/VideoLayoutType.d.ts +4 -0
- package/lib/MultiParty/VideoLayoutType.d.ts.map +1 -0
- package/lib/MultiParty/VideoLayoutType.js +13 -0
- package/lib/MultiParty/VideoLayoutType.js.map +1 -0
- package/lib/MultiParty/index.d.ts +4 -0
- package/lib/MultiParty/index.d.ts.map +1 -0
- package/lib/MultiParty/index.js +61 -0
- package/lib/MultiParty/index.js.map +1 -0
- package/lib/MultiParty/opentok.d.ts +503 -0
- package/lib/TechseeMediaStream.d.ts +6 -6
- package/lib/TechseeMediaStream.d.ts.map +1 -1
- package/lib/TechseeMediaStream.js +59 -53
- package/lib/TechseeMediaStream.js.map +1 -1
- package/lib/oldCode/constants.js +20 -15
- package/lib/oldCode/constants.js.map +1 -1
- package/lib/oldCode/event-emitter.js +45 -22
- package/lib/oldCode/event-emitter.js.map +1 -1
- package/lib/oldCode/index.js +48 -52
- package/lib/oldCode/index.js.map +1 -1
- package/lib/oldCode/opentok/session.js +261 -236
- package/lib/oldCode/opentok/session.js.map +1 -1
- package/lib/oldCode/opentok/stream.js +283 -269
- package/lib/oldCode/opentok/stream.js.map +1 -1
- package/lib/oldCode/publisher.js +96 -71
- package/lib/oldCode/publisher.js.map +1 -1
- package/lib/oldCode/service.js +294 -272
- package/lib/oldCode/service.js.map +1 -1
- package/lib/oldCode/session.js +82 -60
- package/lib/oldCode/session.js.map +1 -1
- package/lib/oldCode/stream.js +153 -125
- package/lib/oldCode/stream.js.map +1 -1
- package/lib/oldCode/subscriber.js +60 -35
- package/lib/oldCode/subscriber.js.map +1 -1
- package/lib/oldCode/tracer.d.ts +3 -2
- package/lib/oldCode/tracer.d.ts.map +1 -1
- package/lib/oldCode/tracer.js +181 -130
- package/lib/oldCode/tracer.js.map +1 -1
- package/lib/oldCode/utils/ImageFixer.js +67 -44
- package/lib/oldCode/utils/ImageFixer.js.map +1 -1
- package/lib/oldCode/webrtc/constants.js +102 -110
- package/lib/oldCode/webrtc/constants.js.map +1 -1
- package/lib/oldCode/webrtc/helper.js +176 -124
- package/lib/oldCode/webrtc/helper.js.map +1 -1
- package/lib/oldCode/webrtc/session-kms.js +408 -393
- package/lib/oldCode/webrtc/session-kms.js.map +1 -1
- package/lib/oldCode/webrtc/session-loopback.js +245 -227
- package/lib/oldCode/webrtc/session-loopback.js.map +1 -1
- package/lib/oldCode/webrtc/session-turn.js +705 -658
- package/lib/oldCode/webrtc/session-turn.js.map +1 -1
- package/lib/oldCode/webrtc/session-turn.v2.js +480 -471
- package/lib/oldCode/webrtc/session-turn.v2.js.map +1 -1
- package/lib/oldCode/webrtc/session.js +12 -6
- package/lib/oldCode/webrtc/session.js.map +1 -1
- package/lib/oldCode/webrtc/stream.js +526 -504
- package/lib/oldCode/webrtc/stream.js.map +1 -1
- package/lib/oldCode/webrtc/temasys/adapter-loader.js +5 -6
- package/lib/oldCode/webrtc/temasys/adapter-loader.js.map +1 -1
- package/lib/oldCode/webrtc/temasys/adapter.js +5264 -5192
- package/lib/oldCode/webrtc/temasys/adapter.js.map +1 -1
- package/lib/oldCode/webrtc/webrtc-ie-shim.js +3357 -2927
- package/lib/oldCode/webrtc/webrtc-ie-shim.js.map +1 -1
- package/lib/qos/raw-qos.js +348 -273
- package/lib/qos/raw-qos.js.map +1 -1
- package/lib/webrtc-ie-shim.js +3386 -2985
- package/lib/webrtc-ie-shim.js.map +1 -1
- package/package.json +54 -42
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/MediaSession/MediaServer.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EACb,sBAAsB,EACtB,yBAAyB,EACzB,kBAAkB,EAClB,gBAAgB,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAC,iBAAiB,EAAE,gBAAgB,EAAkB,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAC,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAC,QAAQ,EAAC,MAAM,yBAAyB,CAAC;AACjD,OAAO,EACH,UAAU,EAGV,SAAS,EAGT,UAAU,EACb,MAAM,2BAA2B,CAAC;AAQnC,UAAU,cAAc;IACpB,WAAW,EAAE,GAAG,CAAC;IACjB,WAAW,EAAE,GAAG,CAAC;CACpB;AAED,UAAU,gBAAiB,SAAQ,iBAAiB;IAChD,WAAW,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IACtC,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IACjC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC/B,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;CACpC;AAED,qBAAa,kBAAmB,SAAQ,gBAAgB,CAAC,gBAAgB,CAAE,YAAW,aAAa;IAC/F,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAM;IACnC,OAAO,CAAC,EAAE,CAA4B;IACtC,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,iBAAiB,CAAa;IAEtC,OAAO,KAAK,SAAS,GAEpB;gBAEW,aAAa,EAAE,kBAAkB,GAAG,yBAAyB,EAAE,aAAa,EAAE,sBAAsB;IAkBhH,OAAO,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B7C,iBAAiB;IAMjB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAkC3B,OAAO,CAAC,kBAAkB;IAiB1B,mBAAmB,CAAC,UAAU,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAM5E,sBAAsB,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAcpE,OAAO,CAAC,oBAAoB;IAW5B,oBAAoB,CAAC,UAAU,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5F,mBAAmB,CAAC,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAItE,OAAO,CAAC,iBAAiB;IAmCzB,OAAO,CAAC,sBAAsB;IAmB9B,OAAO,CAAC,0BAA0B;IAelC,OAAO,CAAC,qBAAqB;IAW7B,OAAO,CAAC,iCAAiC;IAiBzC,OAAO,CAAC,gCAAgC;IAcxC,OAAO,CAAC,qBAAqB;IAuB7B,OAAO,CAAC,oBAAoB;IAoC5B,OAAO,CAAC,yBAAyB;IAyBjC,OAAO,CAAC,oBAAoB;IAgC5B,OAAO,CAAC,wBAAwB;IAwEhC,OAAO,CAAC,kBAAkB;CAK7B","file":"MediaServer.d.ts","sourcesContent":["import {\n IMediaSession,\n ISessionStreamsManager,\n MediaSessionConfiguration,\n MediaSessionParams,\n RemoteTrackStats\n} from '../MediaContracts';\nimport {IMediaSessionPeer, MediaSessionBase, recordingEvents} from './MediaSessionBase';\nimport {SessionClientRole, SessionClientType} from '../MediaConstants';\nimport {Nullable} from '@techsee/techsee-common';\nimport {\n Connection,\n OpenVidu,\n OpenViduError,\n Publisher,\n PublisherProperties,\n Session,\n Subscriber\n} from '@techsee/openvidu-browser';\nimport {getMediaTracer} from '../MediaUtils/MediaTracer';\nimport {throwableGuard} from '@techsee/techsee-common/lib/core/guards';\nimport {Promise} from 'bluebird';\nimport get from 'lodash/get';\n\nconst trace = getMediaTracer('MediaServerSession');\n\ninterface OVStreamSource {\n videoSource: any;\n audioSource: any;\n}\n\ninterface OVPeerConnection extends IMediaSessionPeer {\n localStream: Nullable<OVStreamSource>;\n connection: Nullable<Connection>;\n publisher: Nullable<Publisher>;\n subscriber: Nullable<Subscriber>;\n}\n\nexport class MediaServerSession extends MediaSessionBase<OVPeerConnection> implements IMediaSession {\n private readonly _credentials: any;\n private OV: Nullable<OpenVidu> = null;\n private _session: Nullable<Session> = null;\n private _lastStreamEvents: any[] = [];\n\n private get ownPeerId(): string {\n return this._session && this._session.connection ? this._session.connection.connectionId : '';\n }\n\n constructor(sessionParams: MediaSessionParams & MediaSessionConfiguration, streamFactory: ISessionStreamsManager) {\n super(sessionParams, streamFactory);\n this._credentials = sessionParams.credentials;\n\n this.connect = this.connect.bind(this);\n this.disconnect = this.disconnect.bind(this);\n this.onMediaStreamDestroyed = this.onMediaStreamDestroyed.bind(this);\n this.onPublisherDestroyed = this.onPublisherDestroyed.bind(this);\n this.onMediaStreamRenewed = this.onMediaStreamRenewed.bind(this);\n\n this.createStreamForPublishing = this.createStreamForPublishing.bind(this);\n this.createMediaPublisher = this.createMediaPublisher.bind(this);\n this.connectionCreatedHandler = this.connectionCreatedHandler.bind(this);\n this.connectionDestroyedHandler = this.connectionDestroyedHandler.bind(this);\n this.streamCreatedHandler = this.streamCreatedHandler.bind(this);\n this.streamDestroyedHandler = this.streamDestroyedHandler.bind(this);\n }\n\n connect(connectOnly?: boolean): Promise<void> {\n trace.info('Connect to session', this._credentials);\n\n if (this._session) {\n trace.error('Session already exists');\n\n return Promise.reject('Cannot connect to session while another session is active');\n }\n\n // const iceServers = this._credentials.ice.map((item: any) => ({\n // urls: item.url,\n // username: item.login,\n // credential: item.password\n // }));\n\n this.OV = new OpenVidu();\n // this.OV.setAdvancedConfiguration({ iceServers });\n this._session = this.OV.initSession();\n\n this.initSessionEvents();\n\n return this._session.connect(this._credentials.token, {clientRole: this._sessionParams.clientRole})\n .catch((err) => {\n trace.error('Error to connect to session Media Server: ', err);\n\n throw err;\n });\n }\n\n sessionDisconnect() {\n if (this._session) {\n return this._session.disconnect(true);\n }\n }\n\n disconnect(): Promise<void> {\n return new Promise((resolve) => {\n trace.info('Disconnecting from session');\n\n const promiseDisconnect: any[] = [];\n\n this._peerConnections.forEach((peerConnection) => {\n promiseDisconnect.push(this.destroyPeerConnection(peerConnection));\n });\n\n return Promise.all(promiseDisconnect).then(() => {\n if (!this._session) {\n trace.info('No active session - resolving');\n resolve();\n\n return;\n }\n\n this.removeSessionEvent();\n this._session.disconnect();\n\n this._lastStreamEvents = [];\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n delete this._session;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n delete this.OV;\n\n resolve();\n });\n });\n }\n\n private removeSessionEvent() {\n if (!this._session) {\n return;\n }\n\n this._session.off('connectionCreated');\n this._session.off('streamCreated');\n this._session.off('streamDestroyed');\n this._session.off('connectionDestroyed');\n this._session.off('sessionDisconnected');\n this._session.off('recordingStarted');\n this._session.off('recordingStopped');\n this._sessionParams.removeHandlers && this._sessionParams.removeHandlers();\n\n trace.info('Remove Events Listener');\n }\n\n getRemoteTrackStats(mediaTrack: MediaStreamTrack): Promise<RemoteTrackStats> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore// @ts-ignore\n return Promise.resolve(undefined);\n }\n\n onMediaStreamDestroyed(clientRole: SessionClientRole): Promise<void> {\n trace.info('onMediaStreamDestroyed');\n\n const promises: Promise<void>[] = [];\n\n this._peerConnections.forEach((peerConnection) => {\n if (peerConnection.peerRole === clientRole) {\n promises.push(this.destroyPublisherOnPeerConnection(peerConnection));\n }\n });\n\n return Promise.all(promises).then(() => trace.info('onMediaStreamDestroyed: Success'));\n }\n\n private onPublisherDestroyed(connectionId: string) {\n trace.info('onPublisherDestroyed');\n const peerConnection = this._peerConnections.get(connectionId);\n\n if (!peerConnection) {\n return Promise.resolve();\n }\n\n return this.destroyPublisherOnPeerConnection(peerConnection);\n }\n\n onMediaStreamRenewed(clientRole: SessionClientRole, mediaStream: MediaStream): Promise<void> {\n return Promise.resolve(undefined);\n }\n\n replaceStreamTracks(mediaStream: Nullable<MediaStream>): Promise<void> {\n return Promise.reject(new Error('Not implemented'));\n }\n\n private initSessionEvents() {\n if (!this._session) {\n return;\n }\n\n this._sessionParams.initHandlers && this._sessionParams.initHandlers();\n\n this._lastStreamEvents = [];\n\n this._session!.on('connectionCreated', this.connectionCreatedHandler);\n\n this._session.on('streamCreated', this.streamCreatedHandler);\n\n this._session.on('streamDestroyed', this.streamDestroyedHandler);\n\n this._session.on('connectionDestroyed', this.connectionDestroyedHandler);\n\n this._session.on('recordingStarted', (event) => {\n trace.info('recordingStarted event', event);\n this.emitEvent(recordingEvents.RECORD_STARTED, event);\n });\n\n this._session.on('recordingStopped', (event) => {\n trace.info('recordingStopped event', event);\n this.emitEvent(recordingEvents.RECORD_STOPPED, event);\n });\n\n this._session.on('reconnecting', () => {\n trace.info('reconnecting event');\n this.emitEvent(recordingEvents.RECONNECTING);\n });\n\n this._session.on('sessionDisconnected', this.disconnect);\n }\n\n private streamDestroyedHandler(event: any): void {\n trace.info('streamDestroyedHandler', event);\n const {stream} = event;\n\n if (!this.sessionExistsGuard(false) || !stream) {\n return;\n }\n\n const peerConnection = this._peerConnections.get(stream.connection.connectionId);\n\n if (!peerConnection) {\n trace.warn('Peer connection for remote stream not found');\n\n return;\n }\n\n this.destroySubscriberOnPeerConnection(peerConnection).catch(() => undefined);\n }\n\n private connectionDestroyedHandler(event: any): void {\n trace.info('connectionDestroyedHandler', event);\n const {connection} = event;\n\n if (!this.sessionExistsGuard(false) || !connection) {\n return;\n }\n\n if (this._peerConnections.has(connection.connectionId)) {\n const peerConnection = this._peerConnections.get(connection.connectionId)!;\n\n this.destroySubscriberOnPeerConnection(peerConnection).catch(() => undefined);\n }\n }\n\n private destroyPeerConnection(peerConnection: OVPeerConnection): Promise<void> {\n trace.info('destroyPeerConnection');\n this._peerConnections.delete(peerConnection.peerId);\n\n return Promise.all([this.destroyPublisherOnPeerConnection(peerConnection),\n this.destroySubscriberOnPeerConnection(peerConnection)]).then(() => undefined)\n .catch(() => {\n trace.warn('destroyPeerConnection - something wrong with destroy');\n });\n }\n\n private destroySubscriberOnPeerConnection(peerConnection: OVPeerConnection): Promise<void> {\n trace.info('destroySubscriberOnPeerConnection', peerConnection);\n\n if (this.sessionExistsGuard(false) && peerConnection.subscriber) {\n this._session!.unsubscribe(peerConnection.subscriber);\n }\n\n trace.info('destroySubscriberOnPeerConnection- before unregisterPeersRemoteMediaTracks');\n\n return this.unregisterPeersRemoteMediaTracks(peerConnection)\n .catch(() => trace.warn('Error removing remote streams from peerConnection'))\n .then(() => {\n trace.info('destroySubscriberOnPeerConnection- unregisterPeersRemoteMediaTracks successfully');\n peerConnection.subscriber = null;\n });\n }\n\n private destroyPublisherOnPeerConnection(peerConnection: OVPeerConnection): Promise<void> {\n trace.info('destroyPublisherOnPeerConnection');\n\n if (this.sessionExistsGuard(false) && peerConnection.publisher) {\n trace.info('destroyPublisherOnPeerConnection- unpublish!');\n this._session!.unpublish(peerConnection.publisher);\n }\n\n peerConnection.publisher = null;\n peerConnection.localStream = null;\n\n return Promise.resolve();\n }\n\n private createMediaSubscriber(remoteStream: any): Promise<Subscriber> {\n trace.info('createMediaSubscriber');\n\n return new Promise((resolve: any, reject: any) => {\n if (!this.sessionExistsGuard(false)) {\n return reject('Session not exists');\n }\n\n trace.info('Before create subscriber');\n const subscriber: Subscriber = this._session!.subscribe(remoteStream, '', {}, (err: any) => {\n if (err) {\n trace.warn('Error creating subscriber', err);\n\n return reject(err);\n }\n\n trace.info('create subscriber successfully', subscriber);\n\n return resolve(subscriber);\n });\n });\n }\n\n private streamCreatedHandler(event: any): Promise<void> {\n if (!event) {\n return Promise.resolve();\n }\n\n trace.info('streamCreatedHandler', event.stream);\n const {stream} = event;\n const {connection} = stream || {connection: null};\n\n if (!this.sessionExistsGuard(false) || !stream || connection.connectionId === this.ownPeerId) {\n return Promise.resolve();\n }\n\n if (!this._peerConnections.has(connection.connectionId)) {\n trace.warn('Unexpected case, connection should exist, add to streams to subscribe list', event);\n this._lastStreamEvents.push(event);\n\n return Promise.resolve();\n }\n\n const peerConnection = this._peerConnections.get(connection.connectionId)!;\n\n trace.info('Subscribing the stream');\n\n return this.createMediaSubscriber(stream).then((subscriber: Subscriber) => {\n peerConnection.subscriber = subscriber;\n\n trace.info('Registering remote media tracks', peerConnection.subscriber);\n subscriber.stream.getMediaStream().getTracks().forEach((mediaTrack: MediaStreamTrack) => {\n this.addRemoteTrackToPeer(peerConnection, mediaTrack);\n });\n\n return this.registerPeersRemoteTracks(peerConnection);\n });\n }\n\n private createStreamForPublishing(destinationRole: SessionClientRole): Promise<OVStreamSource> {\n trace.info('createStreamForPublishing');\n\n return this._sessionStreamsManager.getMediaStreamForRole(destinationRole)\n .then((mediaStream: Nullable<MediaStream>) => {\n\n const stream: OVStreamSource = {videoSource: null, audioSource: null};\n\n if (mediaStream) {\n trace.info('Media stream found for publishing', mediaStream);\n mediaStream.getTracks().forEach((track) => {\n if (track.kind === 'video') {\n stream.videoSource = track;\n } else if (track.kind === 'audio') {\n stream.audioSource = track;\n }\n });\n } else if (this._sessionParams.clientRole === SessionClientRole.USER) {\n trace.warn('No local media was found for publishing to destinationRole:', destinationRole);\n }\n\n return stream;\n });\n }\n\n private createMediaPublisher(stream: OVStreamSource): Promise<Publisher> {\n const ovParams: PublisherProperties = {\n videoSource: stream.videoSource ? stream.videoSource : false,\n audioSource: stream.audioSource ? stream.audioSource : false,\n publishAudio: !!stream.audioSource,\n publishVideo: !!stream.videoSource\n };\n\n return new Promise((resolve, reject) => {\n const ovPublisher = this.OV!.initPublisher('', ovParams, (error: any) => {\n if (error) {\n reject(error);\n\n return;\n }\n\n ovPublisher.on('streamDestroyed', (event: any) => {\n trace.info('Publisher stream destroyed', event);\n const connectionId = get(event, 'stream.connection.connectionId');\n\n this.onPublisherDestroyed(connectionId);\n\n //We preventing the default, in order to prevent stop the stream by OV.\n //We managing streams by ourselves and if we allow OV to close the stream, it cannot be reused.\n event.preventDefault();\n });\n\n resolve(ovPublisher);\n });\n });\n }\n\n private connectionCreatedHandler(event: any): void {\n trace.info('connectionCreatedHandler', event);\n const {connection} = event;\n\n if (!this.sessionExistsGuard(false) || !connection) {\n return;\n }\n\n const destinationRole = JSON.parse(connection.data).clientRole;\n\n this.createStreamForPublishing(destinationRole)\n .then((streams: OVStreamSource) => {\n const peerConnection: OVPeerConnection = {\n peerId: connection.connectionId,\n peerRole: destinationRole,\n peerType: this._sessionParams.clientType === SessionClientType.INITIATOR\n ? SessionClientType.GUEST : SessionClientType.INITIATOR,\n connection: connection,\n publisher: null,\n subscriber: null,\n remoteMediaTracks: [],\n localStream: streams,\n connectionTimoutPrt: null\n };\n\n if (connection.connectionId !== this.ownPeerId || (!streams.videoSource && !streams.audioSource)) {\n trace.info('Peer connection without publisher was created', peerConnection);\n\n return peerConnection;\n }\n\n return this.createMediaPublisher(streams)\n .then((publisher: Publisher) => {\n peerConnection.publisher = publisher;\n trace.info('Peer connection with publisher was created', peerConnection);\n\n return peerConnection;\n });\n })\n .then((peerConnection: OVPeerConnection) => {\n this._peerConnections.set(peerConnection.peerId, peerConnection);\n\n if (connection.connectionId === this.ownPeerId) {\n trace.info('Before subscribe the event streams');\n\n return this._lastStreamEvents.reduce((promiseChain: any, streamEvent: any) => promiseChain.then(() => this.streamCreatedHandler(streamEvent)),\n Promise.resolve()).then(() => {\n if (peerConnection.publisher) {\n trace.info('Starting publish to peerConnection.publisher');\n\n return this._session!.publish(peerConnection.publisher)\n .catch((err: OpenViduError) => {\n trace.info('Error during publish', peerConnection.publisher);\n\n if (peerConnection.publisher) {\n trace.info('Error during publish- unpublish');\n this._session!.unpublish(peerConnection.publisher);\n }\n\n throw err;\n });\n }\n\n return Promise.resolve();\n });\n }\n })\n .catch((error: OpenViduError) => {\n trace.error('Error handling new peer connection', error);\n });\n }\n\n private sessionExistsGuard(shouldThrow = true): boolean {\n const connected = !!(this._session && this._session.connection && this._session.connection.connectionId);\n\n return throwableGuard(connected, 'There no MediaServer session exists', shouldThrow);\n }\n}\n"]}
|
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __extends = void 0 && (void 0).__extends || function () {
|
|
4
|
+
var _extendStatics = function extendStatics(d, b) {
|
|
5
|
+
_extendStatics = Object.setPrototypeOf || {
|
|
6
|
+
__proto__: []
|
|
7
|
+
} instanceof Array && function (d, b) {
|
|
8
|
+
d.__proto__ = b;
|
|
9
|
+
} || function (d, b) {
|
|
10
|
+
for (var p in b) {
|
|
11
|
+
if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return _extendStatics(d, b);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return function (d, b) {
|
|
19
|
+
_extendStatics(d, b);
|
|
20
|
+
|
|
21
|
+
function __() {
|
|
22
|
+
this.constructor = d;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
26
|
+
};
|
|
27
|
+
}();
|
|
28
|
+
|
|
29
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
30
|
+
return mod && mod.__esModule ? mod : {
|
|
31
|
+
"default": mod
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
Object.defineProperty(exports, "__esModule", {
|
|
36
|
+
value: true
|
|
37
|
+
});
|
|
38
|
+
exports.MediaServerSession = void 0;
|
|
39
|
+
|
|
40
|
+
var MediaSessionBase_1 = require("./MediaSessionBase");
|
|
41
|
+
|
|
42
|
+
var MediaConstants_1 = require("../MediaConstants");
|
|
43
|
+
|
|
44
|
+
var openvidu_browser_1 = require("@techsee/openvidu-browser");
|
|
45
|
+
|
|
46
|
+
var MediaTracer_1 = require("../MediaUtils/MediaTracer");
|
|
47
|
+
|
|
48
|
+
var guards_1 = require("@techsee/techsee-common/lib/core/guards");
|
|
49
|
+
|
|
50
|
+
var bluebird_1 = require("bluebird");
|
|
51
|
+
|
|
52
|
+
var get_1 = __importDefault(require("lodash/get"));
|
|
53
|
+
|
|
54
|
+
var trace = MediaTracer_1.getMediaTracer('MediaServerSession');
|
|
55
|
+
|
|
56
|
+
var MediaServerSession =
|
|
57
|
+
/** @class */
|
|
58
|
+
function (_super) {
|
|
59
|
+
__extends(MediaServerSession, _super);
|
|
60
|
+
|
|
61
|
+
function MediaServerSession(sessionParams, streamFactory) {
|
|
62
|
+
var _this = _super.call(this, sessionParams, streamFactory) || this;
|
|
63
|
+
|
|
64
|
+
_this.OV = null;
|
|
65
|
+
_this._session = null;
|
|
66
|
+
_this._lastStreamEvents = [];
|
|
67
|
+
_this._credentials = sessionParams.credentials;
|
|
68
|
+
_this.connect = _this.connect.bind(_this);
|
|
69
|
+
_this.disconnect = _this.disconnect.bind(_this);
|
|
70
|
+
_this.onMediaStreamDestroyed = _this.onMediaStreamDestroyed.bind(_this);
|
|
71
|
+
_this.onPublisherDestroyed = _this.onPublisherDestroyed.bind(_this);
|
|
72
|
+
_this.onMediaStreamRenewed = _this.onMediaStreamRenewed.bind(_this);
|
|
73
|
+
_this.createStreamForPublishing = _this.createStreamForPublishing.bind(_this);
|
|
74
|
+
_this.createMediaPublisher = _this.createMediaPublisher.bind(_this);
|
|
75
|
+
_this.connectionCreatedHandler = _this.connectionCreatedHandler.bind(_this);
|
|
76
|
+
_this.connectionDestroyedHandler = _this.connectionDestroyedHandler.bind(_this);
|
|
77
|
+
_this.streamCreatedHandler = _this.streamCreatedHandler.bind(_this);
|
|
78
|
+
_this.streamDestroyedHandler = _this.streamDestroyedHandler.bind(_this);
|
|
79
|
+
return _this;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Object.defineProperty(MediaServerSession.prototype, "ownPeerId", {
|
|
83
|
+
get: function get() {
|
|
84
|
+
return this._session && this._session.connection ? this._session.connection.connectionId : '';
|
|
85
|
+
},
|
|
86
|
+
enumerable: false,
|
|
87
|
+
configurable: true
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
MediaServerSession.prototype.connect = function (connectOnly) {
|
|
91
|
+
trace.info('Connect to session', this._credentials);
|
|
92
|
+
|
|
93
|
+
if (this._session) {
|
|
94
|
+
trace.error('Session already exists');
|
|
95
|
+
return bluebird_1.Promise.reject('Cannot connect to session while another session is active');
|
|
96
|
+
} // const iceServers = this._credentials.ice.map((item: any) => ({
|
|
97
|
+
// urls: item.url,
|
|
98
|
+
// username: item.login,
|
|
99
|
+
// credential: item.password
|
|
100
|
+
// }));
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
this.OV = new openvidu_browser_1.OpenVidu(); // this.OV.setAdvancedConfiguration({ iceServers });
|
|
104
|
+
|
|
105
|
+
this._session = this.OV.initSession();
|
|
106
|
+
this.initSessionEvents();
|
|
107
|
+
return this._session.connect(this._credentials.token, {
|
|
108
|
+
clientRole: this._sessionParams.clientRole
|
|
109
|
+
})["catch"](function (err) {
|
|
110
|
+
trace.error('Error to connect to session Media Server: ', err);
|
|
111
|
+
throw err;
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
MediaServerSession.prototype.sessionDisconnect = function () {
|
|
116
|
+
if (this._session) {
|
|
117
|
+
return this._session.disconnect(true);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
MediaServerSession.prototype.disconnect = function () {
|
|
122
|
+
var _this = this;
|
|
123
|
+
|
|
124
|
+
return new bluebird_1.Promise(function (resolve) {
|
|
125
|
+
trace.info('Disconnecting from session');
|
|
126
|
+
var promiseDisconnect = [];
|
|
127
|
+
|
|
128
|
+
_this._peerConnections.forEach(function (peerConnection) {
|
|
129
|
+
promiseDisconnect.push(_this.destroyPeerConnection(peerConnection));
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
return bluebird_1.Promise.all(promiseDisconnect).then(function () {
|
|
133
|
+
if (!_this._session) {
|
|
134
|
+
trace.info('No active session - resolving');
|
|
135
|
+
resolve();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
_this.removeSessionEvent();
|
|
140
|
+
|
|
141
|
+
_this._session.disconnect();
|
|
142
|
+
|
|
143
|
+
_this._lastStreamEvents = []; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
144
|
+
// @ts-ignore
|
|
145
|
+
|
|
146
|
+
delete _this._session; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
147
|
+
// @ts-ignore
|
|
148
|
+
|
|
149
|
+
delete _this.OV;
|
|
150
|
+
resolve();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
MediaServerSession.prototype.removeSessionEvent = function () {
|
|
156
|
+
if (!this._session) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
this._session.off('connectionCreated');
|
|
161
|
+
|
|
162
|
+
this._session.off('streamCreated');
|
|
163
|
+
|
|
164
|
+
this._session.off('streamDestroyed');
|
|
165
|
+
|
|
166
|
+
this._session.off('connectionDestroyed');
|
|
167
|
+
|
|
168
|
+
this._session.off('sessionDisconnected');
|
|
169
|
+
|
|
170
|
+
this._session.off('recordingStarted');
|
|
171
|
+
|
|
172
|
+
this._session.off('recordingStopped');
|
|
173
|
+
|
|
174
|
+
this._sessionParams.removeHandlers && this._sessionParams.removeHandlers();
|
|
175
|
+
trace.info('Remove Events Listener');
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
MediaServerSession.prototype.getRemoteTrackStats = function (mediaTrack) {
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
180
|
+
// @ts-ignore// @ts-ignore
|
|
181
|
+
return bluebird_1.Promise.resolve(undefined);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
MediaServerSession.prototype.onMediaStreamDestroyed = function (clientRole) {
|
|
185
|
+
var _this = this;
|
|
186
|
+
|
|
187
|
+
trace.info('onMediaStreamDestroyed');
|
|
188
|
+
var promises = [];
|
|
189
|
+
|
|
190
|
+
this._peerConnections.forEach(function (peerConnection) {
|
|
191
|
+
if (peerConnection.peerRole === clientRole) {
|
|
192
|
+
promises.push(_this.destroyPublisherOnPeerConnection(peerConnection));
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
return bluebird_1.Promise.all(promises).then(function () {
|
|
197
|
+
return trace.info('onMediaStreamDestroyed: Success');
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
MediaServerSession.prototype.onPublisherDestroyed = function (connectionId) {
|
|
202
|
+
trace.info('onPublisherDestroyed');
|
|
203
|
+
|
|
204
|
+
var peerConnection = this._peerConnections.get(connectionId);
|
|
205
|
+
|
|
206
|
+
if (!peerConnection) {
|
|
207
|
+
return bluebird_1.Promise.resolve();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return this.destroyPublisherOnPeerConnection(peerConnection);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
MediaServerSession.prototype.onMediaStreamRenewed = function (clientRole, mediaStream) {
|
|
214
|
+
return bluebird_1.Promise.resolve(undefined);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
MediaServerSession.prototype.replaceStreamTracks = function (mediaStream) {
|
|
218
|
+
return bluebird_1.Promise.reject(new Error('Not implemented'));
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
MediaServerSession.prototype.initSessionEvents = function () {
|
|
222
|
+
var _this = this;
|
|
223
|
+
|
|
224
|
+
if (!this._session) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
this._sessionParams.initHandlers && this._sessionParams.initHandlers();
|
|
229
|
+
this._lastStreamEvents = [];
|
|
230
|
+
|
|
231
|
+
this._session.on('connectionCreated', this.connectionCreatedHandler);
|
|
232
|
+
|
|
233
|
+
this._session.on('streamCreated', this.streamCreatedHandler);
|
|
234
|
+
|
|
235
|
+
this._session.on('streamDestroyed', this.streamDestroyedHandler);
|
|
236
|
+
|
|
237
|
+
this._session.on('connectionDestroyed', this.connectionDestroyedHandler);
|
|
238
|
+
|
|
239
|
+
this._session.on('recordingStarted', function (event) {
|
|
240
|
+
trace.info('recordingStarted event', event);
|
|
241
|
+
|
|
242
|
+
_this.emitEvent(MediaSessionBase_1.recordingEvents.RECORD_STARTED, event);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
this._session.on('recordingStopped', function (event) {
|
|
246
|
+
trace.info('recordingStopped event', event);
|
|
247
|
+
|
|
248
|
+
_this.emitEvent(MediaSessionBase_1.recordingEvents.RECORD_STOPPED, event);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
this._session.on('reconnecting', function () {
|
|
252
|
+
trace.info('reconnecting event');
|
|
253
|
+
|
|
254
|
+
_this.emitEvent(MediaSessionBase_1.recordingEvents.RECONNECTING);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
this._session.on('sessionDisconnected', this.disconnect);
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
MediaServerSession.prototype.streamDestroyedHandler = function (event) {
|
|
261
|
+
trace.info('streamDestroyedHandler', event);
|
|
262
|
+
var stream = event.stream;
|
|
263
|
+
|
|
264
|
+
if (!this.sessionExistsGuard(false) || !stream) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
var peerConnection = this._peerConnections.get(stream.connection.connectionId);
|
|
269
|
+
|
|
270
|
+
if (!peerConnection) {
|
|
271
|
+
trace.warn('Peer connection for remote stream not found');
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
this.destroySubscriberOnPeerConnection(peerConnection)["catch"](function () {
|
|
276
|
+
return undefined;
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
MediaServerSession.prototype.connectionDestroyedHandler = function (event) {
|
|
281
|
+
trace.info('connectionDestroyedHandler', event);
|
|
282
|
+
var connection = event.connection;
|
|
283
|
+
|
|
284
|
+
if (!this.sessionExistsGuard(false) || !connection) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (this._peerConnections.has(connection.connectionId)) {
|
|
289
|
+
var peerConnection = this._peerConnections.get(connection.connectionId);
|
|
290
|
+
|
|
291
|
+
this.destroySubscriberOnPeerConnection(peerConnection)["catch"](function () {
|
|
292
|
+
return undefined;
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
MediaServerSession.prototype.destroyPeerConnection = function (peerConnection) {
|
|
298
|
+
trace.info('destroyPeerConnection');
|
|
299
|
+
|
|
300
|
+
this._peerConnections["delete"](peerConnection.peerId);
|
|
301
|
+
|
|
302
|
+
return bluebird_1.Promise.all([this.destroyPublisherOnPeerConnection(peerConnection), this.destroySubscriberOnPeerConnection(peerConnection)]).then(function () {
|
|
303
|
+
return undefined;
|
|
304
|
+
})["catch"](function () {
|
|
305
|
+
trace.warn('destroyPeerConnection - something wrong with destroy');
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
MediaServerSession.prototype.destroySubscriberOnPeerConnection = function (peerConnection) {
|
|
310
|
+
trace.info('destroySubscriberOnPeerConnection', peerConnection);
|
|
311
|
+
|
|
312
|
+
if (this.sessionExistsGuard(false) && peerConnection.subscriber) {
|
|
313
|
+
this._session.unsubscribe(peerConnection.subscriber);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
trace.info('destroySubscriberOnPeerConnection- before unregisterPeersRemoteMediaTracks');
|
|
317
|
+
return this.unregisterPeersRemoteMediaTracks(peerConnection)["catch"](function () {
|
|
318
|
+
return trace.warn('Error removing remote streams from peerConnection');
|
|
319
|
+
}).then(function () {
|
|
320
|
+
trace.info('destroySubscriberOnPeerConnection- unregisterPeersRemoteMediaTracks successfully');
|
|
321
|
+
peerConnection.subscriber = null;
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
MediaServerSession.prototype.destroyPublisherOnPeerConnection = function (peerConnection) {
|
|
326
|
+
trace.info('destroyPublisherOnPeerConnection');
|
|
327
|
+
|
|
328
|
+
if (this.sessionExistsGuard(false) && peerConnection.publisher) {
|
|
329
|
+
trace.info('destroyPublisherOnPeerConnection- unpublish!');
|
|
330
|
+
|
|
331
|
+
this._session.unpublish(peerConnection.publisher);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
peerConnection.publisher = null;
|
|
335
|
+
peerConnection.localStream = null;
|
|
336
|
+
return bluebird_1.Promise.resolve();
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
MediaServerSession.prototype.createMediaSubscriber = function (remoteStream) {
|
|
340
|
+
var _this = this;
|
|
341
|
+
|
|
342
|
+
trace.info('createMediaSubscriber');
|
|
343
|
+
return new bluebird_1.Promise(function (resolve, reject) {
|
|
344
|
+
if (!_this.sessionExistsGuard(false)) {
|
|
345
|
+
return reject('Session not exists');
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
trace.info('Before create subscriber');
|
|
349
|
+
|
|
350
|
+
var subscriber = _this._session.subscribe(remoteStream, '', {}, function (err) {
|
|
351
|
+
if (err) {
|
|
352
|
+
trace.warn('Error creating subscriber', err);
|
|
353
|
+
return reject(err);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
trace.info('create subscriber successfully', subscriber);
|
|
357
|
+
return resolve(subscriber);
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
MediaServerSession.prototype.streamCreatedHandler = function (event) {
|
|
363
|
+
var _this = this;
|
|
364
|
+
|
|
365
|
+
if (!event) {
|
|
366
|
+
return bluebird_1.Promise.resolve();
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
trace.info('streamCreatedHandler', event.stream);
|
|
370
|
+
var stream = event.stream;
|
|
371
|
+
var connection = (stream || {
|
|
372
|
+
connection: null
|
|
373
|
+
}).connection;
|
|
374
|
+
|
|
375
|
+
if (!this.sessionExistsGuard(false) || !stream || connection.connectionId === this.ownPeerId) {
|
|
376
|
+
return bluebird_1.Promise.resolve();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (!this._peerConnections.has(connection.connectionId)) {
|
|
380
|
+
trace.warn('Unexpected case, connection should exist, add to streams to subscribe list', event);
|
|
381
|
+
|
|
382
|
+
this._lastStreamEvents.push(event);
|
|
383
|
+
|
|
384
|
+
return bluebird_1.Promise.resolve();
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
var peerConnection = this._peerConnections.get(connection.connectionId);
|
|
388
|
+
|
|
389
|
+
trace.info('Subscribing the stream');
|
|
390
|
+
return this.createMediaSubscriber(stream).then(function (subscriber) {
|
|
391
|
+
peerConnection.subscriber = subscriber;
|
|
392
|
+
trace.info('Registering remote media tracks', peerConnection.subscriber);
|
|
393
|
+
subscriber.stream.getMediaStream().getTracks().forEach(function (mediaTrack) {
|
|
394
|
+
_this.addRemoteTrackToPeer(peerConnection, mediaTrack);
|
|
395
|
+
});
|
|
396
|
+
return _this.registerPeersRemoteTracks(peerConnection);
|
|
397
|
+
});
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
MediaServerSession.prototype.createStreamForPublishing = function (destinationRole) {
|
|
401
|
+
var _this = this;
|
|
402
|
+
|
|
403
|
+
trace.info('createStreamForPublishing');
|
|
404
|
+
return this._sessionStreamsManager.getMediaStreamForRole(destinationRole).then(function (mediaStream) {
|
|
405
|
+
var stream = {
|
|
406
|
+
videoSource: null,
|
|
407
|
+
audioSource: null
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
if (mediaStream) {
|
|
411
|
+
trace.info('Media stream found for publishing', mediaStream);
|
|
412
|
+
mediaStream.getTracks().forEach(function (track) {
|
|
413
|
+
if (track.kind === 'video') {
|
|
414
|
+
stream.videoSource = track;
|
|
415
|
+
} else if (track.kind === 'audio') {
|
|
416
|
+
stream.audioSource = track;
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
} else if (_this._sessionParams.clientRole === MediaConstants_1.SessionClientRole.USER) {
|
|
420
|
+
trace.warn('No local media was found for publishing to destinationRole:', destinationRole);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return stream;
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
MediaServerSession.prototype.createMediaPublisher = function (stream) {
|
|
428
|
+
var _this = this;
|
|
429
|
+
|
|
430
|
+
var ovParams = {
|
|
431
|
+
videoSource: stream.videoSource ? stream.videoSource : false,
|
|
432
|
+
audioSource: stream.audioSource ? stream.audioSource : false,
|
|
433
|
+
publishAudio: !!stream.audioSource,
|
|
434
|
+
publishVideo: !!stream.videoSource
|
|
435
|
+
};
|
|
436
|
+
return new bluebird_1.Promise(function (resolve, reject) {
|
|
437
|
+
var ovPublisher = _this.OV.initPublisher('', ovParams, function (error) {
|
|
438
|
+
if (error) {
|
|
439
|
+
reject(error);
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
ovPublisher.on('streamDestroyed', function (event) {
|
|
444
|
+
trace.info('Publisher stream destroyed', event);
|
|
445
|
+
var connectionId = get_1["default"](event, 'stream.connection.connectionId');
|
|
446
|
+
|
|
447
|
+
_this.onPublisherDestroyed(connectionId); //We preventing the default, in order to prevent stop the stream by OV.
|
|
448
|
+
//We managing streams by ourselves and if we allow OV to close the stream, it cannot be reused.
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
event.preventDefault();
|
|
452
|
+
});
|
|
453
|
+
resolve(ovPublisher);
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
MediaServerSession.prototype.connectionCreatedHandler = function (event) {
|
|
459
|
+
var _this = this;
|
|
460
|
+
|
|
461
|
+
trace.info('connectionCreatedHandler', event);
|
|
462
|
+
var connection = event.connection;
|
|
463
|
+
|
|
464
|
+
if (!this.sessionExistsGuard(false) || !connection) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
var destinationRole = JSON.parse(connection.data).clientRole;
|
|
469
|
+
this.createStreamForPublishing(destinationRole).then(function (streams) {
|
|
470
|
+
var peerConnection = {
|
|
471
|
+
peerId: connection.connectionId,
|
|
472
|
+
peerRole: destinationRole,
|
|
473
|
+
peerType: _this._sessionParams.clientType === MediaConstants_1.SessionClientType.INITIATOR ? MediaConstants_1.SessionClientType.GUEST : MediaConstants_1.SessionClientType.INITIATOR,
|
|
474
|
+
connection: connection,
|
|
475
|
+
publisher: null,
|
|
476
|
+
subscriber: null,
|
|
477
|
+
remoteMediaTracks: [],
|
|
478
|
+
localStream: streams,
|
|
479
|
+
connectionTimoutPrt: null
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
if (connection.connectionId !== _this.ownPeerId || !streams.videoSource && !streams.audioSource) {
|
|
483
|
+
trace.info('Peer connection without publisher was created', peerConnection);
|
|
484
|
+
return peerConnection;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return _this.createMediaPublisher(streams).then(function (publisher) {
|
|
488
|
+
peerConnection.publisher = publisher;
|
|
489
|
+
trace.info('Peer connection with publisher was created', peerConnection);
|
|
490
|
+
return peerConnection;
|
|
491
|
+
});
|
|
492
|
+
}).then(function (peerConnection) {
|
|
493
|
+
_this._peerConnections.set(peerConnection.peerId, peerConnection);
|
|
494
|
+
|
|
495
|
+
if (connection.connectionId === _this.ownPeerId) {
|
|
496
|
+
trace.info('Before subscribe the event streams');
|
|
497
|
+
return _this._lastStreamEvents.reduce(function (promiseChain, streamEvent) {
|
|
498
|
+
return promiseChain.then(function () {
|
|
499
|
+
return _this.streamCreatedHandler(streamEvent);
|
|
500
|
+
});
|
|
501
|
+
}, bluebird_1.Promise.resolve()).then(function () {
|
|
502
|
+
if (peerConnection.publisher) {
|
|
503
|
+
trace.info('Starting publish to peerConnection.publisher');
|
|
504
|
+
return _this._session.publish(peerConnection.publisher)["catch"](function (err) {
|
|
505
|
+
trace.info('Error during publish', peerConnection.publisher);
|
|
506
|
+
|
|
507
|
+
if (peerConnection.publisher) {
|
|
508
|
+
trace.info('Error during publish- unpublish');
|
|
509
|
+
|
|
510
|
+
_this._session.unpublish(peerConnection.publisher);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
throw err;
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
return bluebird_1.Promise.resolve();
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
})["catch"](function (error) {
|
|
521
|
+
trace.error('Error handling new peer connection', error);
|
|
522
|
+
});
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
MediaServerSession.prototype.sessionExistsGuard = function (shouldThrow) {
|
|
526
|
+
if (shouldThrow === void 0) {
|
|
527
|
+
shouldThrow = true;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
var connected = !!(this._session && this._session.connection && this._session.connection.connectionId);
|
|
531
|
+
return guards_1.throwableGuard(connected, 'There no MediaServer session exists', shouldThrow);
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
return MediaServerSession;
|
|
535
|
+
}(MediaSessionBase_1.MediaSessionBase);
|
|
536
|
+
|
|
537
|
+
exports.MediaServerSession = MediaServerSession;
|
|
538
|
+
//# sourceMappingURL=MediaServer.js.map
|