Selaa lähdekoodia

add local media streams to UI

master
isymchych 9 vuotta sitten
vanhempi
commit
0460e7da29
3 muutettua tiedostoa jossa 1068 lisäystä ja 1333 poistoa
  1. 28
    11
      app.js
  2. 1035
    1317
      lib-jitsi-meet.js
  3. 5
    5
      modules/UI/UI.js

+ 28
- 11
app.js Näytä tiedosto

@@ -46,7 +46,7 @@ function buildRoomName () {
46 46
             let word = RoomnameGenerator.generateRoomWithoutSeparator();
47 47
             roomName = word.toLowerCase();
48 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,9 +56,6 @@ function buildRoomName () {
56 56
 
57 57
 const APP = {
58 58
     init () {
59
-        JitsiMeetJS.init();
60
-        JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
61
-
62 59
         let roomName = buildRoomName();
63 60
         this.conference = {
64 61
             roomName,
@@ -158,14 +155,13 @@ function connect() {
158 155
 
159 156
 var ConferenceEvents = JitsiMeetJS.events.conference;
160 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 160
         openSctp: config.openSctp,
164 161
         disableAudioLevels: config.disableAudioLevels
165 162
     });
166 163
 
167 164
     var users = {};
168
-    var localTracks = [];
169 165
 
170 166
     APP.conference.localId = room.myUserId();
171 167
     Object.defineProperty(APP.conference, "membersCount", {
@@ -185,6 +181,15 @@ function initConference(connection, roomName) {
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 193
     room.on(ConferenceEvents.USER_JOINED, function (id) {
189 194
         users[id] = {
190 195
             displayName: undefined,
@@ -308,7 +313,6 @@ function initConference(connection, roomName) {
308 313
         room.setDisplayName(nickname);
309 314
     });
310 315
 
311
-
312 316
     room.on(ConferenceErrors.PASSWORD_REQUIRED, function () {
313 317
         // FIXME handle
314 318
     });
@@ -339,7 +343,7 @@ function initConference(connection, roomName) {
339 343
     }).catch(function (err) {
340 344
         if (err[0] === ConferenceErrors.PASSWORD_REQUIRED) {
341 345
             // FIXME ask for password and try again
342
-            return initConference(connection, roomName);
346
+            return initConference(localTracks, connection);
343 347
         }
344 348
 
345 349
         // FIXME else notify that we cannot conenct to the room
@@ -348,9 +352,22 @@ function initConference(connection, roomName) {
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 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 371
     }).then(function () {
355 372
         APP.UI.start();
356 373
 

+ 1035
- 1317
lib-jitsi-meet.js
File diff suppressed because it is too large
Näytä tiedosto


+ 5
- 5
modules/UI/UI.js Näytä tiedosto

@@ -277,16 +277,16 @@ UI.start = function () {
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 282
     case 'audio':
283
-        VideoLayout.changeLocalAudio(stream, isMuted);
283
+        VideoLayout.changeLocalAudio(track);
284 284
         break;
285 285
     case 'video':
286
-        VideoLayout.changeLocalVideo(stream, isMuted);
286
+        VideoLayout.changeLocalVideo(track);
287 287
         break;
288 288
     default:
289
-        console.error("Unknown stream type: " + stream.type);
289
+        console.error("Unknown stream type: " + track.getType());
290 290
         break;
291 291
     }
292 292
 };

Loading…
Peruuta
Tallenna