|
|
@@ -12,9 +12,7 @@ var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
|
|
12
|
12
|
var RTCEvents = require("../../service/RTC/RTCEvents.js");
|
|
13
|
13
|
var XMPPEvents = require("../../service/xmpp/XMPPEvents");
|
|
14
|
14
|
var UIEvents = require("../../service/UI/UIEvents");
|
|
15
|
|
-
|
|
16
|
|
-var eventEmitter = new EventEmitter();
|
|
17
|
|
-
|
|
|
15
|
+var desktopsharing = require("../desktopsharing/desktopsharing");
|
|
18
|
16
|
|
|
19
|
17
|
function getMediaStreamUsage()
|
|
20
|
18
|
{
|
|
|
@@ -43,233 +41,263 @@ function getMediaStreamUsage()
|
|
43
|
41
|
return result;
|
|
44
|
42
|
}
|
|
45
|
43
|
|
|
46
|
|
-var RTC = {
|
|
47
|
|
- rtcUtils: null,
|
|
48
|
|
- devices: {
|
|
|
44
|
+
|
|
|
45
|
+function RTC()
|
|
|
46
|
+{
|
|
|
47
|
+ this.rtcUtils = null;
|
|
|
48
|
+ this.devices = {
|
|
49
|
49
|
audio: true,
|
|
50
|
50
|
video: true
|
|
51
|
|
- },
|
|
52
|
|
- localStreams: [],
|
|
53
|
|
- remoteStreams: {},
|
|
54
|
|
- localAudio: null,
|
|
55
|
|
- localVideo: null,
|
|
56
|
|
- addStreamListener: function (listener, eventType) {
|
|
57
|
|
- eventEmitter.on(eventType, listener);
|
|
58
|
|
- },
|
|
59
|
|
- addListener: function (type, listener) {
|
|
60
|
|
- eventEmitter.on(type, listener);
|
|
61
|
|
- },
|
|
62
|
|
- removeStreamListener: function (listener, eventType) {
|
|
63
|
|
- if(!(eventType instanceof StreamEventTypes))
|
|
64
|
|
- throw "Illegal argument";
|
|
65
|
|
-
|
|
66
|
|
- eventEmitter.removeListener(eventType, listener);
|
|
67
|
|
- },
|
|
68
|
|
- createLocalStream: function (stream, type, change, videoType, isMuted, isGUMStream) {
|
|
69
|
|
-
|
|
70
|
|
- var localStream = new LocalStream(stream, type, eventEmitter, videoType, isGUMStream);
|
|
71
|
|
- //in firefox we have only one stream object
|
|
72
|
|
- if(this.localStreams.length == 0 ||
|
|
73
|
|
- this.localStreams[0].getOriginalStream() != stream)
|
|
74
|
|
- this.localStreams.push(localStream);
|
|
75
|
|
- if(isMuted === true)
|
|
|
51
|
+ };
|
|
|
52
|
+ this.localStreams = [];
|
|
|
53
|
+ this.remoteStreams = {};
|
|
|
54
|
+ this.localAudio = null;
|
|
|
55
|
+ this.localVideo = null;
|
|
|
56
|
+ this.eventEmitter = new EventEmitter();
|
|
|
57
|
+ var self = this;
|
|
|
58
|
+ desktopsharing.addListener(
|
|
|
59
|
+ function (stream, isUsingScreenStream, callback) {
|
|
|
60
|
+ self.changeLocalVideo(stream, isUsingScreenStream, callback);
|
|
|
61
|
+ }, DesktopSharingEventTypes.NEW_STREAM_CREATED);
|
|
|
62
|
+
|
|
|
63
|
+ // In case of IE we continue from 'onReady' callback
|
|
|
64
|
+ // passed to RTCUtils constructor. It will be invoked by Temasys plugin
|
|
|
65
|
+ // once it is initialized.
|
|
|
66
|
+ var onReady = function () {
|
|
|
67
|
+ self.eventEmitter.emit(RTCEvents.RTC_READY, true);
|
|
|
68
|
+ };
|
|
|
69
|
+
|
|
|
70
|
+ this.rtcUtils = new RTCUtils(this, onReady);
|
|
|
71
|
+
|
|
|
72
|
+ // Call onReady() if Temasys plugin is not used
|
|
|
73
|
+ if (!RTCBrowserType.isTemasysPluginUsed()) {
|
|
|
74
|
+ onReady();
|
|
|
75
|
+ }
|
|
|
76
|
+}
|
|
|
77
|
+
|
|
|
78
|
+RTC.prototype.obtainAudioAndVideoPermissions = function () {
|
|
|
79
|
+ this.rtcUtils.obtainAudioAndVideoPermissions(
|
|
|
80
|
+ null, null, getMediaStreamUsage());
|
|
|
81
|
+}
|
|
|
82
|
+
|
|
|
83
|
+RTC.prototype.onIncommingCall = function(event) {
|
|
|
84
|
+ DataChannels.init(event.peerconnection, self.eventEmitter);
|
|
|
85
|
+}
|
|
|
86
|
+
|
|
|
87
|
+RTC.prototype.selectedEndpoint = function (id) {
|
|
|
88
|
+ DataChannels.handleSelectedEndpointEvent(id);
|
|
|
89
|
+}
|
|
|
90
|
+
|
|
|
91
|
+RTC.prototype.pinEndpoint = function (id) {
|
|
|
92
|
+ DataChannels.handlePinnedEndpointEvent(id);
|
|
|
93
|
+}
|
|
|
94
|
+
|
|
|
95
|
+RTC.prototype.addStreamListener = function (listener, eventType) {
|
|
|
96
|
+ this.eventEmitter.on(eventType, listener);
|
|
|
97
|
+};
|
|
|
98
|
+
|
|
|
99
|
+RTC.prototype.addListener = function (type, listener) {
|
|
|
100
|
+ this.eventEmitter.on(type, listener);
|
|
|
101
|
+};
|
|
|
102
|
+
|
|
|
103
|
+RTC.prototype.removeStreamListener = function (listener, eventType) {
|
|
|
104
|
+ if(!(eventType instanceof StreamEventTypes))
|
|
|
105
|
+ throw "Illegal argument";
|
|
|
106
|
+
|
|
|
107
|
+ this.removeListener(eventType, listener);
|
|
|
108
|
+};
|
|
|
109
|
+
|
|
|
110
|
+RTC.prototype.createLocalStreams = function (streams, change) {
|
|
|
111
|
+ for (var i = 0; i < streams.length; i++) {
|
|
|
112
|
+ var localStream = new LocalStream(streams.stream,
|
|
|
113
|
+ streams.type, this.eventEmitter, streams.videoType,
|
|
|
114
|
+ streams.isGUMStream);
|
|
|
115
|
+ this.localStreams.push(localStream);
|
|
|
116
|
+ if (streams.isMuted === true)
|
|
76
|
117
|
localStream.setMute(true);
|
|
77
|
118
|
|
|
78
|
|
- if(type == "audio") {
|
|
|
119
|
+ if (streams.type == "audio") {
|
|
79
|
120
|
this.localAudio = localStream;
|
|
80
|
121
|
} else {
|
|
81
|
122
|
this.localVideo = localStream;
|
|
82
|
123
|
}
|
|
83
|
124
|
var eventType = StreamEventTypes.EVENT_TYPE_LOCAL_CREATED;
|
|
84
|
|
- if(change)
|
|
|
125
|
+ if (change)
|
|
85
|
126
|
eventType = StreamEventTypes.EVENT_TYPE_LOCAL_CHANGED;
|
|
86
|
127
|
|
|
87
|
|
- eventEmitter.emit(eventType, localStream, isMuted);
|
|
88
|
|
- return localStream;
|
|
89
|
|
- },
|
|
90
|
|
- removeLocalStream: function (stream) {
|
|
91
|
|
- for(var i = 0; i < this.localStreams.length; i++) {
|
|
92
|
|
- if(this.localStreams[i].getOriginalStream() === stream) {
|
|
93
|
|
- delete this.localStreams[i];
|
|
94
|
|
- return;
|
|
95
|
|
- }
|
|
96
|
|
- }
|
|
97
|
|
- },
|
|
98
|
|
- createRemoteStream: function (data, sid, thessrc) {
|
|
99
|
|
- var remoteStream = new MediaStream(data, sid, thessrc,
|
|
100
|
|
- RTCBrowserType.getBrowserType(), eventEmitter);
|
|
101
|
|
- var jid = data.peerjid || APP.xmpp.myJid();
|
|
102
|
|
- if(!this.remoteStreams[jid]) {
|
|
103
|
|
- this.remoteStreams[jid] = {};
|
|
104
|
|
- }
|
|
105
|
|
- this.remoteStreams[jid][remoteStream.type]= remoteStream;
|
|
106
|
|
- eventEmitter.emit(StreamEventTypes.EVENT_TYPE_REMOTE_CREATED, remoteStream);
|
|
107
|
|
- return remoteStream;
|
|
108
|
|
- },
|
|
109
|
|
- getPCConstraints: function () {
|
|
110
|
|
- return this.rtcUtils.pc_constraints;
|
|
111
|
|
- },
|
|
112
|
|
- getUserMediaWithConstraints:function(um, success_callback,
|
|
113
|
|
- failure_callback, resolution,
|
|
114
|
|
- bandwidth, fps, desktopStream)
|
|
115
|
|
- {
|
|
116
|
|
- return this.rtcUtils.getUserMediaWithConstraints(um, success_callback,
|
|
117
|
|
- failure_callback, resolution, bandwidth, fps, desktopStream);
|
|
118
|
|
- },
|
|
119
|
|
- attachMediaStream: function (elSelector, stream) {
|
|
120
|
|
- this.rtcUtils.attachMediaStream(elSelector, stream);
|
|
121
|
|
- },
|
|
122
|
|
- getStreamID: function (stream) {
|
|
123
|
|
- return this.rtcUtils.getStreamID(stream);
|
|
124
|
|
- },
|
|
125
|
|
- getVideoSrc: function (element) {
|
|
126
|
|
- return this.rtcUtils.getVideoSrc(element);
|
|
127
|
|
- },
|
|
128
|
|
- setVideoSrc: function (element, src) {
|
|
129
|
|
- this.rtcUtils.setVideoSrc(element, src);
|
|
130
|
|
- },
|
|
131
|
|
- getVideoElementName: function () {
|
|
132
|
|
- return RTCBrowserType.isTemasysPluginUsed() ? 'object' : 'video';
|
|
133
|
|
- },
|
|
134
|
|
- dispose: function() {
|
|
135
|
|
- if (this.rtcUtils) {
|
|
136
|
|
- this.rtcUtils = null;
|
|
|
128
|
+ this.eventEmitter.emit(eventType, localStream, streams.isMuted);
|
|
|
129
|
+ }
|
|
|
130
|
+ return this.localStreams;
|
|
|
131
|
+};
|
|
|
132
|
+
|
|
|
133
|
+RTC.prototype.removeLocalStream = function (stream) {
|
|
|
134
|
+ for(var i = 0; i < this.localStreams.length; i++) {
|
|
|
135
|
+ if(this.localStreams[i].getOriginalStream() === stream) {
|
|
|
136
|
+ delete this.localStreams[i];
|
|
|
137
|
+ return;
|
|
137
|
138
|
}
|
|
138
|
|
- },
|
|
139
|
|
- stop: function () {
|
|
140
|
|
- this.dispose();
|
|
141
|
|
- },
|
|
142
|
|
- start: function () {
|
|
143
|
|
- var self = this;
|
|
144
|
|
- APP.desktopsharing.addListener(
|
|
145
|
|
- function (stream, isUsingScreenStream, callback) {
|
|
146
|
|
- self.changeLocalVideo(stream, isUsingScreenStream, callback);
|
|
147
|
|
- }, DesktopSharingEventTypes.NEW_STREAM_CREATED);
|
|
148
|
|
- APP.xmpp.addListener(XMPPEvents.CALL_INCOMING, function(event) {
|
|
149
|
|
- DataChannels.init(event.peerconnection, eventEmitter);
|
|
150
|
|
- });
|
|
151
|
|
- APP.UI.addListener(UIEvents.SELECTED_ENDPOINT,
|
|
152
|
|
- DataChannels.handleSelectedEndpointEvent);
|
|
153
|
|
- APP.UI.addListener(UIEvents.PINNED_ENDPOINT,
|
|
154
|
|
- DataChannels.handlePinnedEndpointEvent);
|
|
155
|
|
-
|
|
156
|
|
- // In case of IE we continue from 'onReady' callback
|
|
157
|
|
- // passed to RTCUtils constructor. It will be invoked by Temasys plugin
|
|
158
|
|
- // once it is initialized.
|
|
159
|
|
- var onReady = function () {
|
|
160
|
|
- eventEmitter.emit(RTCEvents.RTC_READY, true);
|
|
161
|
|
- self.rtcUtils.obtainAudioAndVideoPermissions(
|
|
162
|
|
- null, null, getMediaStreamUsage());
|
|
163
|
|
- };
|
|
|
139
|
+ }
|
|
|
140
|
+};
|
|
164
|
141
|
|
|
165
|
|
- this.rtcUtils = new RTCUtils(this, onReady);
|
|
|
142
|
+RTC.prototype.createRemoteStream = function (data, sid, thessrc) {
|
|
|
143
|
+ var remoteStream = new MediaStream(data, sid, thessrc,
|
|
|
144
|
+ RTCBrowserType.getBrowserType(), this.eventEmitter);
|
|
|
145
|
+ if(data.peerjid)
|
|
|
146
|
+ return;
|
|
|
147
|
+ var jid = data.peerjid;
|
|
|
148
|
+ if(!this.remoteStreams[jid]) {
|
|
|
149
|
+ this.remoteStreams[jid] = {};
|
|
|
150
|
+ }
|
|
|
151
|
+ this.remoteStreams[jid][remoteStream.type]= remoteStream;
|
|
|
152
|
+ this.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_REMOTE_CREATED, remoteStream);
|
|
|
153
|
+ return remoteStream;
|
|
|
154
|
+};
|
|
166
|
155
|
|
|
167
|
|
- // Call onReady() if Temasys plugin is not used
|
|
168
|
|
- if (!RTCBrowserType.isTemasysPluginUsed()) {
|
|
169
|
|
- onReady();
|
|
170
|
|
- }
|
|
171
|
|
- },
|
|
172
|
|
- muteRemoteVideoStream: function (jid, value) {
|
|
173
|
|
- var stream;
|
|
|
156
|
+RTC.prototype.getPCConstraints = function () {
|
|
|
157
|
+ return this.rtcUtils.pc_constraints;
|
|
|
158
|
+};
|
|
174
|
159
|
|
|
175
|
|
- if(this.remoteStreams[jid] &&
|
|
176
|
|
- this.remoteStreams[jid][MediaStreamType.VIDEO_TYPE]) {
|
|
177
|
|
- stream = this.remoteStreams[jid][MediaStreamType.VIDEO_TYPE];
|
|
178
|
|
- }
|
|
|
160
|
+RTC.prototype.getUserMediaWithConstraints = function(um, success_callback,
|
|
|
161
|
+ failure_callback, resolution,
|
|
|
162
|
+ bandwidth, fps, desktopStream)
|
|
|
163
|
+{
|
|
|
164
|
+ return this.rtcUtils.getUserMediaWithConstraints(um, success_callback,
|
|
|
165
|
+ failure_callback, resolution, bandwidth, fps, desktopStream);
|
|
|
166
|
+};
|
|
179
|
167
|
|
|
180
|
|
- if(!stream)
|
|
181
|
|
- return true;
|
|
|
168
|
+RTC.prototype.attachMediaStream = function (elSelector, stream) {
|
|
|
169
|
+ this.rtcUtils.attachMediaStream(elSelector, stream);
|
|
|
170
|
+};
|
|
182
|
171
|
|
|
183
|
|
- if (value != stream.muted) {
|
|
184
|
|
- stream.setMute(value);
|
|
185
|
|
- return true;
|
|
186
|
|
- }
|
|
187
|
|
- return false;
|
|
188
|
|
- },
|
|
189
|
|
- switchVideoStreams: function (new_stream) {
|
|
190
|
|
- this.localVideo.stream = new_stream;
|
|
191
|
|
-
|
|
192
|
|
- this.localStreams = [];
|
|
193
|
|
-
|
|
194
|
|
- //in firefox we have only one stream object
|
|
195
|
|
- if (this.localAudio.getOriginalStream() != new_stream)
|
|
196
|
|
- this.localStreams.push(this.localAudio);
|
|
197
|
|
- this.localStreams.push(this.localVideo);
|
|
198
|
|
- },
|
|
199
|
|
- changeLocalVideo: function (stream, isUsingScreenStream, callback) {
|
|
200
|
|
- var oldStream = this.localVideo.getOriginalStream();
|
|
201
|
|
- var type = (isUsingScreenStream ? "screen" : "camera");
|
|
202
|
|
- var localCallback = callback;
|
|
203
|
|
- if(this.localVideo.isMuted() && this.localVideo.videoType !== type) {
|
|
204
|
|
- localCallback = function() {
|
|
205
|
|
- APP.xmpp.setVideoMute(false, function(mute) {
|
|
206
|
|
- eventEmitter.emit(RTCEvents.VIDEO_MUTE, mute);
|
|
207
|
|
- });
|
|
208
|
|
-
|
|
209
|
|
- callback();
|
|
210
|
|
- };
|
|
211
|
|
- }
|
|
212
|
|
- // FIXME: Workaround for FF/IE/Safari
|
|
213
|
|
- if (stream && stream.videoStream) {
|
|
214
|
|
- stream = stream.videoStream;
|
|
215
|
|
- }
|
|
216
|
|
- var videoStream = this.rtcUtils.createStream(stream, true);
|
|
217
|
|
- this.localVideo = this.createLocalStream(videoStream, "video", true, type);
|
|
218
|
|
- // Stop the stream to trigger onended event for old stream
|
|
219
|
|
- oldStream.stop();
|
|
220
|
|
-
|
|
221
|
|
- this.switchVideoStreams(videoStream, oldStream);
|
|
222
|
|
-
|
|
223
|
|
- APP.xmpp.switchStreams(videoStream, oldStream,localCallback);
|
|
224
|
|
- },
|
|
225
|
|
- changeLocalAudio: function (stream, callback) {
|
|
226
|
|
- var oldStream = this.localAudio.getOriginalStream();
|
|
227
|
|
- var newStream = this.rtcUtils.createStream(stream);
|
|
228
|
|
- this.localAudio = this.createLocalStream(newStream, "audio", true);
|
|
229
|
|
- // Stop the stream to trigger onended event for old stream
|
|
230
|
|
- oldStream.stop();
|
|
231
|
|
- APP.xmpp.switchStreams(newStream, oldStream, callback, true);
|
|
232
|
|
- },
|
|
233
|
|
- isVideoMuted: function (jid) {
|
|
234
|
|
- if (jid === APP.xmpp.myJid()) {
|
|
235
|
|
- var localVideo = APP.RTC.localVideo;
|
|
236
|
|
- return (!localVideo || localVideo.isMuted());
|
|
237
|
|
- } else {
|
|
238
|
|
- if (!APP.RTC.remoteStreams[jid] ||
|
|
239
|
|
- !APP.RTC.remoteStreams[jid][MediaStreamType.VIDEO_TYPE]) {
|
|
240
|
|
- return null;
|
|
241
|
|
- }
|
|
242
|
|
- return APP.RTC.remoteStreams[jid][MediaStreamType.VIDEO_TYPE].muted;
|
|
243
|
|
- }
|
|
244
|
|
- },
|
|
245
|
|
- setVideoMute: function (mute, callback, options) {
|
|
246
|
|
- if (!this.localVideo)
|
|
247
|
|
- return;
|
|
|
172
|
+RTC.prototype.getStreamID = function (stream) {
|
|
|
173
|
+ return this.rtcUtils.getStreamID(stream);
|
|
|
174
|
+};
|
|
248
|
175
|
|
|
249
|
|
- if (mute == APP.RTC.localVideo.isMuted())
|
|
250
|
|
- {
|
|
251
|
|
- APP.xmpp.sendVideoInfoPresence(mute);
|
|
252
|
|
- if (callback)
|
|
253
|
|
- callback(mute);
|
|
254
|
|
- }
|
|
255
|
|
- else
|
|
256
|
|
- {
|
|
257
|
|
- APP.RTC.localVideo.setMute(mute);
|
|
258
|
|
- APP.xmpp.setVideoMute(
|
|
259
|
|
- mute,
|
|
260
|
|
- callback,
|
|
261
|
|
- options);
|
|
|
176
|
+RTC.prototype.getVideoSrc = function (element) {
|
|
|
177
|
+ return this.rtcUtils.getVideoSrc(element);
|
|
|
178
|
+};
|
|
|
179
|
+
|
|
|
180
|
+RTC.prototype.setVideoSrc = function (element, src) {
|
|
|
181
|
+ this.rtcUtils.setVideoSrc(element, src);
|
|
|
182
|
+};
|
|
|
183
|
+
|
|
|
184
|
+RTC.prototype.getVideoElementName = function () {
|
|
|
185
|
+ return RTCBrowserType.isTemasysPluginUsed() ? 'object' : 'video';
|
|
|
186
|
+};
|
|
|
187
|
+
|
|
|
188
|
+RTC.prototype.dispose = function() {
|
|
|
189
|
+ if (this.rtcUtils) {
|
|
|
190
|
+ this.rtcUtils = null;
|
|
|
191
|
+ }
|
|
|
192
|
+};
|
|
|
193
|
+
|
|
|
194
|
+RTC.prototype.muteRemoteVideoStream = function (jid, value) {
|
|
|
195
|
+ var stream;
|
|
|
196
|
+
|
|
|
197
|
+ if(this.remoteStreams[jid] &&
|
|
|
198
|
+ this.remoteStreams[jid][MediaStreamType.VIDEO_TYPE]) {
|
|
|
199
|
+ stream = this.remoteStreams[jid][MediaStreamType.VIDEO_TYPE];
|
|
|
200
|
+ }
|
|
|
201
|
+
|
|
|
202
|
+ if(!stream)
|
|
|
203
|
+ return true;
|
|
|
204
|
+
|
|
|
205
|
+ if (value != stream.muted) {
|
|
|
206
|
+ stream.setMute(value);
|
|
|
207
|
+ return true;
|
|
|
208
|
+ }
|
|
|
209
|
+ return false;
|
|
|
210
|
+};
|
|
|
211
|
+
|
|
|
212
|
+RTC.prototype.switchVideoStreams = function (new_stream) {
|
|
|
213
|
+ this.localVideo.stream = new_stream;
|
|
|
214
|
+
|
|
|
215
|
+ this.localStreams = [];
|
|
|
216
|
+
|
|
|
217
|
+ //in firefox we have only one stream object
|
|
|
218
|
+ if (this.localAudio.getOriginalStream() != new_stream)
|
|
|
219
|
+ this.localStreams.push(this.localAudio);
|
|
|
220
|
+ this.localStreams.push(this.localVideo);
|
|
|
221
|
+};
|
|
|
222
|
+
|
|
|
223
|
+RTC.prototype.changeLocalVideo = function (stream, isUsingScreenStream, callback) {
|
|
|
224
|
+ var oldStream = this.localVideo.getOriginalStream();
|
|
|
225
|
+ var type = (isUsingScreenStream ? "screen" : "camera");
|
|
|
226
|
+ var localCallback = callback;
|
|
|
227
|
+
|
|
|
228
|
+ if(this.localVideo.isMuted() && this.localVideo.videoType !== type) {
|
|
|
229
|
+ localCallback = function() {
|
|
|
230
|
+ APP.xmpp.setVideoMute(false, function(mute) {
|
|
|
231
|
+ self.eventEmitter.emit(RTCEvents.VIDEO_MUTE, mute);
|
|
|
232
|
+ });
|
|
|
233
|
+
|
|
|
234
|
+ callback();
|
|
|
235
|
+ };
|
|
|
236
|
+ }
|
|
|
237
|
+ // FIXME: Workaround for FF/IE/Safari
|
|
|
238
|
+ if (stream && stream.videoStream) {
|
|
|
239
|
+ stream = stream.videoStream;
|
|
|
240
|
+ }
|
|
|
241
|
+ var videoStream = this.rtcUtils.createStream(stream, true);
|
|
|
242
|
+ this.localVideo = this.createLocalStream(videoStream, "video", true, type);
|
|
|
243
|
+ // Stop the stream to trigger onended event for old stream
|
|
|
244
|
+ oldStream.stop();
|
|
|
245
|
+
|
|
|
246
|
+ this.switchVideoStreams(videoStream, oldStream);
|
|
|
247
|
+
|
|
|
248
|
+ APP.xmpp.switchStreams(videoStream, oldStream,localCallback);
|
|
|
249
|
+};
|
|
|
250
|
+
|
|
|
251
|
+RTC.prototype.changeLocalAudio = function (stream, callback) {
|
|
|
252
|
+ var oldStream = this.localAudio.getOriginalStream();
|
|
|
253
|
+ var newStream = this.rtcUtils.createStream(stream);
|
|
|
254
|
+ this.localAudio = this.createLocalStream(newStream, "audio", true);
|
|
|
255
|
+ // Stop the stream to trigger onended event for old stream
|
|
|
256
|
+ oldStream.stop();
|
|
|
257
|
+ APP.xmpp.switchStreams(newStream, oldStream, callback, true);
|
|
|
258
|
+};
|
|
|
259
|
+
|
|
|
260
|
+RTC.prototype.isVideoMuted = function (jid) {
|
|
|
261
|
+ if (jid === APP.xmpp.myJid()) {
|
|
|
262
|
+ var localVideo = APP.RTC.localVideo;
|
|
|
263
|
+ return (!localVideo || localVideo.isMuted());
|
|
|
264
|
+ } else {
|
|
|
265
|
+ if (!this.remoteStreams[jid] ||
|
|
|
266
|
+ !this.remoteStreams[jid][MediaStreamType.VIDEO_TYPE]) {
|
|
|
267
|
+ return null;
|
|
262
|
268
|
}
|
|
263
|
|
- },
|
|
264
|
|
- setDeviceAvailability: function (devices) {
|
|
265
|
|
- if(!devices)
|
|
266
|
|
- return;
|
|
267
|
|
- if(devices.audio === true || devices.audio === false)
|
|
268
|
|
- this.devices.audio = devices.audio;
|
|
269
|
|
- if(devices.video === true || devices.video === false)
|
|
270
|
|
- this.devices.video = devices.video;
|
|
271
|
|
- eventEmitter.emit(RTCEvents.AVAILABLE_DEVICES_CHANGED, this.devices);
|
|
|
269
|
+ return this.remoteStreams[jid][MediaStreamType.VIDEO_TYPE].muted;
|
|
272
|
270
|
}
|
|
273
|
271
|
};
|
|
274
|
272
|
|
|
|
273
|
+RTC.prototype.setVideoMute = function (mute, callback, options) {
|
|
|
274
|
+ if (!this.localVideo)
|
|
|
275
|
+ return;
|
|
|
276
|
+
|
|
|
277
|
+ if (mute == this.localVideo.isMuted())
|
|
|
278
|
+ {
|
|
|
279
|
+ APP.xmpp.sendVideoInfoPresence(mute);
|
|
|
280
|
+ if (callback)
|
|
|
281
|
+ callback(mute);
|
|
|
282
|
+ }
|
|
|
283
|
+ else
|
|
|
284
|
+ {
|
|
|
285
|
+ this.localVideo.setMute(mute);
|
|
|
286
|
+ APP.xmpp.setVideoMute(
|
|
|
287
|
+ mute,
|
|
|
288
|
+ callback,
|
|
|
289
|
+ options);
|
|
|
290
|
+ }
|
|
|
291
|
+};
|
|
|
292
|
+
|
|
|
293
|
+RTC.prototype.setDeviceAvailability = function (devices) {
|
|
|
294
|
+ if(!devices)
|
|
|
295
|
+ return;
|
|
|
296
|
+ if(devices.audio === true || devices.audio === false)
|
|
|
297
|
+ this.devices.audio = devices.audio;
|
|
|
298
|
+ if(devices.video === true || devices.video === false)
|
|
|
299
|
+ this.devices.video = devices.video;
|
|
|
300
|
+ this.eventEmitter.emit(RTCEvents.AVAILABLE_DEVICES_CHANGED, this.devices);
|
|
|
301
|
+};
|
|
|
302
|
+
|
|
275
|
303
|
module.exports = RTC;
|