|
|
@@ -3,7 +3,6 @@
|
|
3
|
3
|
var logger = require("jitsi-meet-logger").getLogger(__filename);
|
|
4
|
4
|
var RTC = require("./modules/RTC/RTC");
|
|
5
|
5
|
var XMPPEvents = require("./service/xmpp/XMPPEvents");
|
|
6
|
|
-var StreamEventTypes = require("./service/RTC/StreamEventTypes");
|
|
7
|
6
|
var RTCEvents = require("./service/RTC/RTCEvents");
|
|
8
|
7
|
var EventEmitter = require("events");
|
|
9
|
8
|
var JitsiConferenceEvents = require("./JitsiConferenceEvents");
|
|
|
@@ -11,6 +10,7 @@ var JitsiConferenceErrors = require("./JitsiConferenceErrors");
|
|
11
|
10
|
var JitsiParticipant = require("./JitsiParticipant");
|
|
12
|
11
|
var Statistics = require("./modules/statistics/statistics");
|
|
13
|
12
|
var JitsiDTMFManager = require('./modules/DTMF/JitsiDTMFManager');
|
|
|
13
|
+var JitsiTrackEvents = require("./JitsiTrackEvents");
|
|
14
|
14
|
|
|
15
|
15
|
/**
|
|
16
|
16
|
* Creates a JitsiConference object with the given name and properties.
|
|
|
@@ -34,7 +34,7 @@ function JitsiConference(options) {
|
|
34
|
34
|
this.room = this.xmpp.createRoom(this.options.name, null, null, this.options.config);
|
|
35
|
35
|
this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
|
|
36
|
36
|
this.rtc = new RTC(this.room, options);
|
|
37
|
|
- if(!options.config.disableAudioLevels)
|
|
|
37
|
+ if(!RTC.options.disableAudioLevels)
|
|
38
|
38
|
this.statistics = new Statistics();
|
|
39
|
39
|
setupListeners(this);
|
|
40
|
40
|
this.participants = {};
|
|
|
@@ -103,7 +103,8 @@ JitsiConference.prototype.addEventListener = JitsiConference.prototype.on;
|
|
103
|
103
|
JitsiConference.prototype.removeEventListener = JitsiConference.prototype.off;
|
|
104
|
104
|
|
|
105
|
105
|
/**
|
|
106
|
|
- * Receives notifications from another participants for commands / custom events(send by sendPresenceCommand method).
|
|
|
106
|
+ * Receives notifications from another participants for commands / custom events
|
|
|
107
|
+ * (send by sendPresenceCommand method).
|
|
107
|
108
|
* @param command {String} the name of the command
|
|
108
|
109
|
* @param handler {Function} handler for the command
|
|
109
|
110
|
*/
|
|
|
@@ -169,11 +170,7 @@ JitsiConference.prototype.removeCommand = function (name) {
|
|
169
|
170
|
*/
|
|
170
|
171
|
JitsiConference.prototype.setDisplayName = function(name) {
|
|
171
|
172
|
if(this.room){
|
|
172
|
|
- this.room.addToPresence("nick", {
|
|
173
|
|
- attributes: {
|
|
174
|
|
- xmlns: 'http://jabber.org/protocol/nick'
|
|
175
|
|
- }, value: name
|
|
176
|
|
- });
|
|
|
173
|
+ this.room.addToPresence("nick", {attributes: {xmlns: 'http://jabber.org/protocol/nick'}, value: name});
|
|
177
|
174
|
this.room.sendPresence();
|
|
178
|
175
|
}
|
|
179
|
176
|
};
|
|
|
@@ -183,8 +180,42 @@ JitsiConference.prototype.setDisplayName = function(name) {
|
|
183
|
180
|
* @param track the JitsiLocalTrack object.
|
|
184
|
181
|
*/
|
|
185
|
182
|
JitsiConference.prototype.addTrack = function (track) {
|
|
186
|
|
- this.rtc.addLocalStream(track);
|
|
187
|
|
- this.room.addStream(track.getOriginalStream(), function () {});
|
|
|
183
|
+ this.room.addStream(track.getOriginalStream(), function () {
|
|
|
184
|
+ this.rtc.addLocalStream(track);
|
|
|
185
|
+ var muteHandler = this._fireMuteChangeEvent.bind(this, track);
|
|
|
186
|
+ var stopHandler = this.removeTrack.bind(this, track);
|
|
|
187
|
+ var audioLevelHandler = this._fireAudioLevelChangeEvent.bind(this);
|
|
|
188
|
+ track.addEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED, muteHandler);
|
|
|
189
|
+ track.addEventListener(JitsiTrackEvents.TRACK_STOPPED, stopHandler);
|
|
|
190
|
+ track.addEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, audioLevelHandler);
|
|
|
191
|
+ this.addEventListener(JitsiConferenceEvents.TRACK_REMOVED, function (someTrack) {
|
|
|
192
|
+ if (someTrack !== track) {
|
|
|
193
|
+ return;
|
|
|
194
|
+ }
|
|
|
195
|
+ track.removeEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED, muteHandler);
|
|
|
196
|
+ track.removeEventListener(JitsiTrackEvents.TRACK_STOPPED, stopHandler);
|
|
|
197
|
+ track.removeEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, audioLevelHandler);
|
|
|
198
|
+ });
|
|
|
199
|
+ this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
|
|
|
200
|
+ }.bind(this));
|
|
|
201
|
+};
|
|
|
202
|
+
|
|
|
203
|
+/**
|
|
|
204
|
+ * Fires TRACK_AUDIO_LEVEL_CHANGED change conference event.
|
|
|
205
|
+ * @param audioLevel the audio level
|
|
|
206
|
+ */
|
|
|
207
|
+JitsiConference.prototype._fireAudioLevelChangeEvent = function (audioLevel) {
|
|
|
208
|
+ this.eventEmitter.emit(
|
|
|
209
|
+ JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
|
|
|
210
|
+ this.myUserId(), audioLevel);
|
|
|
211
|
+};
|
|
|
212
|
+
|
|
|
213
|
+/**
|
|
|
214
|
+ * Fires TRACK_MUTE_CHANGED change conference event.
|
|
|
215
|
+ * @param track the JitsiTrack object related to the event.
|
|
|
216
|
+ */
|
|
|
217
|
+JitsiConference.prototype._fireMuteChangeEvent = function (track) {
|
|
|
218
|
+ this.eventEmitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
|
|
188
|
219
|
};
|
|
189
|
220
|
|
|
190
|
221
|
/**
|
|
|
@@ -192,8 +223,10 @@ JitsiConference.prototype.addTrack = function (track) {
|
|
192
|
223
|
* @param track the JitsiLocalTrack object.
|
|
193
|
224
|
*/
|
|
194
|
225
|
JitsiConference.prototype.removeTrack = function (track) {
|
|
195
|
|
- this.room.removeStream(track.getOriginalStream());
|
|
196
|
|
- this.rtc.removeLocalStream(track);
|
|
|
226
|
+ this.room.removeStream(track.getOriginalStream(), function(){
|
|
|
227
|
+ this.rtc.removeLocalStream(track);
|
|
|
228
|
+ this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
|
|
|
229
|
+ }.bind(this));
|
|
197
|
230
|
};
|
|
198
|
231
|
|
|
199
|
232
|
/**
|
|
|
@@ -325,22 +358,41 @@ JitsiConference.prototype.onDisplayNameChanged = function (jid, displayName) {
|
|
325
|
358
|
this.eventEmitter.emit(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, id, displayName);
|
|
326
|
359
|
};
|
|
327
|
360
|
|
|
328
|
|
-
|
|
329
|
361
|
JitsiConference.prototype.onTrackAdded = function (track) {
|
|
330
|
362
|
var id = track.getParticipantId();
|
|
331
|
363
|
var participant = this.getParticipantById(id);
|
|
|
364
|
+ if (!participant) {
|
|
|
365
|
+ return;
|
|
|
366
|
+ }
|
|
|
367
|
+ // add track to JitsiParticipant
|
|
332
|
368
|
participant._tracks.push(track);
|
|
333
|
|
- this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
|
|
334
|
|
-};
|
|
335
|
369
|
|
|
336
|
|
-JitsiConference.prototype.onTrackRemoved = function (track) {
|
|
337
|
|
- var id = track.getParticipantId();
|
|
338
|
|
- var participant = this.getParticipantById(id);
|
|
339
|
|
- var pos = participant._tracks.indexOf(track);
|
|
340
|
|
- if (pos > -1) {
|
|
341
|
|
- participant._tracks.splice(pos, 1);
|
|
342
|
|
- }
|
|
343
|
|
- this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
|
|
|
370
|
+ var emitter = this.eventEmitter;
|
|
|
371
|
+ track.addEventListener(
|
|
|
372
|
+ JitsiTrackEvents.TRACK_STOPPED,
|
|
|
373
|
+ function () {
|
|
|
374
|
+ // remove track from JitsiParticipant
|
|
|
375
|
+ var pos = participant._tracks.indexOf(track);
|
|
|
376
|
+ if (pos > -1) {
|
|
|
377
|
+ participant._tracks.splice(pos, 1);
|
|
|
378
|
+ }
|
|
|
379
|
+ emitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
|
|
|
380
|
+ }
|
|
|
381
|
+ );
|
|
|
382
|
+ track.addEventListener(
|
|
|
383
|
+ JitsiTrackEvents.TRACK_MUTE_CHANGED,
|
|
|
384
|
+ function () {
|
|
|
385
|
+ emitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
|
|
|
386
|
+ }
|
|
|
387
|
+ );
|
|
|
388
|
+ track.addEventListener(
|
|
|
389
|
+ JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
|
|
|
390
|
+ function (audioLevel) {
|
|
|
391
|
+ emitter.emit(JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, id, audioLevel);
|
|
|
392
|
+ }
|
|
|
393
|
+ );
|
|
|
394
|
+
|
|
|
395
|
+ this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
|
|
344
|
396
|
};
|
|
345
|
397
|
|
|
346
|
398
|
JitsiConference.prototype.updateDTMFSupport = function () {
|
|
|
@@ -408,8 +460,15 @@ function setupListeners(conference) {
|
|
408
|
460
|
if(conference.statistics)
|
|
409
|
461
|
conference.statistics.startRemoteStats(event.peerconnection);
|
|
410
|
462
|
});
|
|
|
463
|
+
|
|
411
|
464
|
conference.room.addListener(XMPPEvents.REMOTE_STREAM_RECEIVED,
|
|
412
|
|
- conference.rtc.createRemoteStream.bind(conference.rtc));
|
|
|
465
|
+ function (data, sid, thessrc) {
|
|
|
466
|
+ var track = conference.rtc.createRemoteStream(data, sid, thessrc);
|
|
|
467
|
+ if (track) {
|
|
|
468
|
+ conference.onTrackAdded(track);
|
|
|
469
|
+ }
|
|
|
470
|
+ }
|
|
|
471
|
+ );
|
|
413
|
472
|
|
|
414
|
473
|
conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
|
|
415
|
474
|
conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
|
|
|
@@ -440,22 +499,9 @@ function setupListeners(conference) {
|
|
440
|
499
|
conference.eventEmitter.emit(JitsiConferenceEvents.SETUP_FAILED);
|
|
441
|
500
|
});
|
|
442
|
501
|
|
|
443
|
|
- conference.rtc.addListener(
|
|
444
|
|
- StreamEventTypes.EVENT_TYPE_REMOTE_CREATED, conference.onTrackAdded.bind(conference)
|
|
445
|
|
- );
|
|
446
|
|
-
|
|
447
|
|
-//FIXME: Maybe remove event should not be associated with the conference.
|
|
448
|
|
- conference.rtc.addListener(
|
|
449
|
|
- StreamEventTypes.EVENT_TYPE_REMOTE_ENDED, conference.onTrackRemoved.bind(conference)
|
|
450
|
|
- );
|
|
451
|
|
-//FIXME: Maybe remove event should not be associated with the conference.
|
|
452
|
|
- conference.rtc.addListener(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, function (stream) {
|
|
453
|
|
- conference.removeTrack(stream);
|
|
454
|
|
- conference.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, stream);
|
|
455
|
|
- });
|
|
456
|
|
-
|
|
457
|
|
- conference.rtc.addListener(StreamEventTypes.TRACK_MUTE_CHANGED, function (track) {
|
|
458
|
|
- conference.eventEmitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
|
|
|
502
|
+ conference.room.addListener(XMPPEvents.MESSAGE_RECEIVED, function (jid, displayName, txt, myJid, ts) {
|
|
|
503
|
+ var id = Strophe.getResourceFromJid(jid);
|
|
|
504
|
+ conference.eventEmitter.emit(JitsiConferenceEvents.MESSAGE_RECEIVED, id, txt, ts);
|
|
459
|
505
|
});
|
|
460
|
506
|
|
|
461
|
507
|
conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (id) {
|
|
|
@@ -482,20 +528,11 @@ function setupListeners(conference) {
|
|
482
|
528
|
//FIXME: Maybe remove event should not be associated with the conference.
|
|
483
|
529
|
conference.statistics.addAudioLevelListener(function (ssrc, level) {
|
|
484
|
530
|
var userId = null;
|
|
485
|
|
- if (ssrc === Statistics.LOCAL_JID) {
|
|
486
|
|
- userId = conference.myUserId();
|
|
487
|
|
- } else {
|
|
488
|
|
- var jid = conference.room.getJidBySSRC(ssrc);
|
|
489
|
|
- if (!jid)
|
|
490
|
|
- return;
|
|
491
|
|
-
|
|
492
|
|
- userId = Strophe.getResourceFromJid(jid);
|
|
493
|
|
- }
|
|
494
|
|
- conference.eventEmitter.emit(JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
|
|
495
|
|
- userId, level);
|
|
496
|
|
- });
|
|
497
|
|
- conference.rtc.addListener(StreamEventTypes.EVENT_TYPE_LOCAL_CREATED, function (stream) {
|
|
498
|
|
- conference.statistics.startLocalStats(stream);
|
|
|
531
|
+ var jid = conference.room.getJidBySSRC(ssrc);
|
|
|
532
|
+ if (!jid)
|
|
|
533
|
+ return;
|
|
|
534
|
+
|
|
|
535
|
+ conference.rtc.setAudioLevel(jid, level);
|
|
499
|
536
|
});
|
|
500
|
537
|
conference.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE,
|
|
501
|
538
|
function () {
|