@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
package/lib/MediaServiceBase.js
CHANGED
|
@@ -1,636 +1,974 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var __assign =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return
|
|
3
|
+
var __assign = void 0 && (void 0).__assign || function () {
|
|
4
|
+
__assign = Object.assign || function (t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
|
|
8
|
+
for (var p in s) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return t;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return __assign.apply(this, arguments);
|
|
14
17
|
};
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
|
|
19
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
20
|
+
return mod && mod.__esModule ? mod : {
|
|
21
|
+
"default": mod
|
|
22
|
+
};
|
|
17
23
|
};
|
|
18
|
-
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(exports, "__esModule", {
|
|
26
|
+
value: true
|
|
27
|
+
});
|
|
28
|
+
exports.TechseeMediaServiceBase = void 0;
|
|
29
|
+
|
|
19
30
|
var filter_1 = __importDefault(require("lodash/filter"));
|
|
31
|
+
|
|
20
32
|
var cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
33
|
+
|
|
21
34
|
var values_1 = __importDefault(require("lodash/values"));
|
|
35
|
+
|
|
22
36
|
var debounce_1 = __importDefault(require("lodash/debounce"));
|
|
37
|
+
|
|
23
38
|
var includes_1 = __importDefault(require("lodash/includes"));
|
|
39
|
+
|
|
24
40
|
var events_1 = require("events");
|
|
41
|
+
|
|
25
42
|
var MediaSubscriber_1 = require("./MediaSubscriber");
|
|
43
|
+
|
|
26
44
|
var LocalStreamManager_1 = require("./LocalStreamManager");
|
|
45
|
+
|
|
27
46
|
var TechseeMediaStream_1 = require("./TechseeMediaStream");
|
|
47
|
+
|
|
28
48
|
var SessionTurn_1 = require("./MediaSession/SessionTurn");
|
|
49
|
+
|
|
29
50
|
var MediaDomUtils_1 = require("./MediaUtils/MediaDomUtils");
|
|
51
|
+
|
|
30
52
|
var Compatibility_1 = require("./MediaUtils/Compatibility");
|
|
53
|
+
|
|
31
54
|
var SessionOpentok_1 = require("./MediaSession/SessionOpentok");
|
|
55
|
+
|
|
32
56
|
var MediaConstants_1 = require("./MediaConstants");
|
|
57
|
+
|
|
33
58
|
var guards_1 = require("@techsee/techsee-common/lib/core/guards");
|
|
59
|
+
|
|
60
|
+
var MediaServer_1 = require("./MediaSession/MediaServer");
|
|
61
|
+
|
|
34
62
|
var MediaTracer_1 = require("./MediaUtils/MediaTracer");
|
|
63
|
+
|
|
64
|
+
var MediaSessionBase_1 = require("./MediaSession/MediaSessionBase");
|
|
65
|
+
|
|
35
66
|
var trace = MediaTracer_1.getMediaTracer('MediaServiceBase');
|
|
36
|
-
var traceStatsInfo = debounce_1
|
|
67
|
+
var traceStatsInfo = debounce_1["default"](trace.info, 1000 * 5, {
|
|
68
|
+
leading: true,
|
|
69
|
+
maxWait: 1000 * 30
|
|
70
|
+
});
|
|
37
71
|
var privateEvents;
|
|
72
|
+
|
|
38
73
|
(function (privateEvents) {
|
|
39
|
-
|
|
40
|
-
|
|
74
|
+
privateEvents["STREAM_CREATED"] = "STREAM_CREATED";
|
|
75
|
+
privateEvents["STREAM_DESTROYED"] = "STREAM_DESTROYED";
|
|
41
76
|
})(privateEvents || (privateEvents = {}));
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
77
|
+
|
|
78
|
+
var TechseeMediaServiceBase =
|
|
79
|
+
/** @class */
|
|
80
|
+
function () {
|
|
81
|
+
function TechseeMediaServiceBase(environment, webRtcSupportInfo) {
|
|
82
|
+
this._subscribers = new Map();
|
|
83
|
+
this._publishers = new Map();
|
|
84
|
+
this._publisherPromises = new Map();
|
|
85
|
+
this._serviceOptions = null;
|
|
86
|
+
this._isIOS_13_orLater = false;
|
|
87
|
+
this._isIOS_14_orLater = false;
|
|
88
|
+
this._autoReconnectEnabled = true;
|
|
89
|
+
this._initLocalStreamsPromise = null;
|
|
90
|
+
this._initServicePromise = null;
|
|
91
|
+
this._registeredStreams = new Map();
|
|
92
|
+
this._isVoipEnabled = false;
|
|
93
|
+
this._session = null;
|
|
94
|
+
trace.info('TechseeMediaServiceBase created');
|
|
95
|
+
this.bindClassMethods();
|
|
96
|
+
this._emitter = new events_1.EventEmitter();
|
|
97
|
+
this._environment = environment;
|
|
98
|
+
this._deviceSupportFlags = {
|
|
99
|
+
videoPlayback: false,
|
|
100
|
+
hasCamera: false,
|
|
101
|
+
hasMicrophone: false,
|
|
102
|
+
webRtcSupportInfo: webRtcSupportInfo
|
|
103
|
+
};
|
|
104
|
+
this._localStreamsManager = new LocalStreamManager_1.LocalStreamManager(this._environment); // TODO: Hack as IOS 13.3 and above sometimes do not return the video/audio device. This
|
|
105
|
+
// is a hack to work around the issue until Apple resolve it
|
|
106
|
+
|
|
107
|
+
this._isIOS_13_orLater = this._environment.isIOS() && (!this._environment.majorVersion() || this._environment.majorVersion() >= 13);
|
|
108
|
+
this._isIOS_14_orLater = this._environment.isIOS() && (!this._environment.majorVersion() || this._environment.majorVersion() >= 14);
|
|
109
|
+
trace.info("TechseeMediaServiceBase: isIOS_13_orLater: " + this._isIOS_13_orLater);
|
|
110
|
+
trace.info("TechseeMediaServiceBase: isIOS_14_orLater: " + this._isIOS_14_orLater);
|
|
111
|
+
this._sessionStreamsManager = {
|
|
112
|
+
getMediaStreamForRole: this.getStreamForDestinationRole,
|
|
113
|
+
addRemoteMediaTrack: this.registerRemoteMediaTrack,
|
|
114
|
+
removeMediaTrack: this.unregisterRemoteMediaTrack
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
Object.defineProperty(TechseeMediaServiceBase.prototype, "deviceSupportInfo", {
|
|
119
|
+
get: function get() {
|
|
120
|
+
this.serviceInitGuard(false);
|
|
121
|
+
return cloneDeep_1["default"](this._deviceSupportFlags);
|
|
122
|
+
},
|
|
123
|
+
enumerable: false,
|
|
124
|
+
configurable: true
|
|
125
|
+
});
|
|
126
|
+
Object.defineProperty(TechseeMediaServiceBase.prototype, "isVoipEnabled", {
|
|
127
|
+
get: function get() {
|
|
128
|
+
return this._isVoipEnabled;
|
|
129
|
+
},
|
|
130
|
+
enumerable: false,
|
|
131
|
+
configurable: true
|
|
132
|
+
});
|
|
133
|
+
Object.defineProperty(TechseeMediaServiceBase.prototype, "isSessionActive", {
|
|
134
|
+
get: function get() {
|
|
135
|
+
return this._session !== null;
|
|
136
|
+
},
|
|
137
|
+
enumerable: false,
|
|
138
|
+
configurable: true
|
|
139
|
+
});
|
|
140
|
+
Object.defineProperty(TechseeMediaServiceBase.prototype, "isLocalStreamInitialized", {
|
|
141
|
+
get: function get() {
|
|
142
|
+
return this._initLocalStreamsPromise !== null;
|
|
143
|
+
},
|
|
144
|
+
enumerable: false,
|
|
145
|
+
configurable: true
|
|
146
|
+
});
|
|
147
|
+
/*
|
|
148
|
+
Initializes media service. Before using anything from this service it should be initialized first.
|
|
149
|
+
All of serviceOptions should be retrieved from account settings and by evaluating application state.
|
|
150
|
+
For example, when initializing service, accountSettings is already loaded, and we know if FS session is audio enabled.
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
TechseeMediaServiceBase.prototype.initMediaService = function (serviceOptions) {
|
|
154
|
+
var _this = this;
|
|
155
|
+
|
|
156
|
+
trace.info('TechseeMediaServiceBase.initMediaService', serviceOptions);
|
|
157
|
+
var warnMessage = 'Multiple initialization does not supposed to happen. Not rejecting, but check the flow for correctness.';
|
|
158
|
+
|
|
159
|
+
if (this._initServicePromise || this._serviceOptions) {
|
|
160
|
+
console.warn(warnMessage);
|
|
161
|
+
return this._initServicePromise ? this._initServicePromise : Promise.resolve();
|
|
70
162
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
get: function get() {
|
|
95
|
-
return this._initLocalStreamsPromise !== null;
|
|
96
|
-
},
|
|
97
|
-
enumerable: true,
|
|
98
|
-
configurable: true
|
|
163
|
+
|
|
164
|
+
this._serviceOptions = cloneDeep_1["default"](serviceOptions);
|
|
165
|
+
this._initServicePromise = Promise.all([Compatibility_1.isVideoPlaySupportedOnDevice(this._serviceOptions.mediaServiceType).then(function (isSupported) {
|
|
166
|
+
return _this._deviceSupportFlags.videoPlayback = isSupported;
|
|
167
|
+
}), (this._isIOS_14_orLater || !this._deviceSupportFlags.webRtcSupportInfo.isWebRTCSupported ? Promise.resolve([]) : Compatibility_1.enumerateMediaDevices())["catch"](function (error) {
|
|
168
|
+
trace.warn(error);
|
|
169
|
+
return [];
|
|
170
|
+
}).then(function (localDevicesList) {
|
|
171
|
+
var groupedDevices = {
|
|
172
|
+
video: filter_1["default"](localDevicesList, function (device) {
|
|
173
|
+
return device.kind.toLowerCase() === 'videoinput';
|
|
174
|
+
}),
|
|
175
|
+
audio: filter_1["default"](localDevicesList, function (device) {
|
|
176
|
+
return device.kind.toLowerCase() === 'audioinput';
|
|
177
|
+
})
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
_this._localStreamsManager.setGroupedDevices(groupedDevices);
|
|
181
|
+
|
|
182
|
+
_this._deviceSupportFlags.hasCamera = _this._isIOS_13_orLater || groupedDevices.video.length > 0;
|
|
183
|
+
_this._deviceSupportFlags.hasMicrophone = _this._isIOS_13_orLater || groupedDevices.audio.length > 0;
|
|
184
|
+
})]).then(function () {
|
|
185
|
+
return undefined;
|
|
99
186
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
var allowedValues = values_1.default(MediaConstants_1.MediaServiceType);
|
|
228
|
-
trace.error("mediaServiceType '" + _this._serviceOptions.mediaServiceType + "' is not supported.", { allowedValues: allowedValues });
|
|
229
|
-
doAsyncReject(new Error('mediaServiceType is not supported'));
|
|
230
|
-
}
|
|
231
|
-
if (_this._session && _this._session.instance) {
|
|
232
|
-
_this._session.instance.connect().then(function () {
|
|
233
|
-
trace.info('Session is connected');
|
|
234
|
-
resolve();
|
|
235
|
-
}).catch(function (error) {
|
|
236
|
-
trace.error('Failed to connect to session', error);
|
|
237
|
-
doAsyncReject(error);
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
} else {
|
|
242
|
-
trace.warn('Session connected already. Disconnect before connect to new session again');
|
|
243
|
-
}
|
|
244
|
-
//TODO - Alex: Change a structure of this function to be more safe
|
|
245
|
-
//(when we return, there should not be case when session or promise is null)
|
|
246
|
-
//To fix, need to return promise immediately, then execute process in setTimeout(fn, 0);
|
|
247
|
-
return this._session.connectPromise;
|
|
248
|
-
};
|
|
249
|
-
/*
|
|
250
|
-
Disconnects from WebRTC session.
|
|
251
|
-
*/
|
|
252
|
-
TechseeMediaServiceBase.prototype.disconnectFromSession = function () {
|
|
253
|
-
return this.disconnectFromSessionInternal(MediaConstants_1.MediaSessionDisconnectReason.ForcedByConsumer);
|
|
254
|
-
};
|
|
255
|
-
/*
|
|
256
|
-
Updates a credentials for turn server
|
|
257
|
-
*/
|
|
258
|
-
TechseeMediaServiceBase.prototype.updateSessionCredentials = function (credentials) {
|
|
259
|
-
trace.info('updateSessionCredentials');
|
|
260
|
-
if (!this.sessionExistsGuard(false)) {
|
|
261
|
-
return Promise.reject('There no session to update credentials');
|
|
262
|
-
}
|
|
263
|
-
this._session.params.credentials = cloneDeep_1.default(credentials);
|
|
264
|
-
return Promise.resolve();
|
|
265
|
-
};
|
|
266
|
-
TechseeMediaServiceBase.prototype.enableVoipDuringSession = function () {
|
|
267
|
-
if (!this._isVoipEnabled && this.isLocalStreamInitialized) {
|
|
268
|
-
throw new Error('Voip support cannot be enabled after local stream where initialized');
|
|
269
|
-
}
|
|
270
|
-
this._isVoipEnabled = true;
|
|
271
|
-
};
|
|
272
|
-
TechseeMediaServiceBase.prototype.disconnectFromSessionInternal = function (reason) {
|
|
273
|
-
if (!this._session) {
|
|
274
|
-
return Promise.resolve();
|
|
275
|
-
}
|
|
276
|
-
trace.info('Disconnecting from session', reason);
|
|
277
|
-
var lastSession = this._session;
|
|
278
|
-
this._session = null;
|
|
279
|
-
return Promise.all([lastSession.instance.disconnect(), this.clearPublishers()]).then(function () {
|
|
280
|
-
return undefined;
|
|
281
|
-
});
|
|
282
|
-
};
|
|
283
|
-
TechseeMediaServiceBase.prototype.getStatsForRemoteTrack = function (streamType) {
|
|
284
|
-
if (!this.sessionExistsGuard(false)) {
|
|
285
|
-
return Promise.reject(new Error('Media session not started'));
|
|
286
|
-
}
|
|
287
|
-
var streamForStats = this.getRegisteredStreamByType(streamType);
|
|
288
|
-
if (!streamForStats) {
|
|
289
|
-
return Promise.reject(new Error('Stream for requested type was not found'));
|
|
290
|
-
}
|
|
291
|
-
return this._session.instance.getRemoteTrackStats(streamForStats.mediaTrack).then(function (trackStats) {
|
|
292
|
-
traceStatsInfo("MediaTrackStats for " + streamType + ": " + JSON.stringify(trackStats));
|
|
187
|
+
return this._initServicePromise;
|
|
188
|
+
}; //#region Media Streams Management
|
|
189
|
+
|
|
190
|
+
/*
|
|
191
|
+
The main method to start the initialization of local media streams.
|
|
192
|
+
This method can be executed many times and it will insure all calls are synced and only relevant stream will be created.
|
|
193
|
+
DO NOT USE ANY OTHER METHOD THAT FORCES "navigator.getUserMedia" OTHER THAN THIS ONE.
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
TechseeMediaServiceBase.prototype.initLocalMediaStreams = function () {
|
|
198
|
+
this.serviceInitGuard();
|
|
199
|
+
var isDashboardOpentok = this._serviceOptions.mediaServiceType === MediaConstants_1.MediaServiceType.OPENTOK && (this._serviceOptions.clientRole === MediaConstants_1.SessionClientRole.AGENT || this._serviceOptions.clientRole === MediaConstants_1.SessionClientRole.OBSERVER); // This hack for IOS 14 force a recreation of stream on seemingly unnecessary occasions (like agent page refresh).
|
|
200
|
+
// we're not sure why but the stream breaks
|
|
201
|
+
|
|
202
|
+
if (!this._initLocalStreamsPromise || this._isIOS_14_orLater && !isDashboardOpentok) {
|
|
203
|
+
trace.info('initLocalMediaStreams creating media streams');
|
|
204
|
+
this._initLocalStreamsPromise = this.getLocalMediaImplementation()["catch"](function (mediaRequestFailResult) {
|
|
205
|
+
trace.error("initLocalMediaStreams failure: " + mediaRequestFailResult);
|
|
206
|
+
throw mediaRequestFailResult;
|
|
207
|
+
});
|
|
208
|
+
} else {
|
|
209
|
+
trace.info('initLocalMediaStreams already done or in progress');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return this._initLocalStreamsPromise;
|
|
213
|
+
};
|
|
214
|
+
/*
|
|
215
|
+
Creates an instance of subscriber that will "listen" to the requested stream.
|
|
216
|
+
Whenever requested stream is available, subscriber will render it.
|
|
217
|
+
*/
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
TechseeMediaServiceBase.prototype.createSubscriber = function (subscriberParams) {
|
|
221
|
+
if (this._subscribers.has(subscriberParams.container)) {
|
|
222
|
+
return Promise.reject('Subscriber for provided DIV element already exists');
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
var subscriber = new MediaSubscriber_1.TechseeMediaSubscriber(subscriberParams);
|
|
226
|
+
|
|
227
|
+
this._subscribers.set(subscriberParams.container, subscriber);
|
|
228
|
+
|
|
229
|
+
var streamForSubscriber = this.getRegisteredStreamByType(subscriber.streamType);
|
|
230
|
+
|
|
231
|
+
if (streamForSubscriber) {
|
|
232
|
+
trace.info("Stream for " + subscriberParams.streamType + " is ready.");
|
|
233
|
+
subscriber.renderStream(streamForSubscriber);
|
|
234
|
+
} else {
|
|
235
|
+
trace.info("Stream for " + subscriberParams.streamType + " not created yet");
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return Promise.resolve(subscriber);
|
|
239
|
+
};
|
|
240
|
+
/*
|
|
241
|
+
Destroys the subscriber for provided HTML DIV container
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
TechseeMediaServiceBase.prototype.destroySubscriber = function (container) {
|
|
246
|
+
if (this._subscribers.has(container)) {
|
|
247
|
+
var subscriber = this._subscribers.get(container);
|
|
248
|
+
|
|
249
|
+
subscriber.dispose();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
this._subscribers["delete"](container);
|
|
253
|
+
|
|
254
|
+
return Promise.resolve();
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
TechseeMediaServiceBase.prototype.onStreamDestroyed = function (callback) {
|
|
258
|
+
this.registerEventCallback(privateEvents.STREAM_DESTROYED, callback);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
TechseeMediaServiceBase.prototype.onStreamCreated = function (callback) {
|
|
262
|
+
this.registerEventCallback(privateEvents.STREAM_CREATED, callback);
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
TechseeMediaServiceBase.prototype.onRecordStarted = function (callback) {
|
|
266
|
+
if (this._session && this._session.instance) {
|
|
267
|
+
this._session.instance.registerEventCallback(MediaSessionBase_1.recordingEvents.RECORD_STARTED, callback);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
TechseeMediaServiceBase.prototype.onRecordStopped = function (callback) {
|
|
272
|
+
if (this._session && this._session.instance) {
|
|
273
|
+
this._session.instance.registerEventCallback(MediaSessionBase_1.recordingEvents.RECORD_STOPPED, callback);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
TechseeMediaServiceBase.prototype.onReconnecting = function (callback) {
|
|
278
|
+
if (this._session && this._session.instance) {
|
|
279
|
+
this._session.instance.registerEventCallback(MediaSessionBase_1.recordingEvents.RECONNECTING, callback);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
TechseeMediaServiceBase.prototype.getSwitchCameraConstraints = function () {
|
|
284
|
+
var constraints = cloneDeep_1["default"](window.latestLocalMediaConstraints);
|
|
285
|
+
|
|
286
|
+
if (!constraints) {
|
|
287
|
+
throw new Error('getSwitchCameraConstraints: unexpected use case constraints is null.');
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
trace.info('getSwitchCameraConstraints - Start switch camera with constraints:', constraints);
|
|
291
|
+
var videoSourceType = constraints.video.videoSourceType === MediaConstants_1.LocalVideoSourceType.CAMERA ? MediaConstants_1.LocalVideoSourceType.CAMERA_FRONT : MediaConstants_1.LocalVideoSourceType.CAMERA;
|
|
292
|
+
trace.info("getSwitchCameraConstraints - switch to videoSourceType: " + videoSourceType);
|
|
293
|
+
constraints.video.videoSourceType = videoSourceType;
|
|
294
|
+
return constraints;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
TechseeMediaServiceBase.prototype.switchCamera = function (revertCameraWhenFailed) {
|
|
298
|
+
var _this = this;
|
|
299
|
+
|
|
300
|
+
trace.info('switchCamera: start');
|
|
301
|
+
var latestLocalMediaConstraints = cloneDeep_1["default"](window.latestLocalMediaConstraints);
|
|
302
|
+
var constraints = !revertCameraWhenFailed ? this.getSwitchCameraConstraints() : latestLocalMediaConstraints;
|
|
303
|
+
|
|
304
|
+
if (!constraints) {
|
|
305
|
+
throw new Error('switchCamera - unexpected use case constraints is null.');
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return this._localStreamsManager.destroyUserMediaStream().then(function () {
|
|
309
|
+
return _this._localStreamsManager.getUserMediaStream(constraints).then(function (streamResult) {
|
|
310
|
+
var stream = streamResult.mediaStream;
|
|
311
|
+
trace.info('switchCamera: new stream: ', stream);
|
|
312
|
+
return _this.replaceStreamTracks(stream).then(function () {
|
|
313
|
+
return _this.registerStreamResult(constraints, streamResult, true).then(function () {
|
|
293
314
|
return {
|
|
294
|
-
|
|
295
|
-
|
|
315
|
+
revertCameraWhenFailed: revertCameraWhenFailed,
|
|
316
|
+
constraints: constraints,
|
|
317
|
+
streamResult: streamResult
|
|
296
318
|
};
|
|
319
|
+
});
|
|
297
320
|
});
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
} else if (!_this._autoReconnectEnabled) {
|
|
309
|
-
trace.info('No reconnection- auto reconnect disabled');
|
|
310
|
-
} else {
|
|
311
|
-
trace.info('No params for reconnection to media session');
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
} else {
|
|
315
|
-
trace.info('Ignore Session disconnect event');
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
TechseeMediaServiceBase.prototype.setAutoReconnect = function (state) {
|
|
319
|
-
this._autoReconnectEnabled = state;
|
|
320
|
-
trace.info('_autoReconnectEnabled:', state);
|
|
321
|
-
if (this._autoReconnectEnabled && !this.isSessionActive) {
|
|
322
|
-
var lastParams = this._session && this._session.params ? this._session.params : null;
|
|
323
|
-
if (lastParams) {
|
|
324
|
-
trace.info('setAutoReconnect - reconnect to session');
|
|
325
|
-
this.reconnectToSession(lastParams);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
TechseeMediaServiceBase.prototype.reconnectToSession = function (lastParams) {
|
|
330
|
-
trace.info('Reconnecting to media session, sessionParams:', lastParams);
|
|
331
|
-
this.connectToSession(lastParams).then(function () {
|
|
332
|
-
trace.info('Media session reconnected');
|
|
333
|
-
}).catch(function (error) {
|
|
334
|
-
trace.error('Error while reconnecting to media session', error);
|
|
335
|
-
});
|
|
336
|
-
};
|
|
337
|
-
//#endregion Session Management
|
|
338
|
-
//#region Utils
|
|
339
|
-
TechseeMediaServiceBase.prototype.getSnapshotFromKnownStream = function (sourceStream, snapshotOptions) {
|
|
340
|
-
var _this = this;
|
|
341
|
-
return new Promise(function (resolve, reject) {
|
|
342
|
-
if (sourceStream !== MediaConstants_1.KnownMediaStream.USER_VIDEO_STREAM && sourceStream !== MediaConstants_1.KnownMediaStream.USER_SCREEN_SHARE_STREAM) {
|
|
343
|
-
trace.error('The requested stream is not video stream, and cannot be used for snapshot');
|
|
344
|
-
reject(new Error('INCOMPATIBLE_STREAM_FOR_SNAPSHOT'));
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
var snapshotStream = _this.getRegisteredStreamByType(sourceStream);
|
|
348
|
-
if (!snapshotStream) {
|
|
349
|
-
trace.error('Cannot make snapshot: The requested stream not exists yet.');
|
|
350
|
-
reject(new Error('NO_REQUESTED_STREAM'));
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
MediaDomUtils_1.getSnapshotFromMediaStream(snapshotStream.mediaStream, snapshotOptions).then(function (imageData) {
|
|
354
|
-
var urlComponents = imageData.split(';base64,');
|
|
355
|
-
var mimeType = urlComponents[0].split(':')[1];
|
|
356
|
-
var bytes = atob(urlComponents[1]);
|
|
357
|
-
var buffer = new ArrayBuffer(bytes.length);
|
|
358
|
-
var rawData = new Uint8Array(buffer);
|
|
359
|
-
for (var i = 0; i < bytes.length; i++) {
|
|
360
|
-
rawData[i] = bytes.charCodeAt(i);
|
|
361
|
-
}
|
|
362
|
-
var blob = new Blob([rawData], { type: mimeType });
|
|
363
|
-
var objectUrl = window.URL.createObjectURL(blob);
|
|
364
|
-
trace.info('Snapshot created successfully');
|
|
365
|
-
var result = {
|
|
366
|
-
base64img: imageData,
|
|
367
|
-
objectUrl: objectUrl,
|
|
368
|
-
imageBlob: blob,
|
|
369
|
-
mimeType: mimeType
|
|
370
|
-
};
|
|
371
|
-
resolve(result);
|
|
372
|
-
}).catch(function (error) {
|
|
373
|
-
trace.error('Error creating snapshot', error);
|
|
374
|
-
reject(error);
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
};
|
|
378
|
-
//Will clean streams, publishers and subscribers, but will not remove event listeners
|
|
379
|
-
TechseeMediaServiceBase.prototype.clearService = function () {
|
|
380
|
-
var _this = this;
|
|
381
|
-
trace.info('MediaService clearing all resources');
|
|
382
|
-
return this.disconnectFromSessionInternal(MediaConstants_1.MediaSessionDisconnectReason.ForcedByConsumer).then(this.clearSubscribers).then(this.clearRegisteredStreams).then(this._localStreamsManager.clearAllStreams).then(function () {
|
|
383
|
-
_this._initLocalStreamsPromise = null;
|
|
384
|
-
}).then(function () {
|
|
385
|
-
return undefined;
|
|
386
|
-
});
|
|
387
|
-
};
|
|
388
|
-
//Will clear the service and remove all event listeners
|
|
389
|
-
TechseeMediaServiceBase.prototype.dispose = function () {
|
|
390
|
-
var _this = this;
|
|
391
|
-
return this.clearService().catch(function () {
|
|
392
|
-
return undefined;
|
|
393
|
-
}).then(function () {
|
|
394
|
-
_this._emitter.removeAllListeners();
|
|
395
|
-
});
|
|
396
|
-
};
|
|
397
|
-
Object.defineProperty(TechseeMediaServiceBase.prototype, "subscribers", {
|
|
398
|
-
//#endregion
|
|
399
|
-
//#region Protected Methods
|
|
400
|
-
get: function get() {
|
|
401
|
-
return this._subscribers;
|
|
402
|
-
},
|
|
403
|
-
enumerable: true,
|
|
404
|
-
configurable: true
|
|
321
|
+
});
|
|
322
|
+
})["catch"](function (err) {
|
|
323
|
+
trace.error('switchCamera: Failed to switch camera: ', err);
|
|
324
|
+
|
|
325
|
+
if (!revertCameraWhenFailed) {
|
|
326
|
+
window.latestLocalMediaConstraints = latestLocalMediaConstraints;
|
|
327
|
+
return _this.switchCamera(true);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return Promise.reject('Failed to switch camera.');
|
|
405
331
|
});
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
TechseeMediaServiceBase.prototype.replaceStreamTracks = function (mediaStream) {
|
|
335
|
+
if (this._session.instance) {
|
|
336
|
+
return this._session.instance.replaceStreamTracks(mediaStream);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return Promise.reject('replaceStreamTracks - session instance is not exists.');
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
TechseeMediaServiceBase.prototype.registerStreamResult = function (constraints, streamResult, switchCamera, addStreamType) {
|
|
343
|
+
var _this = this;
|
|
344
|
+
|
|
345
|
+
var regPromises = [];
|
|
346
|
+
var isOpentok = this._serviceOptions.mediaServiceType === MediaConstants_1.MediaServiceType.OPENTOK;
|
|
347
|
+
|
|
348
|
+
if (streamResult.isNew) {
|
|
349
|
+
trace.info('registerStreamResult: stream result from getUserMediaStream:', streamResult.mediaStream);
|
|
350
|
+
streamResult.mediaStream.getTracks().forEach(function (mediaTrack) {
|
|
351
|
+
trace.info('registerStreamResult: stream result from mediaTrack:', mediaTrack);
|
|
352
|
+
var streamType = addStreamType || (mediaTrack.kind === 'video' ? MediaConstants_1.KnownMediaStream.USER_VIDEO_STREAM : MediaConstants_1.KnownMediaStream.USER_AUDIO_STREAM);
|
|
353
|
+
var newDedicatedStream = new TechseeMediaStream_1.TechseeMediaStream(mediaTrack, streamType, false);
|
|
354
|
+
|
|
355
|
+
if (isOpentok) {
|
|
356
|
+
regPromises.push(_this.registerStream(newDedicatedStream));
|
|
420
357
|
} else {
|
|
421
|
-
|
|
422
|
-
if (streamToChangeState.isRemote && streamToChangeState.streamKind === MediaConstants_1.KnownMediaStreamKind.Audio) {
|
|
423
|
-
this.subscribers.forEach(function (subscriber) {
|
|
424
|
-
if (subscriber.streamType === streamType) {
|
|
425
|
-
subscriber.muteSound(isPaused);
|
|
426
|
-
}
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
trace.info('Local stream enable state is changed', { streamType: streamType, isPaused: isPaused });
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
|
-
TechseeMediaServiceBase.prototype.registerEventCallback = function (event, callback) {
|
|
433
|
-
this._emitter.on(event, callback);
|
|
434
|
-
};
|
|
435
|
-
TechseeMediaServiceBase.prototype.emitEvent = function (event, eventArgs) {
|
|
436
|
-
var _this = this;
|
|
437
|
-
setTimeout(function () {
|
|
438
|
-
_this._emitter.emit(event, eventArgs);
|
|
439
|
-
});
|
|
440
|
-
};
|
|
441
|
-
//#endregion Protected Methods
|
|
442
|
-
//#region Private Methods
|
|
443
|
-
TechseeMediaServiceBase.prototype.registerRemoteMediaTrack = function (remoteMediaTrack) {
|
|
444
|
-
trace.info("Registering remote " + remoteMediaTrack.trackType + " MediaStreamTrack", remoteMediaTrack.mediaTrack);
|
|
445
|
-
var currentStream = this._registeredStreams.get(remoteMediaTrack.trackType);
|
|
446
|
-
if (currentStream && !currentStream.isRemote) {
|
|
447
|
-
return Promise.reject(new Error('Cannot register remote stream with the same type as local stream'));
|
|
358
|
+
regPromises.push(switchCamera ? _this.registerTrack(newDedicatedStream) : _this.registerLocalMediaStream(newDedicatedStream));
|
|
448
359
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return Promise.all(regPromises);
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
TechseeMediaServiceBase.prototype.disconnectFromMediaSession = function () {
|
|
367
|
+
if (this._session && this._session.instance) {
|
|
368
|
+
return this._session.instance.sessionDisconnect();
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
Object.defineProperty(TechseeMediaServiceBase.prototype, "supportSwitchCameras", {
|
|
373
|
+
get: function get() {
|
|
374
|
+
return this._isIOS_13_orLater || this._localStreamsManager.groupedDevices.camerasCount > 1;
|
|
375
|
+
},
|
|
376
|
+
enumerable: false,
|
|
377
|
+
configurable: true
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
TechseeMediaServiceBase.prototype._connectToSession = function (sessionParams) {
|
|
381
|
+
var _this = this;
|
|
382
|
+
|
|
383
|
+
this.serviceInitGuard();
|
|
384
|
+
|
|
385
|
+
if (!this._session) {
|
|
386
|
+
this._session = {
|
|
387
|
+
params: cloneDeep_1["default"](sessionParams)
|
|
388
|
+
};
|
|
389
|
+
this._session.connectPromise = new Promise(function (resolve, reject) {
|
|
390
|
+
var doAsyncReject = function doAsyncReject(error) {
|
|
391
|
+
/*
|
|
392
|
+
Reject with timeout, to change JS 'execution flow'.
|
|
393
|
+
If timeout removed, session is assigned to null, before promise returns, and "catch" will not
|
|
394
|
+
work on promise that is returned.
|
|
395
|
+
*/
|
|
396
|
+
setTimeout(function () {
|
|
397
|
+
_this._session = null;
|
|
398
|
+
reject(error);
|
|
399
|
+
});
|
|
465
400
|
};
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
return registerTrack();
|
|
470
|
-
};
|
|
471
|
-
TechseeMediaServiceBase.prototype.unregisterTechseeMediaStream = function (streamToUnregister, reason) {
|
|
472
|
-
var _this = this;
|
|
473
|
-
var traceError = function traceError(error) {
|
|
474
|
-
trace.warn('Unregister TechseeMediaStream error:', error);
|
|
401
|
+
|
|
402
|
+
var sessionHandlers = {
|
|
403
|
+
onDisconnectedHandler: _this.onSessionDisconnectHandler
|
|
475
404
|
};
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
if (subscriber.streamType === streamToUnregister.streamType) {
|
|
480
|
-
promises.push(subscriber.stopRendering().catch(traceError));
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
if (!streamToUnregister.isRemote) {
|
|
484
|
-
this._publishers.forEach(function (publisher) {
|
|
485
|
-
if (publisher.streamTypes.find(function (streamType) {
|
|
486
|
-
return streamType === streamToUnregister.streamType;
|
|
487
|
-
})) {
|
|
488
|
-
if (_this._session && _this._session.instance) {
|
|
489
|
-
promises.push(_this._session.instance.onMediaStreamDestroyed(publisher.destinationRole).catch(traceError));
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
return Promise.all(promises).then(function () {
|
|
495
|
-
_this._registeredStreams.delete(streamToUnregister.streamType);
|
|
496
|
-
trace.info('Stream deleted', streamToUnregister.streamType);
|
|
497
|
-
var eventArgs = { streamType: streamToUnregister.streamType, reason: reason };
|
|
498
|
-
_this.emitEvent(privateEvents.STREAM_DESTROYED, eventArgs);
|
|
499
|
-
});
|
|
500
|
-
};
|
|
501
|
-
TechseeMediaServiceBase.prototype.unregisterRemoteMediaTrack = function (mediaTrack) {
|
|
502
|
-
var _this = this;
|
|
503
|
-
var promises = [];
|
|
504
|
-
this._registeredStreams.forEach(function (registeredStream) {
|
|
505
|
-
if (registeredStream.mediaTrack.id === mediaTrack.id) {
|
|
506
|
-
promises.push(_this.unregisterTechseeMediaStream(registeredStream, MediaConstants_1.MediaStreamUnregisterReason.ClosedRemotely));
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
return Promise.all(promises).then(function () {
|
|
510
|
-
return undefined;
|
|
405
|
+
|
|
406
|
+
var mediaSessionParams = __assign(__assign({}, sessionParams), {
|
|
407
|
+
peerConnectivityTimeoutSeconds: _this._serviceOptions.peerConnectivityTimeoutSeconds || MediaConstants_1.DEFAULT_PEER_CONNECTIVITY_TIMEOUT_SECONDS
|
|
511
408
|
});
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
409
|
+
|
|
410
|
+
trace.info('connectToSession', sessionParams);
|
|
411
|
+
var allowedValues = values_1["default"](MediaConstants_1.MediaServiceType);
|
|
412
|
+
|
|
413
|
+
switch (_this._serviceOptions.mediaServiceType) {
|
|
414
|
+
case MediaConstants_1.MediaServiceType.TURNSERVER:
|
|
415
|
+
_this._session.instance = new SessionTurn_1.TurnWebRtcSession(mediaSessionParams, sessionHandlers, _this._sessionStreamsManager);
|
|
416
|
+
break;
|
|
417
|
+
|
|
418
|
+
case MediaConstants_1.MediaServiceType.OPENTOK:
|
|
419
|
+
_this._session.instance = new SessionOpentok_1.OpentokSession(mediaSessionParams, _this._sessionStreamsManager);
|
|
420
|
+
break;
|
|
421
|
+
|
|
422
|
+
case MediaConstants_1.MediaServiceType.MEDIASERVER:
|
|
423
|
+
_this._session.instance = new MediaServer_1.MediaServerSession(mediaSessionParams, _this._sessionStreamsManager);
|
|
424
|
+
break;
|
|
425
|
+
|
|
426
|
+
default:
|
|
427
|
+
trace.error("mediaServiceType '" + _this._serviceOptions.mediaServiceType + "' is not supported.", {
|
|
428
|
+
allowedValues: allowedValues
|
|
519
429
|
});
|
|
430
|
+
doAsyncReject(new Error('mediaServiceType is not supported'));
|
|
520
431
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
trace.
|
|
528
|
-
|
|
432
|
+
|
|
433
|
+
if (_this._session && _this._session.instance) {
|
|
434
|
+
_this._session.instance.connect().then(function () {
|
|
435
|
+
trace.info('Session is connected');
|
|
436
|
+
resolve();
|
|
437
|
+
})["catch"](function (error) {
|
|
438
|
+
trace.error('Failed to connect to session', error);
|
|
439
|
+
doAsyncReject(error);
|
|
440
|
+
});
|
|
529
441
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
442
|
+
});
|
|
443
|
+
} else {
|
|
444
|
+
trace.warn('Session connected already. Disconnect before connect to new session again');
|
|
445
|
+
} //TODO - Alex: Change a structure of this function to be more safe
|
|
446
|
+
//(when we return, there should not be case when session or promise is null)
|
|
447
|
+
//To fix, need to return promise immediately, then execute process in setTimeout(fn, 0);
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
return this._session.connectPromise;
|
|
451
|
+
}; //#endregion Media Streams Management
|
|
452
|
+
//#region Session Management
|
|
453
|
+
|
|
454
|
+
/*
|
|
455
|
+
Creates instance of WebRTC session which connects to (signaling server), and begins to listen to WebRTC events.
|
|
456
|
+
*/
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
TechseeMediaServiceBase.prototype.connectToSession = function (sessionParams) {
|
|
460
|
+
return this._connectToSession(sessionParams);
|
|
461
|
+
};
|
|
462
|
+
/*
|
|
463
|
+
Disconnects from WebRTC session.
|
|
464
|
+
*/
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
TechseeMediaServiceBase.prototype.disconnectFromSession = function () {
|
|
468
|
+
return this.disconnectFromSessionInternal(MediaConstants_1.MediaSessionDisconnectReason.ForcedByConsumer);
|
|
469
|
+
};
|
|
470
|
+
/*
|
|
471
|
+
Updates a credentials for turn server
|
|
472
|
+
*/
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
TechseeMediaServiceBase.prototype.updateSessionCredentials = function (credentials) {
|
|
476
|
+
trace.info('updateSessionCredentials');
|
|
477
|
+
|
|
478
|
+
if (!this.sessionExistsGuard(false)) {
|
|
479
|
+
return Promise.reject('There no session to update credentials');
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
this._session.params.credentials = cloneDeep_1["default"](credentials);
|
|
483
|
+
return Promise.resolve();
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
TechseeMediaServiceBase.prototype.enableVoipDuringSession = function () {
|
|
487
|
+
if (!this._isVoipEnabled && this.isLocalStreamInitialized) {
|
|
488
|
+
this._initLocalStreamsPromise = null;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
this._isVoipEnabled = true;
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
TechseeMediaServiceBase.prototype.disconnectFromSessionInternal = function (reason) {
|
|
495
|
+
if (!this._session) {
|
|
496
|
+
return Promise.resolve();
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
trace.info('Disconnecting from session', reason);
|
|
500
|
+
var lastSession = this._session;
|
|
501
|
+
this._session = null;
|
|
502
|
+
return Promise.all([lastSession.instance.disconnect(), this.clearPublishers()]).then(function () {
|
|
503
|
+
return undefined;
|
|
504
|
+
});
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
TechseeMediaServiceBase.prototype.getStatsForRemoteTrack = function (streamType) {
|
|
508
|
+
if (!this.sessionExistsGuard(false)) {
|
|
509
|
+
return Promise.reject(new Error('Media session not started'));
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
var streamForStats = this.getRegisteredStreamByType(streamType);
|
|
513
|
+
|
|
514
|
+
if (!streamForStats) {
|
|
515
|
+
return Promise.reject(new Error('Stream for requested type was not found'));
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
return this._session.instance.getRemoteTrackStats(streamForStats.mediaTrack).then(function (trackStats) {
|
|
519
|
+
traceStatsInfo("MediaTrackStats for " + streamType + ": " + JSON.stringify(trackStats));
|
|
520
|
+
return {
|
|
521
|
+
trackId: streamForStats.mediaTrack.id,
|
|
522
|
+
trackStats: trackStats
|
|
523
|
+
};
|
|
524
|
+
});
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
TechseeMediaServiceBase.prototype.onSessionDisconnectHandler = function (reason) {
|
|
528
|
+
var _this = this;
|
|
529
|
+
|
|
530
|
+
trace.info('onSessionDisconnectHandler', reason);
|
|
531
|
+
|
|
532
|
+
if (reason !== MediaConstants_1.MediaSessionDisconnectReason.ForcedByConsumer) {
|
|
533
|
+
var lastParams_1 = this._session && this._session.params ? this._session.params : null;
|
|
534
|
+
this.disconnectFromSessionInternal(reason).then(function () {
|
|
535
|
+
var reconnectReasons = [MediaConstants_1.MediaSessionDisconnectReason.InitiatorPeerReconnected, MediaConstants_1.MediaSessionDisconnectReason.SignalingChannelDisconnect, MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionInterrupted, MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionStateChangeTimeout];
|
|
536
|
+
|
|
537
|
+
if (lastParams_1 && includes_1["default"](reconnectReasons, reason) && _this._autoReconnectEnabled) {
|
|
538
|
+
_this.reconnectToSession(lastParams_1);
|
|
539
|
+
} else if (!_this._autoReconnectEnabled) {
|
|
540
|
+
trace.info('No reconnection- auto reconnect disabled');
|
|
549
541
|
} else {
|
|
550
|
-
|
|
542
|
+
trace.info('No params for reconnection to media session');
|
|
551
543
|
}
|
|
552
|
-
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
544
|
+
});
|
|
545
|
+
} else {
|
|
546
|
+
trace.info('Ignore Session disconnect event');
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
TechseeMediaServiceBase.prototype.setAutoReconnect = function (state) {
|
|
551
|
+
this._autoReconnectEnabled = state;
|
|
552
|
+
trace.info('_autoReconnectEnabled:', state);
|
|
553
|
+
|
|
554
|
+
if (this._autoReconnectEnabled && !this.isSessionActive) {
|
|
555
|
+
var lastParams = this._session && this._session.params ? this._session.params : null;
|
|
556
|
+
|
|
557
|
+
if (lastParams) {
|
|
558
|
+
trace.info('setAutoReconnect - reconnect to session');
|
|
559
|
+
this.reconnectToSession(lastParams);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
TechseeMediaServiceBase.prototype.reconnectToSession = function (lastParams) {
|
|
565
|
+
trace.info('Reconnecting to media session, sessionParams:', lastParams);
|
|
566
|
+
|
|
567
|
+
this._connectToSession(lastParams).then(function () {
|
|
568
|
+
trace.info('Media session reconnected');
|
|
569
|
+
})["catch"](function (error) {
|
|
570
|
+
trace.error('Error while reconnecting to media session', error);
|
|
571
|
+
});
|
|
572
|
+
}; //#endregion Session Management
|
|
573
|
+
//#region Utils
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
TechseeMediaServiceBase.prototype.getSnapshotFromKnownStream = function (sourceStream, snapshotOptions) {
|
|
577
|
+
var _this = this;
|
|
578
|
+
|
|
579
|
+
return new Promise(function (resolve, reject) {
|
|
580
|
+
if (sourceStream !== MediaConstants_1.KnownMediaStream.USER_VIDEO_STREAM && sourceStream !== MediaConstants_1.KnownMediaStream.USER_SCREEN_SHARE_STREAM) {
|
|
581
|
+
trace.error('The requested stream is not video stream, and cannot be used for snapshot');
|
|
582
|
+
reject(new Error('INCOMPATIBLE_STREAM_FOR_SNAPSHOT'));
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
var snapshotStream = _this.getRegisteredStreamByType(sourceStream);
|
|
587
|
+
|
|
588
|
+
if (!snapshotStream) {
|
|
589
|
+
trace.error('Cannot make snapshot: The requested stream not exists yet.');
|
|
590
|
+
reject(new Error('NO_REQUESTED_STREAM'));
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
MediaDomUtils_1.getSnapshotFromMediaStream(snapshotStream.mediaStream, sourceStream, snapshotOptions).then(function (imageData) {
|
|
595
|
+
var urlComponents = imageData.split(';base64,');
|
|
596
|
+
var mimeType = urlComponents[0].split(':')[1];
|
|
597
|
+
var bytes = atob(urlComponents[1]);
|
|
598
|
+
var buffer = new ArrayBuffer(bytes.length);
|
|
599
|
+
var rawData = new Uint8Array(buffer);
|
|
600
|
+
|
|
601
|
+
for (var i = 0; i < bytes.length; i++) {
|
|
602
|
+
rawData[i] = bytes.charCodeAt(i);
|
|
560
603
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
subscriber.renderStream(registeredStream);
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
return Promise.resolve();
|
|
568
|
-
};
|
|
569
|
-
TechseeMediaServiceBase.prototype.bindClassMethods = function () {
|
|
570
|
-
this.updateSessionCredentials = this.updateSessionCredentials.bind(this);
|
|
571
|
-
this.getStreamForDestinationRole = this.getStreamForDestinationRole.bind(this);
|
|
572
|
-
this.registerRemoteMediaTrack = this.registerRemoteMediaTrack.bind(this);
|
|
573
|
-
this.unregisterRemoteMediaTrack = this.unregisterRemoteMediaTrack.bind(this);
|
|
574
|
-
this.createMediaPublisher = this.createMediaPublisher.bind(this);
|
|
575
|
-
this.updateSubscribersWithNewStream = this.updateSubscribersWithNewStream.bind(this);
|
|
576
|
-
this.initLocalMediaStreams = this.initLocalMediaStreams.bind(this);
|
|
577
|
-
this.onSessionDisconnectHandler = this.onSessionDisconnectHandler.bind(this);
|
|
578
|
-
this.clearService = this.clearService.bind(this);
|
|
579
|
-
this.clearRegisteredStreams = this.clearRegisteredStreams.bind(this);
|
|
580
|
-
this.clearPublishers = this.clearPublishers.bind(this);
|
|
581
|
-
this.clearSubscribers = this.clearSubscribers.bind(this);
|
|
582
|
-
};
|
|
583
|
-
//region Cleanup
|
|
584
|
-
TechseeMediaServiceBase.prototype.clearRegisteredStreams = function () {
|
|
585
|
-
var _this = this;
|
|
586
|
-
trace.info('Clearing registered streams');
|
|
587
|
-
var promises = [];
|
|
588
|
-
this._registeredStreams.forEach(function (streamToUnregister) {
|
|
589
|
-
promises.push(_this.unregisterTechseeMediaStream(streamToUnregister, MediaConstants_1.MediaStreamUnregisterReason.ServiceCleanUp));
|
|
590
|
-
});
|
|
591
|
-
return Promise.all(promises).then(function () {
|
|
592
|
-
return undefined;
|
|
593
|
-
});
|
|
594
|
-
};
|
|
595
|
-
TechseeMediaServiceBase.prototype.clearSubscribers = function () {
|
|
596
|
-
var _this = this;
|
|
597
|
-
trace.info('Clearing subscribers');
|
|
598
|
-
var promises = [];
|
|
599
|
-
this._subscribers.forEach(function (subscriber) {
|
|
600
|
-
promises.push(_this.destroySubscriber(subscriber.container));
|
|
604
|
+
|
|
605
|
+
var blob = new Blob([rawData], {
|
|
606
|
+
type: mimeType
|
|
601
607
|
});
|
|
602
|
-
|
|
603
|
-
|
|
608
|
+
var objectUrl = window.URL.createObjectURL(blob);
|
|
609
|
+
trace.info('Snapshot created successfully');
|
|
610
|
+
var result = {
|
|
611
|
+
base64img: imageData,
|
|
612
|
+
objectUrl: objectUrl,
|
|
613
|
+
imageBlob: blob,
|
|
614
|
+
mimeType: mimeType
|
|
615
|
+
};
|
|
616
|
+
resolve(result);
|
|
617
|
+
})["catch"](function (error) {
|
|
618
|
+
trace.error('Error creating snapshot', error);
|
|
619
|
+
reject(error);
|
|
620
|
+
});
|
|
621
|
+
});
|
|
622
|
+
}; //Will clean streams, publishers and subscribers, but will not remove event listeners
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
TechseeMediaServiceBase.prototype.clearService = function () {
|
|
626
|
+
var _this = this;
|
|
627
|
+
|
|
628
|
+
trace.info('MediaService clearing all resources');
|
|
629
|
+
return this.disconnectFromSessionInternal(MediaConstants_1.MediaSessionDisconnectReason.ForcedByConsumer).then(this.clearSubscribers).then(this.clearRegisteredStreams).then(this._localStreamsManager.clearAllStreams).then(function () {
|
|
630
|
+
_this._initLocalStreamsPromise = null;
|
|
631
|
+
_this._isVoipEnabled = false;
|
|
632
|
+
}).then(function () {
|
|
633
|
+
return undefined;
|
|
634
|
+
});
|
|
635
|
+
}; //Will clear the service and remove all event listeners
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
TechseeMediaServiceBase.prototype.dispose = function () {
|
|
639
|
+
var _this = this;
|
|
640
|
+
|
|
641
|
+
return this.clearService()["catch"](function () {
|
|
642
|
+
return undefined;
|
|
643
|
+
}).then(function () {
|
|
644
|
+
_this._emitter.removeAllListeners();
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
Object.defineProperty(TechseeMediaServiceBase.prototype, "subscribers", {
|
|
649
|
+
//#endregion
|
|
650
|
+
//#region Protected Methods
|
|
651
|
+
get: function get() {
|
|
652
|
+
return this._subscribers;
|
|
653
|
+
},
|
|
654
|
+
enumerable: false,
|
|
655
|
+
configurable: true
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
TechseeMediaServiceBase.prototype.registerLocalMediaStream = function (tsMediaStream) {
|
|
659
|
+
trace.info('Registering local stream', tsMediaStream.streamType);
|
|
660
|
+
|
|
661
|
+
if (this._registeredStreams.has(tsMediaStream.streamType)) {
|
|
662
|
+
return Promise.reject(new Error("Stream " + tsMediaStream.streamType + " already registered"));
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
return this.registerStream(tsMediaStream);
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
TechseeMediaServiceBase.prototype.getRegisteredStreamByType = function (streamType) {
|
|
669
|
+
return this._registeredStreams.get(streamType) || null;
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
TechseeMediaServiceBase.prototype.changeEnableForKnownStream = function (streamType, isPaused) {
|
|
673
|
+
var streamToChangeState = this.getRegisteredStreamByType(streamType);
|
|
674
|
+
|
|
675
|
+
if (!streamToChangeState) {
|
|
676
|
+
trace.warn('There no stream found to change enable state', streamType);
|
|
677
|
+
} else {
|
|
678
|
+
streamToChangeState.mediaTrack.enabled = !isPaused;
|
|
679
|
+
|
|
680
|
+
if (streamToChangeState.isRemote && streamToChangeState.streamKind === MediaConstants_1.KnownMediaStreamKind.Audio) {
|
|
681
|
+
this.subscribers.forEach(function (subscriber) {
|
|
682
|
+
if (subscriber.streamType === streamType) {
|
|
683
|
+
subscriber.muteSound(isPaused);
|
|
684
|
+
}
|
|
604
685
|
});
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
trace.info('Local stream enable state is changed', {
|
|
689
|
+
streamType: streamType,
|
|
690
|
+
isPaused: isPaused
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
TechseeMediaServiceBase.prototype.registerEventCallback = function (event, callback) {
|
|
696
|
+
this._emitter.on(event, callback);
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
TechseeMediaServiceBase.prototype.unregisterEventCallback = function (event, callback) {
|
|
700
|
+
this._emitter.off(event, callback);
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
TechseeMediaServiceBase.prototype.emitEvent = function (event, eventArgs) {
|
|
704
|
+
var _this = this;
|
|
705
|
+
|
|
706
|
+
setTimeout(function () {
|
|
707
|
+
_this._emitter.emit(event, eventArgs);
|
|
708
|
+
});
|
|
709
|
+
}; //#endregion Protected Methods
|
|
710
|
+
//#region Private Methods
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
TechseeMediaServiceBase.prototype.registerRemoteMediaTrack = function (remoteMediaTrack) {
|
|
714
|
+
trace.info("Registering remote " + remoteMediaTrack.trackType + " MediaStreamTrack", remoteMediaTrack.mediaTrack);
|
|
715
|
+
|
|
716
|
+
var currentStream = this._registeredStreams.get(remoteMediaTrack.trackType);
|
|
717
|
+
|
|
718
|
+
if (currentStream && !currentStream.isRemote) {
|
|
719
|
+
return Promise.reject(new Error('Cannot register remote stream with the same type as local stream'));
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
var newDedicatedStream = new TechseeMediaStream_1.TechseeMediaStream(remoteMediaTrack.mediaTrack, remoteMediaTrack.trackType, true);
|
|
723
|
+
return this.registerStream(newDedicatedStream);
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
TechseeMediaServiceBase.prototype.registerTrack = function (mediaStream) {
|
|
727
|
+
var _this = this;
|
|
728
|
+
|
|
729
|
+
mediaStream.mediaTrack.onended = function () {
|
|
730
|
+
return _this.unregisterTechseeMediaStream(mediaStream, MediaConstants_1.MediaStreamUnregisterReason.NativeEvent);
|
|
605
731
|
};
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
732
|
+
|
|
733
|
+
this._registeredStreams.set(mediaStream.streamType, mediaStream);
|
|
734
|
+
|
|
735
|
+
trace.info("TechseeMediaStream registered - " + mediaStream.streamType, TechseeMediaStream_1.TechseeMediaStream);
|
|
736
|
+
return this.updateSubscribersWithNewStream(mediaStream).then(function () {
|
|
737
|
+
var eventArgs = {
|
|
738
|
+
streamType: mediaStream.streamType
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
_this.emitEvent(privateEvents.STREAM_CREATED, eventArgs);
|
|
742
|
+
});
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
TechseeMediaServiceBase.prototype.registerStream = function (mediaStream) {
|
|
746
|
+
var _this = this;
|
|
747
|
+
|
|
748
|
+
var currentStream = this._registeredStreams.get(mediaStream.streamType);
|
|
749
|
+
|
|
750
|
+
if (currentStream) {
|
|
751
|
+
return this.unregisterTechseeMediaStream(currentStream, MediaConstants_1.MediaStreamUnregisterReason.ReplacingStream).then(function () {
|
|
752
|
+
return _this.registerTrack(mediaStream);
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
return this.registerTrack(mediaStream);
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
TechseeMediaServiceBase.prototype.unregisterTechseeMediaStream = function (streamToUnregister, reason) {
|
|
760
|
+
var _this = this;
|
|
761
|
+
|
|
762
|
+
var traceError = function traceError(error) {
|
|
763
|
+
trace.warn('Unregister TechseeMediaStream error:', error);
|
|
616
764
|
};
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
765
|
+
|
|
766
|
+
var promises = [];
|
|
767
|
+
trace.info('Unregister TechseeMediaStream: ', streamToUnregister.streamType);
|
|
768
|
+
|
|
769
|
+
this._subscribers.forEach(function (subscriber) {
|
|
770
|
+
if (subscriber.streamType === streamToUnregister.streamType) {
|
|
771
|
+
promises.push(subscriber.stopRendering()["catch"](traceError));
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
if (!streamToUnregister.isRemote) {
|
|
776
|
+
this._publishers.forEach(function (publisher) {
|
|
777
|
+
if (publisher.streamTypes.find(function (streamType) {
|
|
778
|
+
return streamType === streamToUnregister.streamType;
|
|
779
|
+
})) {
|
|
780
|
+
if (_this._session && _this._session.instance) {
|
|
781
|
+
promises.push(_this._session.instance.onMediaStreamDestroyed(publisher.destinationRole)["catch"](traceError));
|
|
782
|
+
}
|
|
622
783
|
}
|
|
623
|
-
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
return Promise.all(promises).then(function () {
|
|
788
|
+
_this._registeredStreams["delete"](streamToUnregister.streamType);
|
|
789
|
+
|
|
790
|
+
trace.info('Stream deleted', streamToUnregister.streamType);
|
|
791
|
+
var eventArgs = {
|
|
792
|
+
streamType: streamToUnregister.streamType,
|
|
793
|
+
reason: reason
|
|
794
|
+
};
|
|
795
|
+
|
|
796
|
+
_this.emitEvent(privateEvents.STREAM_DESTROYED, eventArgs);
|
|
797
|
+
});
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
TechseeMediaServiceBase.prototype.unregisterRemoteMediaTrack = function (mediaTrack) {
|
|
801
|
+
var _this = this;
|
|
802
|
+
|
|
803
|
+
var promises = [];
|
|
804
|
+
|
|
805
|
+
this._registeredStreams.forEach(function (registeredStream) {
|
|
806
|
+
if (registeredStream.mediaTrack.id === mediaTrack.id) {
|
|
807
|
+
promises.push(_this.unregisterTechseeMediaStream(registeredStream, MediaConstants_1.MediaStreamUnregisterReason.ClosedRemotely));
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
return Promise.all(promises).then(function () {
|
|
812
|
+
return undefined;
|
|
813
|
+
});
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
TechseeMediaServiceBase.prototype.removePublisher = function (publisher) {
|
|
817
|
+
this._publishers["delete"](publisher.destinationRole);
|
|
818
|
+
|
|
819
|
+
if (this._session && this._session.instance) {
|
|
820
|
+
trace.info('Removing publisher', publisher.destinationRole);
|
|
821
|
+
return this._session.instance.onMediaStreamDestroyed(publisher.destinationRole)["catch"](function (error) {
|
|
822
|
+
trace.warn('Error while removing publisher', error);
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
return Promise.resolve();
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
TechseeMediaServiceBase.prototype.getStreamForDestinationRole = function (destinationRole) {
|
|
830
|
+
var _this = this;
|
|
831
|
+
|
|
832
|
+
this.serviceInitGuard();
|
|
833
|
+
|
|
834
|
+
if (this._publishers.has(destinationRole)) {
|
|
835
|
+
trace.info("Publisher for " + destinationRole + " already exists");
|
|
836
|
+
return Promise.resolve(this._publishers.get(destinationRole).mediaStream);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
if (!this._publisherPromises.get(destinationRole)) {
|
|
840
|
+
trace.info("Creating publisher for " + destinationRole);
|
|
841
|
+
var publisherPromise = this.initLocalMediaStreams().then(function () {
|
|
842
|
+
return _this.createMediaPublisher(destinationRole);
|
|
843
|
+
}).then(function (mediaPublisher) {
|
|
844
|
+
if (mediaPublisher) {
|
|
845
|
+
_this._publishers.set(destinationRole, mediaPublisher);
|
|
628
846
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
847
|
+
|
|
848
|
+
_this._publisherPromises["delete"](destinationRole);
|
|
849
|
+
|
|
850
|
+
return mediaPublisher ? mediaPublisher.mediaStream : null;
|
|
851
|
+
})["catch"](function (ex) {
|
|
852
|
+
if (ex && ex.message === 'audioStreamFailed') {
|
|
853
|
+
_this._isVoipEnabled = false;
|
|
854
|
+
return null;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
_this._publisherPromises["delete"](destinationRole);
|
|
858
|
+
|
|
859
|
+
throw ex;
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
this._publisherPromises.set(destinationRole, publisherPromise);
|
|
863
|
+
} else {
|
|
864
|
+
trace.info("Create publisher promise for " + destinationRole + " already exists");
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
return this._publisherPromises.get(destinationRole);
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
TechseeMediaServiceBase.prototype.updateSubscribersWithNewStream = function (registeredStream) {
|
|
871
|
+
trace.info("Updating subscribers of " + registeredStream.streamType + " with new stream");
|
|
872
|
+
|
|
873
|
+
if (this._subscribers.size === 0) {
|
|
874
|
+
trace.warn("No subscribers exists for the " + registeredStream.streamType + ".");
|
|
875
|
+
} else {
|
|
876
|
+
trace.info("Total " + this._subscribers.size + " subscribers exists, will check if rerender needed.");
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
this._subscribers.forEach(function (subscriber) {
|
|
880
|
+
if (subscriber.streamType === registeredStream.streamType) {
|
|
881
|
+
trace.info(registeredStream.streamType + " rendering on subscriber");
|
|
882
|
+
subscriber.renderStream(registeredStream);
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
|
|
886
|
+
return Promise.resolve();
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
TechseeMediaServiceBase.prototype.bindClassMethods = function () {
|
|
890
|
+
this.updateSessionCredentials = this.updateSessionCredentials.bind(this);
|
|
891
|
+
this.getStreamForDestinationRole = this.getStreamForDestinationRole.bind(this);
|
|
892
|
+
this.registerRemoteMediaTrack = this.registerRemoteMediaTrack.bind(this);
|
|
893
|
+
this.unregisterRemoteMediaTrack = this.unregisterRemoteMediaTrack.bind(this);
|
|
894
|
+
this.createMediaPublisher = this.createMediaPublisher.bind(this);
|
|
895
|
+
this.updateSubscribersWithNewStream = this.updateSubscribersWithNewStream.bind(this);
|
|
896
|
+
this.initLocalMediaStreams = this.initLocalMediaStreams.bind(this);
|
|
897
|
+
this.onSessionDisconnectHandler = this.onSessionDisconnectHandler.bind(this);
|
|
898
|
+
this.clearService = this.clearService.bind(this);
|
|
899
|
+
this.clearRegisteredStreams = this.clearRegisteredStreams.bind(this);
|
|
900
|
+
this.clearPublishers = this.clearPublishers.bind(this);
|
|
901
|
+
this.clearSubscribers = this.clearSubscribers.bind(this);
|
|
902
|
+
this._connectToSession = this._connectToSession.bind(this);
|
|
903
|
+
this.disconnectFromMediaSession = this.disconnectFromMediaSession.bind(this);
|
|
904
|
+
}; //region Cleanup
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
TechseeMediaServiceBase.prototype.clearRegisteredStreams = function () {
|
|
908
|
+
var _this = this;
|
|
909
|
+
|
|
910
|
+
trace.info('Clearing registered streams');
|
|
911
|
+
var promises = [];
|
|
912
|
+
|
|
913
|
+
this._registeredStreams.forEach(function (streamToUnregister) {
|
|
914
|
+
promises.push(_this.unregisterTechseeMediaStream(streamToUnregister, MediaConstants_1.MediaStreamUnregisterReason.ServiceCleanUp));
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
return Promise.all(promises).then(function () {
|
|
918
|
+
return undefined;
|
|
919
|
+
});
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
TechseeMediaServiceBase.prototype.clearSubscribers = function () {
|
|
923
|
+
var _this = this;
|
|
924
|
+
|
|
925
|
+
trace.info('Clearing subscribers');
|
|
926
|
+
var promises = [];
|
|
927
|
+
|
|
928
|
+
this._subscribers.forEach(function (subscriber) {
|
|
929
|
+
promises.push(_this.destroySubscriber(subscriber.container));
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
return Promise.all(promises).then(function () {
|
|
933
|
+
return undefined;
|
|
934
|
+
});
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
TechseeMediaServiceBase.prototype.clearPublishers = function () {
|
|
938
|
+
var _this = this;
|
|
939
|
+
|
|
940
|
+
trace.info('Clearing publishers');
|
|
941
|
+
var promises = [];
|
|
942
|
+
|
|
943
|
+
this._publishers.forEach(function (publisher) {
|
|
944
|
+
promises.push(_this.removePublisher(publisher));
|
|
945
|
+
});
|
|
946
|
+
|
|
947
|
+
return Promise.all(promises).then(function () {
|
|
948
|
+
return undefined;
|
|
949
|
+
});
|
|
950
|
+
}; //#endregion Cleanup
|
|
951
|
+
//#region Simple Validation Methods
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
TechseeMediaServiceBase.prototype.serviceInitGuard = function (shouldThrow) {
|
|
955
|
+
if (shouldThrow === void 0) {
|
|
956
|
+
shouldThrow = true;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
return guards_1.throwableGuard(!!this._serviceOptions, 'Media service is not initialized', shouldThrow);
|
|
960
|
+
};
|
|
961
|
+
|
|
962
|
+
TechseeMediaServiceBase.prototype.sessionExistsGuard = function (shouldThrow) {
|
|
963
|
+
if (shouldThrow === void 0) {
|
|
964
|
+
shouldThrow = true;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
return guards_1.throwableGuard(!!this._session, 'There no active session', shouldThrow);
|
|
968
|
+
};
|
|
969
|
+
|
|
970
|
+
return TechseeMediaServiceBase;
|
|
632
971
|
}();
|
|
633
|
-
exports.TechseeMediaServiceBase = TechseeMediaServiceBase;
|
|
634
972
|
|
|
635
|
-
|
|
973
|
+
exports.TechseeMediaServiceBase = TechseeMediaServiceBase;
|
|
636
974
|
//# sourceMappingURL=MediaServiceBase.js.map
|