@techsee/techsee-media-service 18.6.1 → 19.0.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 -45
|
@@ -1,538 +1,393 @@
|
|
|
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
|
-
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
30
|
-
return mod && mod.__esModule ? mod : {
|
|
31
|
-
"default": mod
|
|
32
|
-
};
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
19
|
};
|
|
34
|
-
|
|
35
|
-
Object.defineProperty(exports, "__esModule", {
|
|
36
|
-
value: true
|
|
37
|
-
});
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
21
|
exports.MediaServerSession = void 0;
|
|
39
|
-
|
|
40
22
|
var MediaSessionBase_1 = require("./MediaSessionBase");
|
|
41
|
-
|
|
42
23
|
var MediaConstants_1 = require("../MediaConstants");
|
|
43
|
-
|
|
44
24
|
var openvidu_browser_1 = require("@techsee/openvidu-browser");
|
|
45
|
-
|
|
46
25
|
var MediaTracer_1 = require("../MediaUtils/MediaTracer");
|
|
47
|
-
|
|
48
26
|
var guards_1 = require("@techsee/techsee-common/lib/core/guards");
|
|
49
|
-
|
|
50
27
|
var bluebird_1 = require("bluebird");
|
|
51
|
-
|
|
52
28
|
var get_1 = __importDefault(require("lodash/get"));
|
|
53
|
-
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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);
|
|
29
|
+
var trace = (0, MediaTracer_1.getMediaTracer)('MediaServerSession');
|
|
30
|
+
var MediaServerSession = (function (_super) {
|
|
31
|
+
__extends(MediaServerSession, _super);
|
|
32
|
+
function MediaServerSession(sessionParams, streamFactory) {
|
|
33
|
+
var _this = _super.call(this, sessionParams, streamFactory) || this;
|
|
34
|
+
_this.OV = null;
|
|
35
|
+
_this._session = null;
|
|
36
|
+
_this._lastStreamEvents = [];
|
|
37
|
+
_this._credentials = sessionParams.credentials;
|
|
38
|
+
_this.connect = _this.connect.bind(_this);
|
|
39
|
+
_this.disconnect = _this.disconnect.bind(_this);
|
|
40
|
+
_this.onMediaStreamDestroyed = _this.onMediaStreamDestroyed.bind(_this);
|
|
41
|
+
_this.onPublisherDestroyed = _this.onPublisherDestroyed.bind(_this);
|
|
42
|
+
_this.onMediaStreamRenewed = _this.onMediaStreamRenewed.bind(_this);
|
|
43
|
+
_this.createStreamForPublishing = _this.createStreamForPublishing.bind(_this);
|
|
44
|
+
_this.createMediaPublisher = _this.createMediaPublisher.bind(_this);
|
|
45
|
+
_this.connectionCreatedHandler = _this.connectionCreatedHandler.bind(_this);
|
|
46
|
+
_this.connectionDestroyedHandler = _this.connectionDestroyedHandler.bind(_this);
|
|
47
|
+
_this.streamCreatedHandler = _this.streamCreatedHandler.bind(_this);
|
|
48
|
+
_this.streamDestroyedHandler = _this.streamDestroyedHandler.bind(_this);
|
|
49
|
+
return _this;
|
|
314
50
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
peerConnection.subscriber = null;
|
|
51
|
+
Object.defineProperty(MediaServerSession.prototype, "ownPeerId", {
|
|
52
|
+
get: function () {
|
|
53
|
+
return this._session && this._session.connection ? this._session.connection.connectionId : '';
|
|
54
|
+
},
|
|
55
|
+
enumerable: false,
|
|
56
|
+
configurable: true
|
|
322
57
|
});
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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);
|
|
58
|
+
MediaServerSession.prototype.connect = function (connectOnly) {
|
|
59
|
+
trace.info('Connect to session', this._credentials);
|
|
60
|
+
if (this._session) {
|
|
61
|
+
trace.error('Session already exists');
|
|
62
|
+
return bluebird_1.Promise.reject('Cannot connect to session while another session is active');
|
|
354
63
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
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
|
-
}
|
|
64
|
+
this.OV = new openvidu_browser_1.OpenVidu();
|
|
65
|
+
this._session = this.OV.initSession();
|
|
66
|
+
this.initSessionEvents();
|
|
67
|
+
return this._session
|
|
68
|
+
.connect(this._credentials.token, { clientRole: this._sessionParams.clientRole })
|
|
69
|
+
.catch(function (err) {
|
|
70
|
+
trace.error('Error to connect to session Media Server: ', err);
|
|
71
|
+
throw err;
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
MediaServerSession.prototype.sessionDisconnect = function () {
|
|
75
|
+
if (this._session) {
|
|
76
|
+
return this._session.disconnect(true);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
MediaServerSession.prototype.disconnect = function () {
|
|
80
|
+
var _this = this;
|
|
81
|
+
return new bluebird_1.Promise(function (resolve) {
|
|
82
|
+
trace.info('Disconnecting from session');
|
|
83
|
+
var promiseDisconnect = [];
|
|
84
|
+
_this._peerConnections.forEach(function (peerConnection) {
|
|
85
|
+
promiseDisconnect.push(_this.destroyPeerConnection(peerConnection));
|
|
86
|
+
});
|
|
87
|
+
return bluebird_1.Promise.all(promiseDisconnect).then(function () {
|
|
88
|
+
if (!_this._session) {
|
|
89
|
+
trace.info('No active session - resolving');
|
|
90
|
+
resolve();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
_this.removeSessionEvent();
|
|
94
|
+
_this._session.disconnect();
|
|
95
|
+
_this._lastStreamEvents = [];
|
|
96
|
+
delete _this._session;
|
|
97
|
+
delete _this.OV;
|
|
98
|
+
resolve();
|
|
99
|
+
});
|
|
418
100
|
});
|
|
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
101
|
};
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
reject(error);
|
|
440
|
-
return;
|
|
102
|
+
MediaServerSession.prototype.removeSessionEvent = function () {
|
|
103
|
+
if (!this._session) {
|
|
104
|
+
return;
|
|
441
105
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
106
|
+
this._session.off('connectionCreated');
|
|
107
|
+
this._session.off('streamCreated');
|
|
108
|
+
this._session.off('streamDestroyed');
|
|
109
|
+
this._session.off('connectionDestroyed');
|
|
110
|
+
this._session.off('sessionDisconnected');
|
|
111
|
+
this._session.off('recordingStarted');
|
|
112
|
+
this._session.off('recordingStopped');
|
|
113
|
+
this._sessionParams.removeHandlers && this._sessionParams.removeHandlers();
|
|
114
|
+
trace.info('Remove Events Listener');
|
|
115
|
+
};
|
|
116
|
+
MediaServerSession.prototype.getRemoteTrackStats = function (mediaTrack) {
|
|
117
|
+
return bluebird_1.Promise.resolve(undefined);
|
|
118
|
+
};
|
|
119
|
+
MediaServerSession.prototype.onMediaStreamDestroyed = function (clientRole) {
|
|
120
|
+
var _this = this;
|
|
121
|
+
trace.info('onMediaStreamDestroyed');
|
|
122
|
+
var promises = [];
|
|
123
|
+
this._peerConnections.forEach(function (peerConnection) {
|
|
124
|
+
if (peerConnection.peerRole === clientRole) {
|
|
125
|
+
promises.push(_this.destroyPublisherOnPeerConnection(peerConnection));
|
|
126
|
+
}
|
|
452
127
|
});
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
128
|
+
return bluebird_1.Promise.all(promises).then(function () { return trace.info('onMediaStreamDestroyed: Success'); });
|
|
129
|
+
};
|
|
130
|
+
MediaServerSession.prototype.onPublisherDestroyed = function (connectionId) {
|
|
131
|
+
trace.info('onPublisherDestroyed');
|
|
132
|
+
var peerConnection = this._peerConnections.get(connectionId);
|
|
133
|
+
if (!peerConnection) {
|
|
134
|
+
return bluebird_1.Promise.resolve();
|
|
135
|
+
}
|
|
136
|
+
return this.destroyPublisherOnPeerConnection(peerConnection);
|
|
137
|
+
};
|
|
138
|
+
MediaServerSession.prototype.onMediaStreamRenewed = function (clientRole, mediaStream) {
|
|
139
|
+
return bluebird_1.Promise.resolve(undefined);
|
|
140
|
+
};
|
|
141
|
+
MediaServerSession.prototype.replaceStreamTracks = function (mediaStream) {
|
|
142
|
+
return bluebird_1.Promise.reject(new Error('Not implemented'));
|
|
143
|
+
};
|
|
144
|
+
MediaServerSession.prototype.initSessionEvents = function () {
|
|
145
|
+
var _this = this;
|
|
146
|
+
if (!this._session) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this._sessionParams.initHandlers && this._sessionParams.initHandlers();
|
|
150
|
+
this._lastStreamEvents = [];
|
|
151
|
+
this._session.on('connectionCreated', this.connectionCreatedHandler);
|
|
152
|
+
this._session.on('streamCreated', this.streamCreatedHandler);
|
|
153
|
+
this._session.on('streamDestroyed', this.streamDestroyedHandler);
|
|
154
|
+
this._session.on('connectionDestroyed', this.connectionDestroyedHandler);
|
|
155
|
+
this._session.on('recordingStarted', function (event) {
|
|
156
|
+
trace.info('recordingStarted event', event);
|
|
157
|
+
_this.emitEvent(MediaSessionBase_1.recordingEvents.RECORD_STARTED, event);
|
|
158
|
+
});
|
|
159
|
+
this._session.on('recordingStopped', function (event) {
|
|
160
|
+
trace.info('recordingStopped event', event);
|
|
161
|
+
_this.emitEvent(MediaSessionBase_1.recordingEvents.RECORD_STOPPED, event);
|
|
162
|
+
});
|
|
163
|
+
this._session.on('reconnecting', function () {
|
|
164
|
+
trace.info('reconnecting event');
|
|
165
|
+
_this.emitEvent(MediaSessionBase_1.recordingEvents.RECONNECTING);
|
|
166
|
+
});
|
|
167
|
+
this._session.on('sessionDisconnected', this.disconnect);
|
|
168
|
+
};
|
|
169
|
+
MediaServerSession.prototype.streamDestroyedHandler = function (event) {
|
|
170
|
+
trace.info('streamDestroyedHandler', event);
|
|
171
|
+
var stream = event.stream;
|
|
172
|
+
if (!this.sessionExistsGuard(false) || !stream) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
var peerConnection = this._peerConnections.get(stream.connection.connectionId);
|
|
176
|
+
if (!peerConnection) {
|
|
177
|
+
trace.warn('Peer connection for remote stream not found');
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
this.destroySubscriberOnPeerConnection(peerConnection).catch(function () { return undefined; });
|
|
181
|
+
};
|
|
182
|
+
MediaServerSession.prototype.connectionDestroyedHandler = function (event) {
|
|
183
|
+
trace.info('connectionDestroyedHandler', event);
|
|
184
|
+
var connection = event.connection;
|
|
185
|
+
if (!this.sessionExistsGuard(false) || !connection) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (this._peerConnections.has(connection.connectionId)) {
|
|
189
|
+
var peerConnection = this._peerConnections.get(connection.connectionId);
|
|
190
|
+
this.destroySubscriberOnPeerConnection(peerConnection).catch(function () { return undefined; });
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
MediaServerSession.prototype.destroyPeerConnection = function (peerConnection) {
|
|
194
|
+
trace.info('destroyPeerConnection');
|
|
195
|
+
this._peerConnections.delete(peerConnection.peerId);
|
|
196
|
+
return bluebird_1.Promise.all([
|
|
197
|
+
this.destroyPublisherOnPeerConnection(peerConnection),
|
|
198
|
+
this.destroySubscriberOnPeerConnection(peerConnection)
|
|
199
|
+
])
|
|
200
|
+
.then(function () { return undefined; })
|
|
201
|
+
.catch(function () {
|
|
202
|
+
trace.warn('destroyPeerConnection - something wrong with destroy');
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
MediaServerSession.prototype.destroySubscriberOnPeerConnection = function (peerConnection) {
|
|
206
|
+
trace.info('destroySubscriberOnPeerConnection', peerConnection);
|
|
207
|
+
if (this.sessionExistsGuard(false) && peerConnection.subscriber) {
|
|
208
|
+
this._session.unsubscribe(peerConnection.subscriber);
|
|
209
|
+
}
|
|
210
|
+
trace.info('destroySubscriberOnPeerConnection- before unregisterPeersRemoteMediaTracks');
|
|
211
|
+
return this.unregisterPeersRemoteMediaTracks(peerConnection)
|
|
212
|
+
.catch(function () { return trace.warn('Error removing remote streams from peerConnection'); })
|
|
213
|
+
.then(function () {
|
|
214
|
+
trace.info('destroySubscriberOnPeerConnection- unregisterPeersRemoteMediaTracks successfully');
|
|
215
|
+
peerConnection.subscriber = null;
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
MediaServerSession.prototype.destroyPublisherOnPeerConnection = function (peerConnection) {
|
|
219
|
+
trace.info('destroyPublisherOnPeerConnection');
|
|
220
|
+
if (this.sessionExistsGuard(false) && peerConnection.publisher) {
|
|
221
|
+
trace.info('destroyPublisherOnPeerConnection- unpublish!');
|
|
222
|
+
this._session.unpublish(peerConnection.publisher);
|
|
223
|
+
}
|
|
224
|
+
peerConnection.publisher = null;
|
|
225
|
+
peerConnection.localStream = null;
|
|
226
|
+
return bluebird_1.Promise.resolve();
|
|
227
|
+
};
|
|
228
|
+
MediaServerSession.prototype.createMediaSubscriber = function (remoteStream) {
|
|
229
|
+
var _this = this;
|
|
230
|
+
trace.info('createMediaSubscriber');
|
|
231
|
+
return new bluebird_1.Promise(function (resolve, reject) {
|
|
232
|
+
if (!_this.sessionExistsGuard(false)) {
|
|
233
|
+
return reject('Session not exists');
|
|
234
|
+
}
|
|
235
|
+
trace.info('Before create subscriber');
|
|
236
|
+
var subscriber = _this._session.subscribe(remoteStream, '', {}, function (err) {
|
|
237
|
+
if (err) {
|
|
238
|
+
trace.warn('Error creating subscriber', err);
|
|
239
|
+
return reject(err);
|
|
240
|
+
}
|
|
241
|
+
trace.info('create subscriber successfully', subscriber);
|
|
242
|
+
return resolve(subscriber);
|
|
514
243
|
});
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
return bluebird_1.Promise.resolve();
|
|
518
244
|
});
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
}
|
|
536
|
-
|
|
245
|
+
};
|
|
246
|
+
MediaServerSession.prototype.streamCreatedHandler = function (event) {
|
|
247
|
+
var _this = this;
|
|
248
|
+
if (!event) {
|
|
249
|
+
return bluebird_1.Promise.resolve();
|
|
250
|
+
}
|
|
251
|
+
trace.info('streamCreatedHandler', event.stream);
|
|
252
|
+
var stream = event.stream;
|
|
253
|
+
var connection = (stream || { connection: null }).connection;
|
|
254
|
+
if (!this.sessionExistsGuard(false) || !stream || connection.connectionId === this.ownPeerId) {
|
|
255
|
+
return bluebird_1.Promise.resolve();
|
|
256
|
+
}
|
|
257
|
+
if (!this._peerConnections.has(connection.connectionId)) {
|
|
258
|
+
trace.warn('Unexpected case, connection should exist, add to streams to subscribe list', event);
|
|
259
|
+
this._lastStreamEvents.push(event);
|
|
260
|
+
return bluebird_1.Promise.resolve();
|
|
261
|
+
}
|
|
262
|
+
var peerConnection = this._peerConnections.get(connection.connectionId);
|
|
263
|
+
trace.info('Subscribing the stream');
|
|
264
|
+
return this.createMediaSubscriber(stream).then(function (subscriber) {
|
|
265
|
+
peerConnection.subscriber = subscriber;
|
|
266
|
+
trace.info('Registering remote media tracks', peerConnection.subscriber);
|
|
267
|
+
subscriber.stream
|
|
268
|
+
.getMediaStream()
|
|
269
|
+
.getTracks()
|
|
270
|
+
.forEach(function (mediaTrack) {
|
|
271
|
+
_this.addRemoteTrackToPeer(peerConnection, mediaTrack);
|
|
272
|
+
});
|
|
273
|
+
return _this.registerPeersRemoteTracks(peerConnection);
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
MediaServerSession.prototype.createStreamForPublishing = function (destinationRole) {
|
|
277
|
+
var _this = this;
|
|
278
|
+
trace.info('createStreamForPublishing');
|
|
279
|
+
return this._sessionStreamsManager
|
|
280
|
+
.getMediaStreamForRole(destinationRole)
|
|
281
|
+
.then(function (mediaStream) {
|
|
282
|
+
var stream = { videoSource: null, audioSource: null };
|
|
283
|
+
if (mediaStream) {
|
|
284
|
+
trace.info('Media stream found for publishing', mediaStream);
|
|
285
|
+
mediaStream.getTracks().forEach(function (track) {
|
|
286
|
+
if (track.kind === 'video') {
|
|
287
|
+
stream.videoSource = track;
|
|
288
|
+
}
|
|
289
|
+
else if (track.kind === 'audio') {
|
|
290
|
+
stream.audioSource = track;
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
else if (_this._sessionParams.clientRole === MediaConstants_1.SessionClientRole.USER) {
|
|
295
|
+
trace.warn('No local media was found for publishing to destinationRole:', destinationRole);
|
|
296
|
+
}
|
|
297
|
+
return stream;
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
MediaServerSession.prototype.createMediaPublisher = function (stream) {
|
|
301
|
+
var _this = this;
|
|
302
|
+
var ovParams = {
|
|
303
|
+
videoSource: stream.videoSource ? stream.videoSource : false,
|
|
304
|
+
audioSource: stream.audioSource ? stream.audioSource : false,
|
|
305
|
+
publishAudio: !!stream.audioSource,
|
|
306
|
+
publishVideo: !!stream.videoSource
|
|
307
|
+
};
|
|
308
|
+
return new bluebird_1.Promise(function (resolve, reject) {
|
|
309
|
+
var ovPublisher = _this.OV.initPublisher('', ovParams, function (error) {
|
|
310
|
+
if (error) {
|
|
311
|
+
reject(error);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
ovPublisher.on('streamDestroyed', function (event) {
|
|
315
|
+
trace.info('Publisher stream destroyed', event);
|
|
316
|
+
var connectionId = (0, get_1.default)(event, 'stream.connection.connectionId');
|
|
317
|
+
_this.onPublisherDestroyed(connectionId);
|
|
318
|
+
event.preventDefault();
|
|
319
|
+
});
|
|
320
|
+
resolve(ovPublisher);
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
MediaServerSession.prototype.connectionCreatedHandler = function (event) {
|
|
325
|
+
var _this = this;
|
|
326
|
+
trace.info('connectionCreatedHandler', event);
|
|
327
|
+
var connection = event.connection;
|
|
328
|
+
if (!this.sessionExistsGuard(false) || !connection) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
var destinationRole = JSON.parse(connection.data).clientRole;
|
|
332
|
+
this.createStreamForPublishing(destinationRole)
|
|
333
|
+
.then(function (streams) {
|
|
334
|
+
var peerConnection = {
|
|
335
|
+
peerId: connection.connectionId,
|
|
336
|
+
peerRole: destinationRole,
|
|
337
|
+
peerType: _this._sessionParams.clientType === MediaConstants_1.SessionClientType.INITIATOR
|
|
338
|
+
? MediaConstants_1.SessionClientType.GUEST
|
|
339
|
+
: MediaConstants_1.SessionClientType.INITIATOR,
|
|
340
|
+
connection: connection,
|
|
341
|
+
publisher: null,
|
|
342
|
+
subscriber: null,
|
|
343
|
+
remoteMediaTracks: [],
|
|
344
|
+
localStream: streams,
|
|
345
|
+
connectionTimoutPrt: null
|
|
346
|
+
};
|
|
347
|
+
if (connection.connectionId !== _this.ownPeerId || (!streams.videoSource && !streams.audioSource)) {
|
|
348
|
+
trace.info('Peer connection without publisher was created', peerConnection);
|
|
349
|
+
return peerConnection;
|
|
350
|
+
}
|
|
351
|
+
return _this.createMediaPublisher(streams).then(function (publisher) {
|
|
352
|
+
peerConnection.publisher = publisher;
|
|
353
|
+
trace.info('Peer connection with publisher was created', peerConnection);
|
|
354
|
+
return peerConnection;
|
|
355
|
+
});
|
|
356
|
+
})
|
|
357
|
+
.then(function (peerConnection) {
|
|
358
|
+
_this._peerConnections.set(peerConnection.peerId, peerConnection);
|
|
359
|
+
if (connection.connectionId === _this.ownPeerId) {
|
|
360
|
+
trace.info('Before subscribe the event streams');
|
|
361
|
+
return _this._lastStreamEvents
|
|
362
|
+
.reduce(function (promiseChain, streamEvent) {
|
|
363
|
+
return promiseChain.then(function () { return _this.streamCreatedHandler(streamEvent); });
|
|
364
|
+
}, bluebird_1.Promise.resolve())
|
|
365
|
+
.then(function () {
|
|
366
|
+
if (peerConnection.publisher) {
|
|
367
|
+
trace.info('Starting publish to peerConnection.publisher');
|
|
368
|
+
return _this._session.publish(peerConnection.publisher).catch(function (err) {
|
|
369
|
+
trace.info('Error during publish', peerConnection.publisher);
|
|
370
|
+
if (peerConnection.publisher) {
|
|
371
|
+
trace.info('Error during publish- unpublish');
|
|
372
|
+
_this._session.unpublish(peerConnection.publisher);
|
|
373
|
+
}
|
|
374
|
+
throw err;
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
return bluebird_1.Promise.resolve();
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
})
|
|
381
|
+
.catch(function (error) {
|
|
382
|
+
trace.error('Error handling new peer connection', error);
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
MediaServerSession.prototype.sessionExistsGuard = function (shouldThrow) {
|
|
386
|
+
if (shouldThrow === void 0) { shouldThrow = true; }
|
|
387
|
+
var connected = !!(this._session && this._session.connection && this._session.connection.connectionId);
|
|
388
|
+
return (0, guards_1.throwableGuard)(connected, 'There no MediaServer session exists', shouldThrow);
|
|
389
|
+
};
|
|
390
|
+
return MediaServerSession;
|
|
391
|
+
}(MediaSessionBase_1.MediaSessionBase));
|
|
537
392
|
exports.MediaServerSession = MediaServerSession;
|
|
538
|
-
//# sourceMappingURL=MediaServer.js.map
|
|
393
|
+
//# sourceMappingURL=MediaServer.js.map
|