Ver código fonte

propagate MESSAGE_RECEIVED event

master
isymchych 10 anos atrás
pai
commit
91ad76ec52
3 arquivos alterados com 97 adições e 55 exclusões
  1. 91
    54
      JitsiConference.js
  2. 1
    1
      doc/API.md
  3. 5
    0
      lib-jitsi-meet.js

+ 91
- 54
JitsiConference.js Ver arquivo

3
 var logger = require("jitsi-meet-logger").getLogger(__filename);
3
 var logger = require("jitsi-meet-logger").getLogger(__filename);
4
 var RTC = require("./modules/RTC/RTC");
4
 var RTC = require("./modules/RTC/RTC");
5
 var XMPPEvents = require("./service/xmpp/XMPPEvents");
5
 var XMPPEvents = require("./service/xmpp/XMPPEvents");
6
-var StreamEventTypes = require("./service/RTC/StreamEventTypes");
7
 var RTCEvents = require("./service/RTC/RTCEvents");
6
 var RTCEvents = require("./service/RTC/RTCEvents");
8
 var EventEmitter = require("events");
7
 var EventEmitter = require("events");
9
 var JitsiConferenceEvents = require("./JitsiConferenceEvents");
8
 var JitsiConferenceEvents = require("./JitsiConferenceEvents");
11
 var JitsiParticipant = require("./JitsiParticipant");
10
 var JitsiParticipant = require("./JitsiParticipant");
12
 var Statistics = require("./modules/statistics/statistics");
11
 var Statistics = require("./modules/statistics/statistics");
13
 var JitsiDTMFManager = require('./modules/DTMF/JitsiDTMFManager');
12
 var JitsiDTMFManager = require('./modules/DTMF/JitsiDTMFManager');
13
+var JitsiTrackEvents = require("./JitsiTrackEvents");
14
 
14
 
15
 /**
15
 /**
16
  * Creates a JitsiConference object with the given name and properties.
16
  * Creates a JitsiConference object with the given name and properties.
34
     this.room = this.xmpp.createRoom(this.options.name, null, null, this.options.config);
34
     this.room = this.xmpp.createRoom(this.options.name, null, null, this.options.config);
35
     this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
35
     this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
36
     this.rtc = new RTC(this.room, options);
36
     this.rtc = new RTC(this.room, options);
37
-    if(!options.config.disableAudioLevels)
37
+    if(!RTC.options.disableAudioLevels)
38
         this.statistics = new Statistics();
38
         this.statistics = new Statistics();
39
     setupListeners(this);
39
     setupListeners(this);
40
     this.participants = {};
40
     this.participants = {};
103
 JitsiConference.prototype.removeEventListener = JitsiConference.prototype.off;
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
  * @param command {String} the name of the command
108
  * @param command {String} the name of the command
108
  * @param handler {Function} handler for the command
109
  * @param handler {Function} handler for the command
109
  */
110
  */
169
  */
170
  */
170
 JitsiConference.prototype.setDisplayName = function(name) {
171
 JitsiConference.prototype.setDisplayName = function(name) {
171
     if(this.room){
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
         this.room.sendPresence();
174
         this.room.sendPresence();
178
     }
175
     }
179
 };
176
 };
183
  * @param track the JitsiLocalTrack object.
180
  * @param track the JitsiLocalTrack object.
184
  */
181
  */
185
 JitsiConference.prototype.addTrack = function (track) {
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
  * @param track the JitsiLocalTrack object.
223
  * @param track the JitsiLocalTrack object.
193
  */
224
  */
194
 JitsiConference.prototype.removeTrack = function (track) {
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
     this.eventEmitter.emit(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, id, displayName);
358
     this.eventEmitter.emit(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, id, displayName);
326
 };
359
 };
327
 
360
 
328
-
329
 JitsiConference.prototype.onTrackAdded = function (track) {
361
 JitsiConference.prototype.onTrackAdded = function (track) {
330
     var id = track.getParticipantId();
362
     var id = track.getParticipantId();
331
     var participant = this.getParticipantById(id);
363
     var participant = this.getParticipantById(id);
364
+    if (!participant) {
365
+        return;
366
+    }
367
+    // add track to JitsiParticipant
332
     participant._tracks.push(track);
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
 JitsiConference.prototype.updateDTMFSupport = function () {
398
 JitsiConference.prototype.updateDTMFSupport = function () {
408
         if(conference.statistics)
460
         if(conference.statistics)
409
             conference.statistics.startRemoteStats(event.peerconnection);
461
             conference.statistics.startRemoteStats(event.peerconnection);
410
     });
462
     });
463
+
411
     conference.room.addListener(XMPPEvents.REMOTE_STREAM_RECEIVED,
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
     conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
473
     conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
415
         conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
474
         conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
440
         conference.eventEmitter.emit(JitsiConferenceEvents.SETUP_FAILED);
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
     conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (id) {
507
     conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (id) {
482
         //FIXME: Maybe remove event should not be associated with the conference.
528
         //FIXME: Maybe remove event should not be associated with the conference.
483
         conference.statistics.addAudioLevelListener(function (ssrc, level) {
529
         conference.statistics.addAudioLevelListener(function (ssrc, level) {
484
             var userId = null;
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
         conference.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE,
537
         conference.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE,
501
             function () {
538
             function () {

+ 1
- 1
doc/API.md Ver arquivo

71
         - ACTIVE_SPEAKER_CHANGED - the active speaker is changed. (parameters - id(string))
71
         - ACTIVE_SPEAKER_CHANGED - the active speaker is changed. (parameters - id(string))
72
         - USER_JOINED - new user joined a conference. (parameters - id(string), user(JitsiParticipant))
72
         - USER_JOINED - new user joined a conference. (parameters - id(string), user(JitsiParticipant))
73
         - USER_LEFT - a participant left conference. (parameters - id(string), user(JitsiParticipant))
73
         - USER_LEFT - a participant left conference. (parameters - id(string), user(JitsiParticipant))
74
-        - MESSAGE_RECEIVED - new text message received. (parameters - id(string), text(string))
74
+        - MESSAGE_RECEIVED - new text message received. (parameters - id(string), text(string), ts(number))
75
         - DISPLAY_NAME_CHANGED - user has changed his display name. (parameters - id(string), displayName(string))
75
         - DISPLAY_NAME_CHANGED - user has changed his display name. (parameters - id(string), displayName(string))
76
         - LAST_N_ENDPOINTS_CHANGED - last n set was changed (parameters - array of ids of users)
76
         - LAST_N_ENDPOINTS_CHANGED - last n set was changed (parameters - array of ids of users)
77
         - IN_LAST_N_CHANGED - passes boolean property that shows whether the local user is included in last n set of any other user or not. (parameters - boolean)
77
         - IN_LAST_N_CHANGED - passes boolean property that shows whether the local user is included in last n set of any other user or not. (parameters - boolean)

+ 5
- 0
lib-jitsi-meet.js Ver arquivo

501
         conference.eventEmitter.emit(JitsiConferenceEvents.SETUP_FAILED);
501
         conference.eventEmitter.emit(JitsiConferenceEvents.SETUP_FAILED);
502
     });
502
     });
503
 
503
 
504
+    conference.room.addListener(XMPPEvents.MESSAGE_RECEIVED, function (jid, displayName, txt, myJid, ts) {
505
+        var id = Strophe.getResourceFromJid(jid);
506
+        conference.eventEmitter.emit(JitsiConferenceEvents.MESSAGE_RECEIVED, id, txt, ts);
507
+    });
508
+
504
     conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (id) {
509
     conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (id) {
505
         if(conference.lastActiveSpeaker !== id && conference.room) {
510
         if(conference.lastActiveSpeaker !== id && conference.room) {
506
             conference.lastActiveSpeaker = id;
511
             conference.lastActiveSpeaker = id;

Carregando…
Cancelar
Salvar