Browse Source

add local media streams to UI

j8
isymchych 9 years ago
parent
commit
0460e7da29
3 changed files with 1068 additions and 1333 deletions
  1. 28
    11
      app.js
  2. 1035
    1317
      lib-jitsi-meet.js
  3. 5
    5
      modules/UI/UI.js

+ 28
- 11
app.js View File

46
             let word = RoomnameGenerator.generateRoomWithoutSeparator();
46
             let word = RoomnameGenerator.generateRoomWithoutSeparator();
47
             roomName = word.toLowerCase();
47
             roomName = word.toLowerCase();
48
             window.history.pushState(
48
             window.history.pushState(
49
-                'VideoChat', 'Room: ' + word, window.location.pathname + word
49
+                'VideoChat', `Room: ${word}`, window.location.pathname + word
50
             );
50
             );
51
         }
51
         }
52
     }
52
     }
56
 
56
 
57
 const APP = {
57
 const APP = {
58
     init () {
58
     init () {
59
-        JitsiMeetJS.init();
60
-        JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
61
-
62
         let roomName = buildRoomName();
59
         let roomName = buildRoomName();
63
         this.conference = {
60
         this.conference = {
64
             roomName,
61
             roomName,
158
 
155
 
159
 var ConferenceEvents = JitsiMeetJS.events.conference;
156
 var ConferenceEvents = JitsiMeetJS.events.conference;
160
 var ConferenceErrors = JitsiMeetJS.errors.conference;
157
 var ConferenceErrors = JitsiMeetJS.errors.conference;
161
-function initConference(connection, roomName) {
162
-    var room = connection.initJitsiConference(roomName, {
158
+function initConference(localTracks, connection) {
159
+    var room = connection.initJitsiConference(APP.conference.roomName, {
163
         openSctp: config.openSctp,
160
         openSctp: config.openSctp,
164
         disableAudioLevels: config.disableAudioLevels
161
         disableAudioLevels: config.disableAudioLevels
165
     });
162
     });
166
 
163
 
167
     var users = {};
164
     var users = {};
168
-    var localTracks = [];
169
 
165
 
170
     APP.conference.localId = room.myUserId();
166
     APP.conference.localId = room.myUserId();
171
     Object.defineProperty(APP.conference, "membersCount", {
167
     Object.defineProperty(APP.conference, "membersCount", {
185
         }
181
         }
186
     }
182
     }
187
 
183
 
184
+    // add local streams when joined to the conference
185
+    room.on(ConferenceEvents.CONFERENCE_JOINED, function () {
186
+        localTracks.forEach(function (track) {
187
+            room.addTrack(track);
188
+            APP.UI.addLocalStream(track);
189
+        });
190
+    });
191
+
192
+
188
     room.on(ConferenceEvents.USER_JOINED, function (id) {
193
     room.on(ConferenceEvents.USER_JOINED, function (id) {
189
         users[id] = {
194
         users[id] = {
190
             displayName: undefined,
195
             displayName: undefined,
308
         room.setDisplayName(nickname);
313
         room.setDisplayName(nickname);
309
     });
314
     });
310
 
315
 
311
-
312
     room.on(ConferenceErrors.PASSWORD_REQUIRED, function () {
316
     room.on(ConferenceErrors.PASSWORD_REQUIRED, function () {
313
         // FIXME handle
317
         // FIXME handle
314
     });
318
     });
339
     }).catch(function (err) {
343
     }).catch(function (err) {
340
         if (err[0] === ConferenceErrors.PASSWORD_REQUIRED) {
344
         if (err[0] === ConferenceErrors.PASSWORD_REQUIRED) {
341
             // FIXME ask for password and try again
345
             // FIXME ask for password and try again
342
-            return initConference(connection, roomName);
346
+            return initConference(localTracks, connection);
343
         }
347
         }
344
 
348
 
345
         // FIXME else notify that we cannot conenct to the room
349
         // FIXME else notify that we cannot conenct to the room
348
     });
352
     });
349
 }
353
 }
350
 
354
 
355
+function createLocalTracks () {
356
+    return JitsiMeetJS.createLocalTracks({
357
+        devices: ['audio', 'video']
358
+    }).catch(function (err) {
359
+        console.error('failed to create local tracks', err);
360
+        return [];
361
+    });
362
+}
363
+
351
 function init() {
364
 function init() {
352
-    connect().then(function (connection) {
353
-        return initConference(connection, APP.conference.roomName);
365
+    JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
366
+    JitsiMeetJS.init().then(function () {
367
+        return Promise.all([createLocalTracks(), connect()]);
368
+    }).then(function ([tracks, connection]) {
369
+        console.log('initialized with %s local tracks', tracks.length);
370
+        return initConference(tracks, connection);
354
     }).then(function () {
371
     }).then(function () {
355
         APP.UI.start();
372
         APP.UI.start();
356
 
373
 

+ 1035
- 1317
lib-jitsi-meet.js
File diff suppressed because it is too large
View File


+ 5
- 5
modules/UI/UI.js View File

277
 };
277
 };
278
 
278
 
279
 
279
 
280
-UI.addLocalStream = function (stream, isMuted) {
281
-    switch (stream.type) {
280
+UI.addLocalStream = function (track) {
281
+    switch (track.getType()) {
282
     case 'audio':
282
     case 'audio':
283
-        VideoLayout.changeLocalAudio(stream, isMuted);
283
+        VideoLayout.changeLocalAudio(track);
284
         break;
284
         break;
285
     case 'video':
285
     case 'video':
286
-        VideoLayout.changeLocalVideo(stream, isMuted);
286
+        VideoLayout.changeLocalVideo(track);
287
         break;
287
         break;
288
     default:
288
     default:
289
-        console.error("Unknown stream type: " + stream.type);
289
+        console.error("Unknown stream type: " + track.getType());
290
         break;
290
         break;
291
     }
291
     }
292
 };
292
 };

Loading…
Cancel
Save