@techsee/techsee-media-service 18.6.1 → 19.1.0
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 +1 -0
- package/lib/LocalStreamManager.d.ts.map +1 -1
- package/lib/LocalStreamManager.js +320 -441
- package/lib/LocalStreamManager.js.map +1 -1
- package/lib/MediaConstants.d.ts +1 -0
- package/lib/MediaConstants.d.ts.map +1 -1
- package/lib/MediaConstants.js +53 -95
- package/lib/MediaConstants.js.map +1 -1
- package/lib/MediaContracts.d.ts +1 -0
- package/lib/MediaContracts.d.ts.map +1 -1
- package/lib/MediaContracts.js +2 -5
- package/lib/MediaContracts.js.map +1 -1
- package/lib/MediaPublisher.d.ts +1 -0
- package/lib/MediaPublisher.d.ts.map +1 -1
- package/lib/MediaPublisher.js +36 -49
- package/lib/MediaPublisher.js.map +1 -1
- package/lib/MediaServiceBase.d.ts +1 -0
- package/lib/MediaServiceBase.d.ts.map +1 -1
- package/lib/MediaServiceBase.js +687 -937
- package/lib/MediaServiceBase.js.map +1 -1
- package/lib/MediaSession/MediaServer.d.ts +1 -0
- package/lib/MediaSession/MediaServer.d.ts.map +1 -1
- package/lib/MediaSession/MediaServer.js +372 -517
- package/lib/MediaSession/MediaServer.js.map +1 -1
- package/lib/MediaSession/MediaSessionBase.d.ts +1 -0
- package/lib/MediaSession/MediaSessionBase.d.ts.map +1 -1
- package/lib/MediaSession/MediaSessionBase.js +88 -127
- package/lib/MediaSession/MediaSessionBase.js.map +1 -1
- package/lib/MediaSession/SessionOpentok.d.ts +1 -0
- package/lib/MediaSession/SessionOpentok.d.ts.map +1 -1
- package/lib/MediaSession/SessionOpentok.js +357 -503
- package/lib/MediaSession/SessionOpentok.js.map +1 -1
- package/lib/MediaSession/SessionTurn.d.ts +1 -0
- package/lib/MediaSession/SessionTurn.d.ts.map +1 -1
- package/lib/MediaSession/SessionTurn.js +431 -613
- package/lib/MediaSession/SessionTurn.js.map +1 -1
- package/lib/MediaSession/TurnConstants.d.ts +1 -0
- package/lib/MediaSession/TurnConstants.d.ts.map +1 -1
- package/lib/MediaSession/TurnConstants.js +17 -32
- package/lib/MediaSession/TurnConstants.js.map +1 -1
- package/lib/MediaSubscriber.d.ts +1 -0
- package/lib/MediaSubscriber.d.ts.map +1 -1
- package/lib/MediaSubscriber.js +189 -245
- package/lib/MediaSubscriber.js.map +1 -1
- package/lib/MediaUtils/Compatibility.d.ts +1 -0
- package/lib/MediaUtils/Compatibility.d.ts.map +1 -1
- package/lib/MediaUtils/Compatibility.js +129 -283
- package/lib/MediaUtils/Compatibility.js.map +1 -1
- package/lib/MediaUtils/MediaDomUtils.d.ts +1 -0
- package/lib/MediaUtils/MediaDomUtils.d.ts.map +1 -1
- package/lib/MediaUtils/MediaDomUtils.js +184 -252
- package/lib/MediaUtils/MediaDomUtils.js.map +1 -1
- package/lib/MediaUtils/MediaTracer.d.ts +1 -0
- package/lib/MediaUtils/MediaTracer.d.ts.map +1 -1
- package/lib/MediaUtils/MediaTracer.js +3 -10
- package/lib/MediaUtils/MediaTracer.js.map +1 -1
- package/lib/MediaUtils/index.d.ts +1 -0
- package/lib/MediaUtils/index.d.ts.map +1 -1
- package/lib/MediaUtils/index.js +3 -13
- package/lib/MediaUtils/index.js.map +1 -1
- package/lib/MultiParty/DetectWebRtcService.d.ts +1 -0
- package/lib/MultiParty/DetectWebRtcService.d.ts.map +1 -1
- package/lib/MultiParty/DetectWebRtcService.js +92 -241
- package/lib/MultiParty/DetectWebRtcService.js.map +1 -1
- package/lib/MultiParty/MediaCapabilitiesService.d.ts +1 -0
- package/lib/MultiParty/MediaCapabilitiesService.d.ts.map +1 -1
- package/lib/MultiParty/MediaCapabilitiesService.js +143 -312
- package/lib/MultiParty/MediaCapabilitiesService.js.map +1 -1
- package/lib/MultiParty/MediaCapabilitiesUtils.d.ts +1 -0
- package/lib/MultiParty/MediaCapabilitiesUtils.d.ts.map +1 -1
- package/lib/MultiParty/MediaCapabilitiesUtils.js +95 -277
- package/lib/MultiParty/MediaCapabilitiesUtils.js.map +1 -1
- package/lib/MultiParty/MediaTracer.d.ts +1 -0
- package/lib/MultiParty/MediaTracer.d.ts.map +1 -1
- package/lib/MultiParty/MediaTracer.js +3 -10
- package/lib/MultiParty/MediaTracer.js.map +1 -1
- package/lib/MultiParty/MultiPartyService.d.ts +1 -0
- package/lib/MultiParty/MultiPartyService.d.ts.map +1 -1
- package/lib/MultiParty/MultiPartyService.js +24 -47
- package/lib/MultiParty/MultiPartyService.js.map +1 -1
- package/lib/MultiParty/MultiPartyServiceFactory.d.ts +2 -1
- package/lib/MultiParty/MultiPartyServiceFactory.d.ts.map +1 -1
- package/lib/MultiParty/MultiPartyServiceFactory.js +7 -15
- package/lib/MultiParty/MultiPartyServiceFactory.js.map +1 -1
- package/lib/MultiParty/MultipartyServiceEventTypes.d.ts +1 -0
- package/lib/MultiParty/MultipartyServiceEventTypes.d.ts.map +1 -1
- package/lib/MultiParty/MultipartyServiceEventTypes.js +11 -15
- package/lib/MultiParty/MultipartyServiceEventTypes.js.map +1 -1
- package/lib/MultiParty/index.d.ts +1 -0
- package/lib/MultiParty/index.d.ts.map +1 -1
- package/lib/MultiParty/index.js +15 -35
- package/lib/MultiParty/index.js.map +1 -1
- package/lib/MultiParty/opentok/OpentokMultiPartyService.d.ts +2 -1
- package/lib/MultiParty/opentok/OpentokMultiPartyService.d.ts.map +1 -1
- package/lib/MultiParty/opentok/OpentokMultiPartyService.js +457 -839
- package/lib/MultiParty/opentok/OpentokMultiPartyService.js.map +1 -1
- package/lib/MultiParty/opentok/OpentokPublisher.d.ts +1 -0
- package/lib/MultiParty/opentok/OpentokPublisher.d.ts.map +1 -1
- package/lib/MultiParty/opentok/OpentokPublisher.js +107 -269
- package/lib/MultiParty/opentok/OpentokPublisher.js.map +1 -1
- package/lib/MultiParty/opentok/OpentokPublisherEventMapper.d.ts +1 -0
- package/lib/MultiParty/opentok/OpentokPublisherEventMapper.d.ts.map +1 -1
- package/lib/MultiParty/opentok/OpentokPublisherEventMapper.js +34 -54
- package/lib/MultiParty/opentok/OpentokPublisherEventMapper.js.map +1 -1
- package/lib/MultiParty/opentok/OpentokScreenPublisher.d.ts +1 -0
- package/lib/MultiParty/opentok/OpentokScreenPublisher.d.ts.map +1 -1
- package/lib/MultiParty/opentok/OpentokScreenPublisher.js +40 -77
- package/lib/MultiParty/opentok/OpentokScreenPublisher.js.map +1 -1
- package/lib/MultiParty/opentok/OpentokSubscriber.d.ts +1 -0
- package/lib/MultiParty/opentok/OpentokSubscriber.d.ts.map +1 -1
- package/lib/MultiParty/opentok/OpentokSubscriber.js +20 -28
- package/lib/MultiParty/opentok/OpentokSubscriber.js.map +1 -1
- package/lib/MultiParty/opentok/OpentokVideoPublisher.d.ts +1 -0
- package/lib/MultiParty/opentok/OpentokVideoPublisher.d.ts.map +1 -1
- package/lib/MultiParty/opentok/OpentokVideoPublisher.js +150 -355
- package/lib/MultiParty/opentok/OpentokVideoPublisher.js.map +1 -1
- package/lib/MultiParty/opentok/trace.d.ts +1 -0
- package/lib/MultiParty/opentok/trace.d.ts.map +1 -1
- package/lib/MultiParty/opentok/trace.js +11 -24
- package/lib/MultiParty/opentok/trace.js.map +1 -1
- package/lib/MultiParty/types.d.ts +1 -0
- package/lib/MultiParty/types.d.ts.map +1 -1
- package/lib/MultiParty/types.js +2 -5
- package/lib/MultiParty/types.js.map +1 -1
- package/lib/MultiParty/utils.d.ts +1 -0
- package/lib/MultiParty/utils.d.ts.map +1 -1
- package/lib/MultiParty/utils.js +5 -15
- package/lib/MultiParty/utils.js.map +1 -1
- package/lib/TechseeMediaStream.d.ts +1 -0
- package/lib/TechseeMediaStream.d.ts.map +1 -1
- package/lib/TechseeMediaStream.js +53 -61
- package/lib/TechseeMediaStream.js.map +1 -1
- package/lib/qos/raw-qos.d.ts +29 -0
- package/lib/qos/raw-qos.d.ts.map +1 -0
- package/lib/qos/raw-qos.js +247 -382
- package/lib/qos/raw-qos.js.map +1 -1
- package/lib/webrtc-ie-shim.d.ts +4 -0
- package/lib/webrtc-ie-shim.d.ts.map +1 -0
- package/lib/webrtc-ie-shim.js +1999 -3454
- package/lib/webrtc-ie-shim.js.map +1 -1
- package/package.json +42 -46
|
@@ -1,529 +1,383 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
}
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
13
8
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
26
|
-
};
|
|
27
|
-
}();
|
|
28
|
-
|
|
29
|
-
Object.defineProperty(exports, "__esModule", {
|
|
30
|
-
value: true
|
|
31
|
-
});
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
18
|
exports.OpentokSession = void 0;
|
|
33
|
-
|
|
34
19
|
var MediaConstants_1 = require("../MediaConstants");
|
|
35
|
-
|
|
36
20
|
var guards_1 = require("@techsee/techsee-common/lib/core/guards");
|
|
37
|
-
|
|
38
21
|
var MediaSessionBase_1 = require("./MediaSessionBase");
|
|
39
|
-
|
|
40
22
|
var MediaTracer_1 = require("../MediaUtils/MediaTracer");
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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');
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return new Promise(function (resolve, reject) {
|
|
100
|
-
var handleError = function handleError(error) {
|
|
101
|
-
_this._session && _this._session.off();
|
|
23
|
+
var trace = (0, MediaTracer_1.getMediaTracer)('OpentokSession');
|
|
24
|
+
var OpentokSession = (function (_super) {
|
|
25
|
+
__extends(OpentokSession, _super);
|
|
26
|
+
function OpentokSession(sessionParams, streamFactory) {
|
|
27
|
+
var _this = _super.call(this, sessionParams, streamFactory) || this;
|
|
28
|
+
_this._lastStreamEvents = [];
|
|
102
29
|
_this._session = null;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
}
|
|
30
|
+
_this._credentials = sessionParams.credentials;
|
|
31
|
+
_this.connect = _this.connect.bind(_this);
|
|
32
|
+
_this.disconnect = _this.disconnect.bind(_this);
|
|
33
|
+
_this.onMediaStreamDestroyed = _this.onMediaStreamDestroyed.bind(_this);
|
|
34
|
+
_this.onMediaStreamRenewed = _this.onMediaStreamRenewed.bind(_this);
|
|
35
|
+
_this.createStreamForPublishing = _this.createStreamForPublishing.bind(_this);
|
|
36
|
+
_this.createMediaPublisher = _this.createMediaPublisher.bind(_this);
|
|
37
|
+
_this.connectionCreatedHandler = _this.connectionCreatedHandler.bind(_this);
|
|
38
|
+
_this.connectionDestroyedHandler = _this.connectionDestroyedHandler.bind(_this);
|
|
39
|
+
_this.streamCreatedHandler = _this.streamCreatedHandler.bind(_this);
|
|
40
|
+
_this.streamDestroyedHandler = _this.streamDestroyedHandler.bind(_this);
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
Object.defineProperty(OpentokSession.prototype, "id", {
|
|
44
|
+
get: function () {
|
|
45
|
+
return this._session && this._session.sessionId ? this._session.sessionId : '';
|
|
46
|
+
},
|
|
47
|
+
enumerable: false,
|
|
48
|
+
configurable: true
|
|
181
49
|
});
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
50
|
+
Object.defineProperty(OpentokSession.prototype, "ownPeerId", {
|
|
51
|
+
get: function () {
|
|
52
|
+
return this._session && this._session.connection ? this._session.connection.connectionId : '';
|
|
53
|
+
},
|
|
54
|
+
enumerable: false,
|
|
55
|
+
configurable: true
|
|
185
56
|
});
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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;
|
|
57
|
+
OpentokSession.prototype.sessionDisconnect = function () {
|
|
58
|
+
if (this._session) {
|
|
59
|
+
this._session.disconnect();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
OpentokSession.prototype.connect = function () {
|
|
63
|
+
var _this = this;
|
|
64
|
+
trace.info('Connect to session', this._credentials);
|
|
65
|
+
if (this._session) {
|
|
66
|
+
trace.error('Session already exists');
|
|
67
|
+
return Promise.reject('Cannot connect to session while another session is active');
|
|
217
68
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
69
|
+
return new Promise(function (resolve, reject) {
|
|
70
|
+
var handleError = function (error) {
|
|
71
|
+
_this._session && _this._session.off();
|
|
72
|
+
_this._session = null;
|
|
73
|
+
trace.error('handleConnect error:', error);
|
|
74
|
+
reject(error);
|
|
75
|
+
};
|
|
76
|
+
var _a = _this._sessionParams.credentials, apiKey = _a.apiKey, sessionId = _a.sessionId;
|
|
77
|
+
_this._session = window.OTSESSION = window.OT.initSession(apiKey, sessionId);
|
|
78
|
+
_this._lastStreamEvents = [];
|
|
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
|
+
_this._session.on('archiveStarted', function (event) {
|
|
84
|
+
trace.info('archiveStarted event', event);
|
|
85
|
+
_this.emitEvent(MediaSessionBase_1.recordingEvents.RECORD_STARTED, event);
|
|
86
|
+
});
|
|
87
|
+
_this._session.on('archiveStopped', function (event) {
|
|
88
|
+
trace.info('archiveStopped event', event);
|
|
89
|
+
_this.emitEvent(MediaSessionBase_1.recordingEvents.RECORD_STOPPED, event);
|
|
90
|
+
});
|
|
91
|
+
var connectHandler = function (error) {
|
|
92
|
+
if (error) {
|
|
93
|
+
handleError(error);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
resolve();
|
|
97
|
+
};
|
|
98
|
+
_this._session.connect(_this._credentials.token, connectHandler);
|
|
222
99
|
});
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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) {
|
|
100
|
+
};
|
|
101
|
+
OpentokSession.prototype.disconnect = function () {
|
|
102
|
+
var _this = this;
|
|
103
|
+
return new Promise(function (resolve) {
|
|
104
|
+
trace.info('Disconnecting from session');
|
|
105
|
+
var currentSession = _this._session;
|
|
106
|
+
_this._session = null;
|
|
107
|
+
_this._peerConnections.forEach(function (peerConnection) {
|
|
108
|
+
_this.destroyPeerConnection(peerConnection);
|
|
109
|
+
});
|
|
110
|
+
if (!currentSession) {
|
|
111
|
+
trace.info('No active session - resolving');
|
|
112
|
+
resolve();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
currentSession.off();
|
|
116
|
+
currentSession.disconnect();
|
|
117
|
+
_this._lastStreamEvents = [];
|
|
118
|
+
trace.info('Disconnection from session completed');
|
|
119
|
+
resolve();
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
OpentokSession.prototype.onMediaStreamDestroyed = function (clientRole) {
|
|
123
|
+
var _this = this;
|
|
124
|
+
var promises = [];
|
|
125
|
+
this._peerConnections.forEach(function (peerConnection) {
|
|
126
|
+
if (peerConnection.peerRole === clientRole) {
|
|
127
|
+
promises.push(_this.destroyPublisherOnPeerConnection(peerConnection));
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return Promise.all(promises).then(function () { return undefined; });
|
|
131
|
+
};
|
|
132
|
+
OpentokSession.prototype.onMediaStreamRenewed = function (clientRole, mediaStream) {
|
|
133
|
+
return Promise.resolve();
|
|
134
|
+
};
|
|
135
|
+
OpentokSession.prototype.replaceStreamTracks = function (mediaStream) {
|
|
136
|
+
return Promise.reject(new Error('Not implemented'));
|
|
137
|
+
};
|
|
138
|
+
OpentokSession.prototype.getRemoteTrackStats = function (mediaTrack) {
|
|
139
|
+
var _this = this;
|
|
140
|
+
return new Promise(function (resolve, reject) {
|
|
141
|
+
var peerConnectionOfTrack = _this.getPeerConnectionByMediaTrack(mediaTrack);
|
|
142
|
+
if (!peerConnectionOfTrack || !peerConnectionOfTrack.subscriber) {
|
|
143
|
+
reject(new Error('Cannot find peer or subscriber for getting stats'));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
peerConnectionOfTrack.subscriber.getStats(function (error, stats) {
|
|
282
147
|
if (error) {
|
|
283
|
-
|
|
284
|
-
|
|
148
|
+
trace.warn('Error getting stats', error);
|
|
149
|
+
resolve({ trackId: mediaTrack.id, trackStats: {} });
|
|
150
|
+
return;
|
|
285
151
|
}
|
|
286
|
-
|
|
287
|
-
trace.info('Publish to peerConnection success');
|
|
288
|
-
return resolve();
|
|
289
|
-
});
|
|
152
|
+
resolve({ trackId: mediaTrack.id, trackStats: stats });
|
|
290
153
|
});
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return Promise.resolve();
|
|
294
154
|
});
|
|
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
|
|
384
155
|
};
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
156
|
+
OpentokSession.prototype.connectionCreatedHandler = function (event) {
|
|
157
|
+
var _this = this;
|
|
158
|
+
trace.info('connectionCreatedHandler', event);
|
|
159
|
+
var connection = event.connection;
|
|
160
|
+
if (!this.sessionExistsGuard(false) || !connection) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
var destinationRole = JSON.parse(connection.data).clientRole;
|
|
164
|
+
this.createStreamForPublishing(destinationRole, connection.connectionId === this.ownPeerId)
|
|
165
|
+
.then(function (streams) {
|
|
166
|
+
var peerConnection = {
|
|
167
|
+
peerId: connection.connectionId,
|
|
168
|
+
peerRole: destinationRole,
|
|
169
|
+
peerType: _this._sessionParams.clientType === MediaConstants_1.SessionClientType.INITIATOR
|
|
170
|
+
? MediaConstants_1.SessionClientType.GUEST
|
|
171
|
+
: MediaConstants_1.SessionClientType.INITIATOR,
|
|
172
|
+
connection: connection,
|
|
173
|
+
publisher: null,
|
|
174
|
+
subscriber: null,
|
|
175
|
+
remoteMediaTracks: [],
|
|
176
|
+
localStream: streams,
|
|
177
|
+
connectionTimoutPrt: null
|
|
178
|
+
};
|
|
179
|
+
if (connection.connectionId !== _this.ownPeerId || (!streams.videoSource && !streams.audioSource)) {
|
|
180
|
+
trace.info('Peer connection without publisher was created', peerConnection);
|
|
181
|
+
return peerConnection;
|
|
182
|
+
}
|
|
183
|
+
return _this.createMediaPublisher(streams).then(function (publisher) {
|
|
184
|
+
peerConnection.publisher = publisher;
|
|
185
|
+
trace.info('Peer connection with publisher was created', peerConnection);
|
|
186
|
+
return peerConnection;
|
|
187
|
+
});
|
|
188
|
+
})
|
|
189
|
+
.then(function (peerConnection) {
|
|
190
|
+
_this._peerConnections.set(peerConnection.peerId, peerConnection);
|
|
191
|
+
if (connection.connectionId === _this.ownPeerId) {
|
|
192
|
+
trace.info('Before subscribe the event streams');
|
|
193
|
+
return _this._lastStreamEvents
|
|
194
|
+
.reduce(function (promiseChain, streamEvent) {
|
|
195
|
+
return promiseChain.then(function () { return _this.streamCreatedHandler(streamEvent); });
|
|
196
|
+
}, Promise.resolve())
|
|
197
|
+
.then(function () {
|
|
198
|
+
if (peerConnection.publisher) {
|
|
199
|
+
return new Promise(function (resolve, reject) {
|
|
200
|
+
trace.info('Starting publish to peerConnection.publisher');
|
|
201
|
+
_this._session.publish(peerConnection.publisher, function (error) {
|
|
202
|
+
if (error) {
|
|
203
|
+
trace.error("Publish to peerConnection error ".concat(error));
|
|
204
|
+
return reject(error);
|
|
205
|
+
}
|
|
206
|
+
trace.info('Publish to peerConnection success');
|
|
207
|
+
return resolve();
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return Promise.resolve();
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
})
|
|
215
|
+
.catch(function (error) {
|
|
216
|
+
trace.error("Error handling new peer connection: ".concat(error));
|
|
400
217
|
});
|
|
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
|
|
417
218
|
};
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
219
|
+
OpentokSession.prototype.connectionDestroyedHandler = function (event) {
|
|
220
|
+
trace.info('connectionDestroyedHandler', event);
|
|
221
|
+
var connection = event.connection;
|
|
222
|
+
if (!this.sessionExistsGuard(false) || !connection) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (this._peerConnections.has(connection.connectionId)) {
|
|
226
|
+
this.destroyPeerConnection(this._peerConnections.get(connection.connectionId));
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
OpentokSession.prototype.streamCreatedHandler = function (event) {
|
|
230
|
+
trace.info('streamCreatedHandler', event.stream);
|
|
231
|
+
var stream = event.stream;
|
|
232
|
+
var connection = (stream || { connection: null }).connection;
|
|
233
|
+
if (!this.sessionExistsGuard(false) || !stream || connection.connectionId === this.ownPeerId) {
|
|
234
|
+
return;
|
|
423
235
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
236
|
+
if (!this._peerConnections.has(connection.connectionId)) {
|
|
237
|
+
trace.warn('Unexpected case, connection should exist on this stage');
|
|
238
|
+
this._lastStreamEvents.push(event);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
var peerConnection = this._peerConnections.get(connection.connectionId);
|
|
242
|
+
trace.info('Subscribing the stream');
|
|
243
|
+
this.createMediaSubscriber(stream).then(function (subscriber) {
|
|
244
|
+
peerConnection.subscriber = subscriber;
|
|
430
245
|
});
|
|
431
|
-
|
|
432
|
-
|
|
246
|
+
};
|
|
247
|
+
OpentokSession.prototype.streamDestroyedHandler = function (event) {
|
|
248
|
+
trace.info('streamDestroyedHandler', event);
|
|
249
|
+
var stream = event.stream;
|
|
250
|
+
if (!this.sessionExistsGuard(false) || !stream) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
var peerConnection = this._peerConnections.get(stream.connection.connectionId);
|
|
254
|
+
if (!peerConnection) {
|
|
255
|
+
trace.warn('Peer connection for remote stream not found');
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
this.destroySubscriberOnPeerConnection(peerConnection).catch(function () {
|
|
259
|
+
return trace.warn('Error destroying subscriber on stream destroy');
|
|
433
260
|
});
|
|
434
|
-
|
|
435
|
-
|
|
261
|
+
};
|
|
262
|
+
OpentokSession.prototype.destroyPeerConnection = function (peerConnection) {
|
|
263
|
+
this._peerConnections.delete(peerConnection.peerId);
|
|
264
|
+
this.destroyPublisherOnPeerConnection(peerConnection).catch(function () {
|
|
265
|
+
return trace.warn('Error destroying publisher on peer destroy');
|
|
436
266
|
});
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
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;
|
|
267
|
+
this.destroySubscriberOnPeerConnection(peerConnection).catch(function () {
|
|
268
|
+
return trace.warn('Error destroying subscriber on peer destroy');
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
OpentokSession.prototype.createStreamForPublishing = function (destinationRole, shouldCreateStream) {
|
|
272
|
+
var _this = this;
|
|
273
|
+
trace.info('createStreamForPublishing');
|
|
274
|
+
var stream = { videoSource: null, audioSource: null };
|
|
275
|
+
if (!shouldCreateStream) {
|
|
276
|
+
trace.info("createStreamForPublishing - destinationRole: ".concat(destinationRole, " not supposed to create a stream"));
|
|
277
|
+
return Promise.resolve(stream);
|
|
470
278
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
_this.registerPeersRemoteTracks(peerConnection);
|
|
279
|
+
return this._sessionStreamsManager
|
|
280
|
+
.getMediaStreamForRole(destinationRole)
|
|
281
|
+
.then(function (mediaStream) {
|
|
282
|
+
if (mediaStream) {
|
|
283
|
+
trace.info('Media stream found for publishing', mediaStream);
|
|
284
|
+
mediaStream.getTracks().forEach(function (track) {
|
|
285
|
+
if (track.kind === 'video') {
|
|
286
|
+
stream.videoSource = track;
|
|
287
|
+
}
|
|
288
|
+
else if (track.kind === 'audio') {
|
|
289
|
+
stream.audioSource = track;
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
else if (_this._sessionParams.clientRole === MediaConstants_1.SessionClientRole.USER) {
|
|
294
|
+
trace.warn('No local media was found for publishing to destinationRole:', destinationRole);
|
|
295
|
+
}
|
|
296
|
+
return stream;
|
|
491
297
|
});
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
298
|
+
};
|
|
299
|
+
OpentokSession.prototype.createMediaPublisher = function (stream) {
|
|
300
|
+
var otParams = {
|
|
301
|
+
videoSource: stream.videoSource ? stream.videoSource : false,
|
|
302
|
+
audioSource: stream.audioSource ? stream.audioSource : false,
|
|
303
|
+
publishAudio: !!stream.audioSource,
|
|
304
|
+
publishVideo: !!stream.videoSource,
|
|
305
|
+
showControls: false,
|
|
306
|
+
insertDefaultUI: false
|
|
307
|
+
};
|
|
308
|
+
return new Promise(function (resolve, reject) {
|
|
309
|
+
var otPublisher = window.OT.initPublisher(undefined, otParams, function (error) {
|
|
310
|
+
if (error) {
|
|
311
|
+
reject(error);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
otPublisher.on('streamDestroyed', function (event) {
|
|
315
|
+
trace.info('Publisher stream destroyed', event);
|
|
316
|
+
event.preventDefault();
|
|
317
|
+
});
|
|
318
|
+
otPublisher.on('videoElementCreated', function (event) {
|
|
319
|
+
event.element.muted = true;
|
|
320
|
+
});
|
|
321
|
+
otPublisher.on('streamCreated', function (event) {
|
|
322
|
+
trace.info('publisher stream created', event, otPublisher.stream.hasAudio);
|
|
323
|
+
});
|
|
324
|
+
resolve(otPublisher);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
OpentokSession.prototype.destroyPublisherOnPeerConnection = function (peerConnection) {
|
|
329
|
+
if (this.sessionExistsGuard(false) && peerConnection.publisher) {
|
|
330
|
+
this._session.unpublish(peerConnection.publisher);
|
|
331
|
+
}
|
|
332
|
+
peerConnection.publisher = null;
|
|
333
|
+
peerConnection.localStream = null;
|
|
334
|
+
return Promise.resolve();
|
|
335
|
+
};
|
|
336
|
+
OpentokSession.prototype.createMediaSubscriber = function (remoteStream) {
|
|
337
|
+
var _this = this;
|
|
338
|
+
return new Promise(function (resolve, reject) {
|
|
339
|
+
if (!_this.sessionExistsGuard(false)) {
|
|
340
|
+
reject('Session not exists');
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
var subscriber = _this._session.subscribe(remoteStream, null, { insertDefaultUI: false }, function (err) {
|
|
344
|
+
if (err) {
|
|
345
|
+
trace.warn('Error creating subscriber', err);
|
|
346
|
+
reject(err);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
subscriber.on('videoElementCreated', function (event) {
|
|
350
|
+
var element = event.element;
|
|
351
|
+
var peerConnection = _this._peerConnections.get(remoteStream.connection.connectionId);
|
|
352
|
+
var otMediaStream = element.srcObject;
|
|
353
|
+
peerConnection.subscriber = subscriber;
|
|
354
|
+
if (!otMediaStream) {
|
|
355
|
+
trace.warn('MediaStream not found in OT video element');
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
trace.info('Registering remote media tracks', peerConnection.subscriber, otMediaStream);
|
|
359
|
+
otMediaStream.getTracks().forEach(function (mediaTrack) {
|
|
360
|
+
_this.addRemoteTrackToPeer(peerConnection, mediaTrack);
|
|
361
|
+
});
|
|
362
|
+
_this.registerPeersRemoteTracks(peerConnection);
|
|
363
|
+
});
|
|
364
|
+
resolve(subscriber);
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
};
|
|
368
|
+
OpentokSession.prototype.destroySubscriberOnPeerConnection = function (peerConnection) {
|
|
369
|
+
if (this.sessionExistsGuard(false) && peerConnection.subscriber) {
|
|
370
|
+
this._session.unsubscribe(peerConnection.subscriber);
|
|
371
|
+
}
|
|
372
|
+
peerConnection.subscriber = null;
|
|
373
|
+
return Promise.resolve();
|
|
374
|
+
};
|
|
375
|
+
OpentokSession.prototype.sessionExistsGuard = function (shouldThrow) {
|
|
376
|
+
if (shouldThrow === void 0) { shouldThrow = true; }
|
|
377
|
+
var connected = !!(this._session && this._session.connection && this._session.connection.connectionId);
|
|
378
|
+
return (0, guards_1.throwableGuard)(connected, 'There no OpenTok session exists', shouldThrow);
|
|
379
|
+
};
|
|
380
|
+
return OpentokSession;
|
|
381
|
+
}(MediaSessionBase_1.MediaSessionBase));
|
|
528
382
|
exports.OpentokSession = OpentokSession;
|
|
529
|
-
//# sourceMappingURL=SessionOpentok.js.map
|
|
383
|
+
//# sourceMappingURL=SessionOpentok.js.map
|