@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
|
@@ -1,381 +1,529 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var __extends =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
return function (d, b) {
|
|
15
|
-
_extendStatics(d, b);
|
|
16
|
-
function __() {
|
|
17
|
-
this.constructor = d;
|
|
18
|
-
}
|
|
19
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
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
|
+
}
|
|
20
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
|
+
};
|
|
21
27
|
}();
|
|
22
|
-
|
|
28
|
+
|
|
29
|
+
Object.defineProperty(exports, "__esModule", {
|
|
30
|
+
value: true
|
|
31
|
+
});
|
|
32
|
+
exports.OpentokSession = void 0;
|
|
33
|
+
|
|
23
34
|
var MediaConstants_1 = require("../MediaConstants");
|
|
35
|
+
|
|
24
36
|
var guards_1 = require("@techsee/techsee-common/lib/core/guards");
|
|
37
|
+
|
|
25
38
|
var MediaSessionBase_1 = require("./MediaSessionBase");
|
|
39
|
+
|
|
26
40
|
var MediaTracer_1 = require("../MediaUtils/MediaTracer");
|
|
27
|
-
|
|
28
|
-
//Currently this version supports subscribing only. Publishing will be implemented as needed.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
|
|
42
|
+
var trace = MediaTracer_1.getMediaTracer('OpentokSession'); //Currently this version supports subscribing only. Publishing will be implemented as needed.
|
|
43
|
+
|
|
44
|
+
var OpentokSession =
|
|
45
|
+
/** @class */
|
|
46
|
+
function (_super) {
|
|
47
|
+
__extends(OpentokSession, _super);
|
|
48
|
+
|
|
49
|
+
function OpentokSession(sessionParams, streamFactory) {
|
|
50
|
+
var _this = _super.call(this, sessionParams, streamFactory) || this;
|
|
51
|
+
|
|
52
|
+
_this._lastStreamEvents = [];
|
|
53
|
+
_this._session = null;
|
|
54
|
+
_this._credentials = sessionParams.credentials;
|
|
55
|
+
_this.connect = _this.connect.bind(_this);
|
|
56
|
+
_this.disconnect = _this.disconnect.bind(_this);
|
|
57
|
+
_this.onMediaStreamDestroyed = _this.onMediaStreamDestroyed.bind(_this);
|
|
58
|
+
_this.onMediaStreamRenewed = _this.onMediaStreamRenewed.bind(_this);
|
|
59
|
+
_this.createStreamForPublishing = _this.createStreamForPublishing.bind(_this);
|
|
60
|
+
_this.createMediaPublisher = _this.createMediaPublisher.bind(_this);
|
|
61
|
+
_this.connectionCreatedHandler = _this.connectionCreatedHandler.bind(_this);
|
|
62
|
+
_this.connectionDestroyedHandler = _this.connectionDestroyedHandler.bind(_this);
|
|
63
|
+
_this.streamCreatedHandler = _this.streamCreatedHandler.bind(_this);
|
|
64
|
+
_this.streamDestroyedHandler = _this.streamDestroyedHandler.bind(_this);
|
|
65
|
+
return _this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
Object.defineProperty(OpentokSession.prototype, "id", {
|
|
69
|
+
get: function get() {
|
|
70
|
+
return this._session && this._session.sessionId ? this._session.sessionId : '';
|
|
71
|
+
},
|
|
72
|
+
enumerable: false,
|
|
73
|
+
configurable: true
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(OpentokSession.prototype, "ownPeerId", {
|
|
76
|
+
get: function get() {
|
|
77
|
+
return this._session && this._session.connection ? this._session.connection.connectionId : '';
|
|
78
|
+
},
|
|
79
|
+
enumerable: false,
|
|
80
|
+
configurable: true
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
OpentokSession.prototype.sessionDisconnect = function () {
|
|
84
|
+
if (this._session) {
|
|
85
|
+
this._session.disconnect();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
OpentokSession.prototype.connect = function () {
|
|
90
|
+
var _this = this;
|
|
91
|
+
|
|
92
|
+
trace.info('Connect to session', this._credentials);
|
|
93
|
+
|
|
94
|
+
if (this._session) {
|
|
95
|
+
trace.error('Session already exists');
|
|
96
|
+
return Promise.reject('Cannot connect to session while another session is active');
|
|
46
97
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
98
|
+
|
|
99
|
+
return new Promise(function (resolve, reject) {
|
|
100
|
+
var handleError = function handleError(error) {
|
|
101
|
+
_this._session && _this._session.off();
|
|
102
|
+
_this._session = null;
|
|
103
|
+
trace.error('handleConnect error:', error);
|
|
104
|
+
reject(error);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
var _a = _this._sessionParams.credentials,
|
|
108
|
+
apiKey = _a.apiKey,
|
|
109
|
+
sessionId = _a.sessionId;
|
|
110
|
+
_this._session = window.OTSESSION = window.OT.initSession(apiKey, sessionId);
|
|
111
|
+
_this._lastStreamEvents = [];
|
|
112
|
+
|
|
113
|
+
_this._session.on('connectionCreated', _this.connectionCreatedHandler);
|
|
114
|
+
|
|
115
|
+
_this._session.on('connectionDestroyed', _this.connectionDestroyedHandler);
|
|
116
|
+
|
|
117
|
+
_this._session.on('streamCreated', _this.streamCreatedHandler);
|
|
118
|
+
|
|
119
|
+
_this._session.on('streamDestroyed', _this.streamDestroyedHandler);
|
|
120
|
+
|
|
121
|
+
_this._session.on('archiveStarted', function (event) {
|
|
122
|
+
trace.info('archiveStarted event', event);
|
|
123
|
+
|
|
124
|
+
_this.emitEvent(MediaSessionBase_1.recordingEvents.RECORD_STARTED, event);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
_this._session.on('archiveStopped', function (event) {
|
|
128
|
+
trace.info('archiveStopped event', event);
|
|
129
|
+
|
|
130
|
+
_this.emitEvent(MediaSessionBase_1.recordingEvents.RECORD_STOPPED, event);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
var connectHandler = function connectHandler(error) {
|
|
134
|
+
if (error) {
|
|
135
|
+
handleError(error);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
resolve();
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
_this._session.connect(_this._credentials.token, connectHandler);
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
OpentokSession.prototype.disconnect = function () {
|
|
147
|
+
var _this = this;
|
|
148
|
+
|
|
149
|
+
return new Promise(function (resolve) {
|
|
150
|
+
trace.info('Disconnecting from session');
|
|
151
|
+
var currentSession = _this._session;
|
|
152
|
+
_this._session = null;
|
|
153
|
+
|
|
154
|
+
_this._peerConnections.forEach(function (peerConnection) {
|
|
155
|
+
_this.destroyPeerConnection(peerConnection);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
if (!currentSession) {
|
|
159
|
+
trace.info('No active session - resolving');
|
|
160
|
+
resolve();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
currentSession.off();
|
|
165
|
+
currentSession.disconnect();
|
|
166
|
+
_this._lastStreamEvents = [];
|
|
167
|
+
trace.info('Disconnection from session completed');
|
|
168
|
+
resolve();
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
OpentokSession.prototype.onMediaStreamDestroyed = function (clientRole) {
|
|
173
|
+
var _this = this;
|
|
174
|
+
|
|
175
|
+
var promises = [];
|
|
176
|
+
|
|
177
|
+
this._peerConnections.forEach(function (peerConnection) {
|
|
178
|
+
if (peerConnection.peerRole === clientRole) {
|
|
179
|
+
promises.push(_this.destroyPublisherOnPeerConnection(peerConnection));
|
|
180
|
+
}
|
|
53
181
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
enumerable: true,
|
|
59
|
-
configurable: true
|
|
182
|
+
|
|
183
|
+
return Promise.all(promises).then(function () {
|
|
184
|
+
return undefined;
|
|
60
185
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
OpentokSession.prototype.onMediaStreamRenewed = function (clientRole, mediaStream) {
|
|
189
|
+
//TODO - Alex: need to implement adding new tracks to peer connection and forcing negotiation (in OT API)
|
|
190
|
+
return Promise.resolve();
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
OpentokSession.prototype.replaceStreamTracks = function (mediaStream) {
|
|
194
|
+
return Promise.reject(new Error('Not implemented'));
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
OpentokSession.prototype.getRemoteTrackStats = function (mediaTrack) {
|
|
198
|
+
var _this = this;
|
|
199
|
+
|
|
200
|
+
return new Promise(function (resolve, reject) {
|
|
201
|
+
var peerConnectionOfTrack = _this.getPeerConnectionByMediaTrack(mediaTrack);
|
|
202
|
+
|
|
203
|
+
if (!peerConnectionOfTrack || !peerConnectionOfTrack.subscriber) {
|
|
204
|
+
reject(new Error('Cannot find peer or subscriber for getting stats'));
|
|
205
|
+
return;
|
|
206
|
+
} //https://tokbox.com/developer/sdks/js/reference/Subscriber.html#getStats
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
peerConnectionOfTrack.subscriber.getStats(function (error, stats) {
|
|
210
|
+
if (error) {
|
|
211
|
+
trace.warn('Error getting stats', error);
|
|
212
|
+
resolve({
|
|
213
|
+
trackId: mediaTrack.id,
|
|
214
|
+
trackStats: {}
|
|
215
|
+
});
|
|
216
|
+
return;
|
|
67
217
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
trace.error('handleConnect error:', error);
|
|
73
|
-
reject(error);
|
|
74
|
-
};
|
|
75
|
-
var _a = _this._sessionParams.credentials,
|
|
76
|
-
apiKey = _a.apiKey,
|
|
77
|
-
sessionId = _a.sessionId;
|
|
78
|
-
_this._session = window.OTSESSION = window.OT.initSession(apiKey, sessionId);
|
|
79
|
-
_this._session.on('connectionCreated', _this.connectionCreatedHandler);
|
|
80
|
-
_this._session.on('connectionDestroyed', _this.connectionDestroyedHandler);
|
|
81
|
-
_this._session.on('streamCreated', _this.streamCreatedHandler);
|
|
82
|
-
_this._session.on('streamDestroyed', _this.streamDestroyedHandler);
|
|
83
|
-
var connectHandler = function connectHandler(error) {
|
|
84
|
-
if (error) {
|
|
85
|
-
handleError(error);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
resolve();
|
|
89
|
-
};
|
|
90
|
-
_this._session.connect(_this._credentials.token, connectHandler);
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
OpentokSession.prototype.disconnect = function () {
|
|
94
|
-
var _this = this;
|
|
95
|
-
return new Promise(function (resolve) {
|
|
96
|
-
trace.info('Disconnecting from session');
|
|
97
|
-
var currentSession = _this._session;
|
|
98
|
-
_this._session = null;
|
|
99
|
-
_this._peerConnections.forEach(function (peerConnection) {
|
|
100
|
-
_this.destroyPeerConnection(peerConnection);
|
|
101
|
-
});
|
|
102
|
-
if (!currentSession) {
|
|
103
|
-
trace.info('No active session - resolving');
|
|
104
|
-
resolve();
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
currentSession.off();
|
|
108
|
-
currentSession.disconnect();
|
|
109
|
-
resolve();
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
OpentokSession.prototype.onMediaStreamDestroyed = function (clientRole) {
|
|
113
|
-
var _this = this;
|
|
114
|
-
var promises = [];
|
|
115
|
-
this._peerConnections.forEach(function (peerConnection) {
|
|
116
|
-
if (peerConnection.peerRole === clientRole) {
|
|
117
|
-
promises.push(_this.destroyPublisherOnPeerConnection(peerConnection));
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
return Promise.all(promises).then(function () {
|
|
121
|
-
return undefined;
|
|
218
|
+
|
|
219
|
+
resolve({
|
|
220
|
+
trackId: mediaTrack.id,
|
|
221
|
+
trackStats: stats
|
|
122
222
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}; //#region OpenTok Events Handlers
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
OpentokSession.prototype.connectionCreatedHandler = function (event) {
|
|
229
|
+
var _this = this;
|
|
230
|
+
|
|
231
|
+
trace.info('connectionCreatedHandler', event);
|
|
232
|
+
var connection = event.connection;
|
|
233
|
+
|
|
234
|
+
if (!this.sessionExistsGuard(false) || !connection) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
var destinationRole = JSON.parse(connection.data).clientRole;
|
|
239
|
+
this.createStreamForPublishing(destinationRole, connection.connectionId === this.ownPeerId).then(function (streams) {
|
|
240
|
+
var peerConnection = {
|
|
241
|
+
peerId: connection.connectionId,
|
|
242
|
+
peerRole: destinationRole,
|
|
243
|
+
peerType: _this._sessionParams.clientType === MediaConstants_1.SessionClientType.INITIATOR ? MediaConstants_1.SessionClientType.GUEST : MediaConstants_1.SessionClientType.INITIATOR,
|
|
244
|
+
connection: connection,
|
|
245
|
+
publisher: null,
|
|
246
|
+
subscriber: null,
|
|
247
|
+
remoteMediaTracks: [],
|
|
248
|
+
localStream: streams,
|
|
249
|
+
connectionTimoutPrt: null
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
if (connection.connectionId !== _this.ownPeerId || !streams.videoSource && !streams.audioSource) {
|
|
253
|
+
trace.info('Peer connection without publisher was created', peerConnection);
|
|
254
|
+
return peerConnection;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return _this.createMediaPublisher(streams).then(function (publisher) {
|
|
258
|
+
peerConnection.publisher = publisher;
|
|
259
|
+
trace.info('Peer connection with publisher was created', peerConnection);
|
|
260
|
+
return peerConnection;
|
|
261
|
+
});
|
|
262
|
+
}).then(function (peerConnection) {
|
|
263
|
+
_this._peerConnections.set(peerConnection.peerId, peerConnection);
|
|
264
|
+
|
|
265
|
+
if (connection.connectionId === _this.ownPeerId) {
|
|
266
|
+
trace.info('Before subscribe the event streams');
|
|
267
|
+
/*
|
|
268
|
+
When publisher connect after others participants,
|
|
269
|
+
make sure the publisher will not loose their stream to subscribe
|
|
270
|
+
*/
|
|
271
|
+
|
|
272
|
+
return _this._lastStreamEvents.reduce(function (promiseChain, streamEvent) {
|
|
273
|
+
return promiseChain.then(function () {
|
|
274
|
+
return _this.streamCreatedHandler(streamEvent);
|
|
275
|
+
});
|
|
276
|
+
}, Promise.resolve()).then(function () {
|
|
277
|
+
if (peerConnection.publisher) {
|
|
278
|
+
return new Promise(function (resolve, reject) {
|
|
279
|
+
trace.info('Starting publish to peerConnection.publisher');
|
|
280
|
+
|
|
281
|
+
_this._session.publish(peerConnection.publisher, function (error) {
|
|
137
282
|
if (error) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return;
|
|
283
|
+
trace.error("Publish to peerConnection error " + error);
|
|
284
|
+
return reject(error);
|
|
141
285
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
//#region OpenTok Events Handlers
|
|
147
|
-
OpentokSession.prototype.connectionCreatedHandler = function (event) {
|
|
148
|
-
var _this = this;
|
|
149
|
-
trace.info('connectionCreatedHandler', event);
|
|
150
|
-
var connection = event.connection;
|
|
151
|
-
if (!this.sessionExistsGuard(false) || !connection) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
//In case we got our own connection, we have nothing to do with it
|
|
155
|
-
if (connection.connectionId === this.ownPeerId) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
var destinationRole = this.calculateDestinationRole();
|
|
159
|
-
this.createStreamForPublishing(destinationRole).then(function (streams) {
|
|
160
|
-
var peerConnection = {
|
|
161
|
-
peerId: connection.connectionId,
|
|
162
|
-
peerRole: destinationRole,
|
|
163
|
-
peerType: _this._sessionParams.clientType === MediaConstants_1.SessionClientType.INITIATOR ? MediaConstants_1.SessionClientType.GUEST : MediaConstants_1.SessionClientType.INITIATOR,
|
|
164
|
-
connection: connection,
|
|
165
|
-
publisher: null,
|
|
166
|
-
subscriber: null,
|
|
167
|
-
remoteMediaTracks: [],
|
|
168
|
-
localStream: streams,
|
|
169
|
-
connectionTimoutPrt: null
|
|
170
|
-
};
|
|
171
|
-
if (!streams.videoSource && !streams.audioSource) {
|
|
172
|
-
trace.info('Peer connection without publisher was created', peerConnection);
|
|
173
|
-
return peerConnection;
|
|
174
|
-
}
|
|
175
|
-
var streamName = destinationRole === MediaConstants_1.SessionClientRole.USER ? MediaConstants_1.KnownMediaStream.AGENT_AUDIO_STREAM : MediaConstants_1.KnownMediaStream.USER_VIDEO_STREAM;
|
|
176
|
-
return _this.createMediaPublisher(streams, streamName).then(function (publisher) {
|
|
177
|
-
peerConnection.publisher = publisher;
|
|
178
|
-
trace.info('Peer connection with publisher was created', peerConnection);
|
|
179
|
-
return peerConnection;
|
|
286
|
+
|
|
287
|
+
trace.info('Publish to peerConnection success');
|
|
288
|
+
return resolve();
|
|
289
|
+
});
|
|
180
290
|
});
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return new Promise(function (resolve, reject) {
|
|
185
|
-
trace.info('Starting publish to peerConnection.publisher');
|
|
186
|
-
_this._session.publish(peerConnection.publisher, function (error) {
|
|
187
|
-
if (error) {
|
|
188
|
-
trace.error('Publish to peerConnection error', error);
|
|
189
|
-
return reject(error);
|
|
190
|
-
}
|
|
191
|
-
trace.info('Publish to peerConnection success');
|
|
192
|
-
return resolve();
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
return Promise.resolve();
|
|
197
|
-
}).catch(function (error) {
|
|
198
|
-
//Need to handle fail cases during reliability
|
|
199
|
-
trace.error('Error handling new peer connection', error);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return Promise.resolve();
|
|
200
294
|
});
|
|
295
|
+
}
|
|
296
|
+
})["catch"](function (error) {
|
|
297
|
+
//Need to handle fail cases during reliability
|
|
298
|
+
trace.error("Error handling new peer connection: " + error);
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
OpentokSession.prototype.connectionDestroyedHandler = function (event) {
|
|
303
|
+
trace.info('connectionDestroyedHandler', event);
|
|
304
|
+
var connection = event.connection;
|
|
305
|
+
|
|
306
|
+
if (!this.sessionExistsGuard(false) || !connection) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (this._peerConnections.has(connection.connectionId)) {
|
|
311
|
+
this.destroyPeerConnection(this._peerConnections.get(connection.connectionId));
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
OpentokSession.prototype.streamCreatedHandler = function (event) {
|
|
316
|
+
trace.info('streamCreatedHandler', event.stream);
|
|
317
|
+
var stream = event.stream;
|
|
318
|
+
var connection = (stream || {
|
|
319
|
+
connection: null
|
|
320
|
+
}).connection;
|
|
321
|
+
|
|
322
|
+
if (!this.sessionExistsGuard(false) || !stream || connection.connectionId === this.ownPeerId) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (!this._peerConnections.has(connection.connectionId)) {
|
|
327
|
+
trace.warn('Unexpected case, connection should exist on this stage');
|
|
328
|
+
|
|
329
|
+
this._lastStreamEvents.push(event);
|
|
330
|
+
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
var peerConnection = this._peerConnections.get(connection.connectionId);
|
|
335
|
+
|
|
336
|
+
trace.info('Subscribing the stream');
|
|
337
|
+
this.createMediaSubscriber(stream).then(function (subscriber) {
|
|
338
|
+
peerConnection.subscriber = subscriber;
|
|
339
|
+
});
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
OpentokSession.prototype.streamDestroyedHandler = function (event) {
|
|
343
|
+
trace.info('streamDestroyedHandler', event);
|
|
344
|
+
var stream = event.stream;
|
|
345
|
+
|
|
346
|
+
if (!this.sessionExistsGuard(false) || !stream) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
var peerConnection = this._peerConnections.get(stream.connection.connectionId);
|
|
351
|
+
|
|
352
|
+
if (!peerConnection) {
|
|
353
|
+
trace.warn('Peer connection for remote stream not found');
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
this.destroySubscriberOnPeerConnection(peerConnection)["catch"](function () {
|
|
358
|
+
return trace.warn('Error destroying subscriber on stream destroy');
|
|
359
|
+
});
|
|
360
|
+
}; //#endregion
|
|
361
|
+
//#region PeerConnection
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
OpentokSession.prototype.destroyPeerConnection = function (peerConnection) {
|
|
365
|
+
this._peerConnections["delete"](peerConnection.peerId);
|
|
366
|
+
|
|
367
|
+
this.destroyPublisherOnPeerConnection(peerConnection)["catch"](function () {
|
|
368
|
+
return trace.warn('Error destroying publisher on peer destroy');
|
|
369
|
+
});
|
|
370
|
+
this.destroySubscriberOnPeerConnection(peerConnection)["catch"](function () {
|
|
371
|
+
return trace.warn('Error destroying subscriber on peer destroy');
|
|
372
|
+
});
|
|
373
|
+
}; //#endregion
|
|
374
|
+
//#region Publisher
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
OpentokSession.prototype.createStreamForPublishing = function (destinationRole, shouldCreateStream) {
|
|
378
|
+
var _this = this;
|
|
379
|
+
|
|
380
|
+
trace.info('createStreamForPublishing');
|
|
381
|
+
var stream = {
|
|
382
|
+
videoSource: null,
|
|
383
|
+
audioSource: null
|
|
201
384
|
};
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (!this.sessionExistsGuard(false) || !stream) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
if (!this._peerConnections.has(connection.connectionId)) {
|
|
221
|
-
trace.warn('Unexpected case, connection should exist on this stage');
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
var peerConnection = this._peerConnections.get(connection.connectionId);
|
|
225
|
-
trace.info('Subscribing the stream');
|
|
226
|
-
this.createMediaSubscriber(stream).then(function (subcriber) {
|
|
227
|
-
peerConnection.subscriber = subcriber;
|
|
228
|
-
peerConnection.subscriber.on('videoElementCreated', function (args) {
|
|
229
|
-
var element = args.element;
|
|
230
|
-
var otMediaStream = element.srcObject;
|
|
231
|
-
if (!otMediaStream) {
|
|
232
|
-
trace.warn('MediaStream not found in OT video element');
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
trace.info('Registering remote media tracks', peerConnection.subscriber, otMediaStream);
|
|
236
|
-
otMediaStream.getTracks().forEach(function (mediaTrack) {
|
|
237
|
-
_this.addRemoteTrackToPeer(peerConnection, mediaTrack);
|
|
238
|
-
});
|
|
239
|
-
_this.registerPeersRemoteTracks(peerConnection);
|
|
240
|
-
});
|
|
385
|
+
|
|
386
|
+
if (!shouldCreateStream) {
|
|
387
|
+
trace.info("createStreamForPublishing - destinationRole: " + destinationRole + " not supposed to create a stream");
|
|
388
|
+
return Promise.resolve(stream);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return this._sessionStreamsManager.getMediaStreamForRole(destinationRole).then(function (mediaStream) {
|
|
392
|
+
if (mediaStream) {
|
|
393
|
+
trace.info('Media stream found for publishing', mediaStream);
|
|
394
|
+
mediaStream.getTracks().forEach(function (track) {
|
|
395
|
+
if (track.kind === 'video') {
|
|
396
|
+
stream.videoSource = track;
|
|
397
|
+
} else if (track.kind === 'audio') {
|
|
398
|
+
stream.audioSource = track;
|
|
399
|
+
}
|
|
241
400
|
});
|
|
401
|
+
} else if (_this._sessionParams.clientRole === MediaConstants_1.SessionClientRole.USER) {
|
|
402
|
+
trace.warn('No local media was found for publishing to destinationRole:', destinationRole);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return stream;
|
|
406
|
+
});
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
OpentokSession.prototype.createMediaPublisher = function (stream) {
|
|
410
|
+
var otParams = {
|
|
411
|
+
videoSource: stream.videoSource ? stream.videoSource : false,
|
|
412
|
+
audioSource: stream.audioSource ? stream.audioSource : false,
|
|
413
|
+
publishAudio: !!stream.audioSource,
|
|
414
|
+
publishVideo: !!stream.videoSource,
|
|
415
|
+
showControls: false,
|
|
416
|
+
insertDefaultUI: false
|
|
242
417
|
};
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
var peerConnection = this._peerConnections.get(stream.connection.connectionId);
|
|
250
|
-
if (!peerConnection) {
|
|
251
|
-
trace.warn('Peer connection for remote stream not found');
|
|
252
|
-
return;
|
|
418
|
+
return new Promise(function (resolve, reject) {
|
|
419
|
+
var otPublisher = window.OT.initPublisher(undefined, otParams, function (error) {
|
|
420
|
+
if (error) {
|
|
421
|
+
reject(error);
|
|
422
|
+
return;
|
|
253
423
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
OpentokSession.prototype.destroyPeerConnection = function (peerConnection) {
|
|
261
|
-
this._peerConnections.delete(peerConnection.peerId);
|
|
262
|
-
this.destroyPublisherOnPeerConnection(peerConnection).catch(function () {
|
|
263
|
-
return undefined;
|
|
264
|
-
});
|
|
265
|
-
this.destroySubscriberOnPeerConnection(peerConnection).catch(function () {
|
|
266
|
-
return undefined;
|
|
267
|
-
});
|
|
268
|
-
};
|
|
269
|
-
//#endregion
|
|
270
|
-
//#region Publisher
|
|
271
|
-
OpentokSession.prototype.createStreamForPublishing = function (destinationRole) {
|
|
272
|
-
var _this = this;
|
|
273
|
-
trace.info('createStreamForPublishing');
|
|
274
|
-
return this._sessionStreamsManager.getMediaStreamForRole(destinationRole).then(function (mediaStream) {
|
|
275
|
-
var stream = { videoSource: null, audioSource: null };
|
|
276
|
-
if (mediaStream) {
|
|
277
|
-
trace.info('Media stream found for publishing', mediaStream);
|
|
278
|
-
mediaStream.getTracks().forEach(function (track) {
|
|
279
|
-
if (track.kind === 'video') {
|
|
280
|
-
stream.videoSource = track;
|
|
281
|
-
} else if (track.kind === 'audio') {
|
|
282
|
-
stream.audioSource = track;
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
} else if (_this._sessionParams.clientRole === MediaConstants_1.SessionClientRole.USER) {
|
|
286
|
-
trace.warn('No local media was found for publishing to destinationRole:', destinationRole);
|
|
287
|
-
}
|
|
288
|
-
return stream;
|
|
424
|
+
|
|
425
|
+
otPublisher.on('streamDestroyed', function (event) {
|
|
426
|
+
trace.info('Publisher stream destroyed', event); //We preventing the default, in order to prevent stop the stream by OT.
|
|
427
|
+
//We managing streams by ourselves and if we allow OT to close the stream, it cannot be reused.
|
|
428
|
+
|
|
429
|
+
event.preventDefault();
|
|
289
430
|
});
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
var otParams = {
|
|
293
|
-
videoSource: stream.videoSource ? stream.videoSource : false,
|
|
294
|
-
audioSource: stream.audioSource ? stream.audioSource : false,
|
|
295
|
-
publishAudio: !!stream.audioSource,
|
|
296
|
-
publishVideo: !!stream.videoSource,
|
|
297
|
-
showControls: false,
|
|
298
|
-
name: streamName
|
|
299
|
-
};
|
|
300
|
-
return new Promise(function (resolve, reject) {
|
|
301
|
-
var otPublisher = window.OT.initPublisher(undefined, otParams, function (error) {
|
|
302
|
-
if (error) {
|
|
303
|
-
reject(error);
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
otPublisher.on('streamDestroyed', function (event) {
|
|
307
|
-
trace.info('Publisher stream destroyed', event);
|
|
308
|
-
//We preventing the default, in order to prevent stop the stream by OT.
|
|
309
|
-
//We managing streams by ourselves and if we allow OT to close the stream, it cannot be reused.
|
|
310
|
-
event.preventDefault();
|
|
311
|
-
});
|
|
312
|
-
otPublisher.on('videoElementCreated', function (event) {
|
|
313
|
-
document.getElementById(otPublisher.id).style.display = 'none';
|
|
314
|
-
event.element.muted = true;
|
|
315
|
-
});
|
|
316
|
-
resolve(otPublisher);
|
|
317
|
-
});
|
|
431
|
+
otPublisher.on('videoElementCreated', function (event) {
|
|
432
|
+
event.element.muted = true;
|
|
318
433
|
});
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if (this.sessionExistsGuard(false) && peerConnection.publisher) {
|
|
322
|
-
this._session.unpublish(peerConnection.publisher);
|
|
323
|
-
}
|
|
324
|
-
peerConnection.publisher = null;
|
|
325
|
-
peerConnection.localStream = null;
|
|
326
|
-
return Promise.resolve();
|
|
327
|
-
};
|
|
328
|
-
//#endregion
|
|
329
|
-
//#region Subscriber
|
|
330
|
-
OpentokSession.prototype.createMediaSubscriber = function (remoteStream) {
|
|
331
|
-
var _this = this;
|
|
332
|
-
return new Promise(function (resolve, reject) {
|
|
333
|
-
if (!_this.sessionExistsGuard(false)) {
|
|
334
|
-
reject('Session not exists');
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
var subscriber = _this._session.subscribe(remoteStream, null, null, function (err) {
|
|
338
|
-
if (err) {
|
|
339
|
-
trace.warn('Error creating subscriber', err);
|
|
340
|
-
reject(err);
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
subscriber.on('videoElementCreated', function (event) {
|
|
344
|
-
document.getElementById(subscriber.id).style.display = 'none';
|
|
345
|
-
event.element.muted = true;
|
|
346
|
-
});
|
|
347
|
-
resolve(subscriber);
|
|
348
|
-
});
|
|
434
|
+
otPublisher.on('streamCreated', function (event) {
|
|
435
|
+
trace.info('publisher stream created', event, otPublisher.stream.hasAudio);
|
|
349
436
|
});
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
437
|
+
resolve(otPublisher);
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
OpentokSession.prototype.destroyPublisherOnPeerConnection = function (peerConnection) {
|
|
443
|
+
if (this.sessionExistsGuard(false) && peerConnection.publisher) {
|
|
444
|
+
this._session.unpublish(peerConnection.publisher);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
peerConnection.publisher = null;
|
|
448
|
+
peerConnection.localStream = null;
|
|
449
|
+
return Promise.resolve();
|
|
450
|
+
}; //#endregion
|
|
451
|
+
//#region Subscriber
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
OpentokSession.prototype.createMediaSubscriber = function (remoteStream) {
|
|
455
|
+
var _this = this;
|
|
456
|
+
|
|
457
|
+
return new Promise(function (resolve, reject) {
|
|
458
|
+
if (!_this.sessionExistsGuard(false)) {
|
|
459
|
+
reject('Session not exists');
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
var subscriber = _this._session.subscribe(remoteStream, null, {
|
|
464
|
+
insertDefaultUI: false
|
|
465
|
+
}, function (err) {
|
|
466
|
+
if (err) {
|
|
467
|
+
trace.warn('Error creating subscriber', err);
|
|
468
|
+
reject(err);
|
|
469
|
+
return;
|
|
354
470
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
471
|
+
|
|
472
|
+
subscriber.on('videoElementCreated', function (event) {
|
|
473
|
+
var element = event.element;
|
|
474
|
+
|
|
475
|
+
var peerConnection = _this._peerConnections.get(remoteStream.connection.connectionId);
|
|
476
|
+
|
|
477
|
+
var otMediaStream = element.srcObject;
|
|
478
|
+
peerConnection.subscriber = subscriber;
|
|
479
|
+
|
|
480
|
+
if (!otMediaStream) {
|
|
481
|
+
trace.warn('MediaStream not found in OT video element');
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
trace.info('Registering remote media tracks', peerConnection.subscriber, otMediaStream);
|
|
486
|
+
otMediaStream.getTracks().forEach(function (mediaTrack) {
|
|
487
|
+
_this.addRemoteTrackToPeer(peerConnection, mediaTrack);
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
_this.registerPeersRemoteTracks(peerConnection);
|
|
359
491
|
});
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
return
|
|
492
|
+
resolve(subscriber);
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
OpentokSession.prototype.destroySubscriberOnPeerConnection = function (peerConnection) {
|
|
498
|
+
if (this.sessionExistsGuard(false) && peerConnection.subscriber) {
|
|
499
|
+
this._session.unsubscribe(peerConnection.subscriber);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
peerConnection.subscriber = null;
|
|
503
|
+
return Promise.resolve();
|
|
504
|
+
/**
|
|
505
|
+
REMARK- opentok provide the same media track id for all participates.
|
|
506
|
+
when we unregister the media track we check by the id which is the same for all.
|
|
507
|
+
**/
|
|
508
|
+
// return this.unregisterPeersRemoteMediaTracks(peerConnection)
|
|
509
|
+
// .catch(() => trace.warn('Error removing remote streams from peerConnection'))
|
|
510
|
+
// .then(() => {
|
|
511
|
+
// peerConnection.subscriber = null;
|
|
512
|
+
// });
|
|
513
|
+
}; //#endregion
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
OpentokSession.prototype.sessionExistsGuard = function (shouldThrow) {
|
|
517
|
+
if (shouldThrow === void 0) {
|
|
518
|
+
shouldThrow = true;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
var connected = !!(this._session && this._session.connection && this._session.connection.connectionId);
|
|
522
|
+
return guards_1.throwableGuard(connected, 'There no OpenTok session exists', shouldThrow);
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
return OpentokSession;
|
|
377
526
|
}(MediaSessionBase_1.MediaSessionBase);
|
|
378
|
-
exports.OpentokSession = OpentokSession;
|
|
379
527
|
|
|
380
|
-
|
|
528
|
+
exports.OpentokSession = OpentokSession;
|
|
381
529
|
//# sourceMappingURL=SessionOpentok.js.map
|