瀏覽代碼

Implements create local streams.

dev1
hristoterezov 10 年之前
父節點
當前提交
3416086dc2
共有 7 個文件被更改,包括 1001 次插入526 次删除
  1. 2
    2
      JitsiConference.js
  2. 1
    1
      JitsiMeetJS.js
  3. 901
    426
      lib-jitsi-meet.js
  4. 7
    6
      modules/RTC/LocalStream.js
  5. 11
    10
      modules/RTC/RTC.js
  6. 79
    80
      modules/RTC/RTCUtils.js
  7. 0
    1
      modules/xmpp/JingleSessionPC.js

+ 2
- 2
JitsiConference.js 查看文件

@@ -28,7 +28,7 @@ function JitsiConference(options) {
28 28
  */
29 29
 JitsiConference.prototype.join = function (password) {
30 30
 
31
-    this.room.joinRoom(password);
31
+    this.room.join(password);
32 32
 }
33 33
 
34 34
 /**
@@ -47,7 +47,7 @@ JitsiConference.prototype.leave = function () {
47 47
  *     or a JitsiConferenceError if rejected.
48 48
  */
49 49
 JitsiConference.prototype.createLocalTracks = function (options) {
50
-    this.rtc.obtainAudioAndVideoPermissions();
50
+    return this.rtc.obtainAudioAndVideoPermissions(options || {});
51 51
 }
52 52
 
53 53
 /**

+ 1
- 1
JitsiMeetJS.js 查看文件

@@ -22,6 +22,6 @@ var LibJitsiMeet = {
22 22
 }
23 23
 
24 24
 //Setups the promise object.
25
-require("es6-promise").polyfill();
25
+window.Promise = window.Promise || require("es6-promise").polyfill();
26 26
 
27 27
 module.exports = LibJitsiMeet;

+ 901
- 426
lib-jitsi-meet.js
文件差異過大導致無法顯示
查看文件


+ 7
- 6
modules/RTC/LocalStream.js 查看文件

@@ -20,7 +20,8 @@ function implementOnEndedHandling(stream) {
20 20
     };
21 21
 }
22 22
 
23
-function LocalStream(stream, type, eventEmitter, videoType, isGUMStream) {
23
+function LocalStream(RTC, stream, type, eventEmitter, videoType, isGUMStream) {
24
+    this.rtc = RTC;
24 25
     this.stream = stream;
25 26
     this.eventEmitter = eventEmitter;
26 27
     this.type = type;
@@ -82,16 +83,16 @@ LocalStream.prototype.setMute = function (mute)
82 83
             this.eventEmitter.emit(eventType, true);
83 84
         } else {
84 85
             var self = this;
85
-            APP.RTC.rtcUtils.obtainAudioAndVideoPermissions(
86
-                (this.isAudioStream() ? ["audio"] : ["video"]),
87
-                function (stream) {
86
+            this.rtcUtils.obtainAudioAndVideoPermissions(
87
+                (this.isAudioStream() ? ["audio"] : ["video"]))
88
+                .then(function (stream) {
88 89
                     if (isAudio) {
89
-                        APP.RTC.changeLocalAudio(stream,
90
+                        self.rtc.changeLocalAudio(stream,
90 91
                             function () {
91 92
                                 self.eventEmitter.emit(eventType, false);
92 93
                             });
93 94
                     } else {
94
-                        APP.RTC.changeLocalVideo(stream, false,
95
+                        self.rtc.changeLocalVideo(stream, false,
95 96
                             function () {
96 97
                                 self.eventEmitter.emit(eventType, false);
97 98
                             });

+ 11
- 10
modules/RTC/RTC.js 查看文件

@@ -42,7 +42,7 @@ function getMediaStreamUsage()
42 42
 }
43 43
 
44 44
 
45
-function RTC()
45
+function RTC(options)
46 46
 {
47 47
     this.rtcUtils = null;
48 48
     this.devices = {
@@ -55,6 +55,7 @@ function RTC()
55 55
     this.localVideo = null;
56 56
     this.eventEmitter = new EventEmitter();
57 57
     var self = this;
58
+    this.options = options || {};
58 59
     desktopsharing.addListener(
59 60
         function (stream, isUsingScreenStream, callback) {
60 61
             self.changeLocalVideo(stream, isUsingScreenStream, callback);
@@ -75,9 +76,9 @@ function RTC()
75 76
     }
76 77
 }
77 78
 
78
-RTC.prototype.obtainAudioAndVideoPermissions = function () {
79
-    this.rtcUtils.obtainAudioAndVideoPermissions(
80
-        null, null, getMediaStreamUsage());
79
+RTC.prototype.obtainAudioAndVideoPermissions = function (options) {
80
+    return this.rtcUtils.obtainAudioAndVideoPermissions(
81
+        null, getMediaStreamUsage(), options.resolution);
81 82
 }
82 83
 
83 84
 RTC.prototype.onIncommingCall = function(event) {
@@ -109,14 +110,14 @@ RTC.prototype.removeStreamListener = function (listener, eventType) {
109 110
 
110 111
 RTC.prototype.createLocalStreams = function (streams, change) {
111 112
     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);
113
+        var localStream = new LocalStream(this, streams[i].stream,
114
+            streams[i].type, this.eventEmitter, streams[i].videoType,
115
+            streams[i].isGUMStream);
115 116
         this.localStreams.push(localStream);
116
-        if (streams.isMuted === true)
117
+        if (streams[i].isMuted === true)
117 118
             localStream.setMute(true);
118 119
 
119
-        if (streams.type == "audio") {
120
+        if (streams[i].type == "audio") {
120 121
             this.localAudio = localStream;
121 122
         } else {
122 123
             this.localVideo = localStream;
@@ -125,7 +126,7 @@ RTC.prototype.createLocalStreams = function (streams, change) {
125 126
         if (change)
126 127
             eventType = StreamEventTypes.EVENT_TYPE_LOCAL_CHANGED;
127 128
 
128
-        this.eventEmitter.emit(eventType, localStream, streams.isMuted);
129
+        this.eventEmitter.emit(eventType, localStream, streams[i].isMuted);
129 130
     }
130 131
     return this.localStreams;
131 132
 };

+ 79
- 80
modules/RTC/RTCUtils.js 查看文件

@@ -135,7 +135,7 @@ function getConstraints(um, resolution, bandwidth, fps, desktopStream, isAndroid
135 135
 }
136 136
 
137 137
 //Options parameter is to pass config options. Currently uses only "useIPv6".
138
-function RTCUtils(RTCService, onTemasysPluginReady, options)
138
+function RTCUtils(RTCService, onTemasysPluginReady)
139 139
 {
140 140
     var self = this;
141 141
     this.service = RTCService;
@@ -209,7 +209,7 @@ function RTCUtils(RTCService, onTemasysPluginReady, options)
209 209
         };
210 210
         // DTLS should now be enabled by default but..
211 211
         this.pc_constraints = {'optional': [{'DtlsSrtpKeyAgreement': 'true'}]};
212
-        if (options.useIPv6) {
212
+        if (this.service.options.useIPv6) {
213 213
             // https://code.google.com/p/webrtc/issues/detail?id=2828
214 214
             this.pc_constraints.optional.push({googIPv6: true});
215 215
         }
@@ -340,94 +340,93 @@ RTCUtils.prototype.setAvailableDevices = function (um, available) {
340 340
  * not to ask twice.
341 341
  */
342 342
 RTCUtils.prototype.obtainAudioAndVideoPermissions =
343
-    function(devices, callback, usageOptions)
343
+    function(devices, usageOptions, resolution)
344 344
 {
345 345
     var self = this;
346 346
     // Get AV
347 347
 
348
-    var successCallback = function (stream) {
349
-        if(callback)
350
-            callback(stream, usageOptions);
351
-        else
352
-            self.successCallback(stream, usageOptions);
353
-    };
348
+    return new Promise(function(resolve, reject) {
349
+        var successCallback = function (stream) {
350
+            resolve(self.successCallback(stream, usageOptions));
351
+        };
354 352
 
355
-    if(!devices)
356
-        devices = ['audio', 'video'];
353
+        if (!devices)
354
+            devices = ['audio', 'video'];
357 355
 
358
-    var newDevices = [];
356
+        var newDevices = [];
359 357
 
360 358
 
361
-    if(usageOptions)
362
-        for(var i = 0; i < devices.length; i++) {
363
-            var device = devices[i];
364
-            if(usageOptions[device] === true)
365
-                newDevices.push(device);
366
-        }
367
-    else
368
-        newDevices = devices;
359
+        if (usageOptions)
360
+            for (var i = 0; i < devices.length; i++) {
361
+                var device = devices[i];
362
+                if (usageOptions[device] === true)
363
+                    newDevices.push(device);
364
+            }
365
+        else
366
+            newDevices = devices;
369 367
 
370
-    if(newDevices.length === 0) {
371
-        successCallback();
372
-        return;
373
-    }
368
+        if (newDevices.length === 0) {
369
+            successCallback();
370
+            return;
371
+        }
374 372
 
375
-    if (RTCBrowserType.isFirefox() || RTCBrowserType.isTemasysPluginUsed()) {
376
-
377
-        // With FF/IE we can't split the stream into audio and video because FF
378
-        // doesn't support media stream constructors. So, we need to get the
379
-        // audio stream separately from the video stream using two distinct GUM
380
-        // calls. Not very user friendly :-( but we don't have many other
381
-        // options neither.
382
-        //
383
-        // Note that we pack those 2 streams in a single object and pass it to
384
-        // the successCallback method.
385
-        var obtainVideo = function (audioStream) {
386
-            self.getUserMediaWithConstraints(
387
-                ['video'],
388
-                function (videoStream) {
389
-                    return successCallback({
390
-                        audioStream: audioStream,
391
-                        videoStream: videoStream
392
-                    });
373
+        if (RTCBrowserType.isFirefox() || RTCBrowserType.isTemasysPluginUsed()) {
374
+
375
+            // With FF/IE we can't split the stream into audio and video because FF
376
+            // doesn't support media stream constructors. So, we need to get the
377
+            // audio stream separately from the video stream using two distinct GUM
378
+            // calls. Not very user friendly :-( but we don't have many other
379
+            // options neither.
380
+            //
381
+            // Note that we pack those 2 streams in a single object and pass it to
382
+            // the successCallback method.
383
+            var obtainVideo = function (audioStream) {
384
+                self.getUserMediaWithConstraints(
385
+                    ['video'],
386
+                    function (videoStream) {
387
+                        return successCallback({
388
+                            audioStream: audioStream,
389
+                            videoStream: videoStream
390
+                        });
391
+                    },
392
+                    function (error) {
393
+                        console.error(
394
+                            'failed to obtain video stream - stop', error);
395
+                        self.errorCallback(error, resolve);
396
+                    },
397
+                        config.resolution || '360');
398
+            };
399
+            var obtainAudio = function () {
400
+                self.getUserMediaWithConstraints(
401
+                    ['audio'],
402
+                    function (audioStream) {
403
+                        if (newDevices.indexOf('video') !== -1)
404
+                            obtainVideo(audioStream);
405
+                    },
406
+                    function (error) {
407
+                        console.error(
408
+                            'failed to obtain audio stream - stop', error);
409
+                        self.errorCallback(error, resolve);
410
+                    }
411
+                );
412
+            };
413
+            if (newDevices.indexOf('audio') !== -1) {
414
+                obtainAudio();
415
+            } else {
416
+                obtainVideo(null);
417
+            }
418
+        } else {
419
+            this.getUserMediaWithConstraints(
420
+                newDevices,
421
+                function (stream) {
422
+                    successCallback(stream);
393 423
                 },
394 424
                 function (error) {
395
-                    console.error(
396
-                        'failed to obtain video stream - stop', error);
397
-                    self.errorCallback(error);
398
-                },
399
-                config.resolution || '360');
400
-        };
401
-        var obtainAudio = function () {
402
-            self.getUserMediaWithConstraints(
403
-                ['audio'],
404
-                function (audioStream) {
405
-                    if (newDevices.indexOf('video') !== -1)
406
-                        obtainVideo(audioStream);
425
+                    self.errorCallback(error, resolve);
407 426
                 },
408
-                function (error) {
409
-                    console.error(
410
-                        'failed to obtain audio stream - stop', error);
411
-                    self.errorCallback(error);
412
-                }
413
-            );
414
-        };
415
-        if (newDevices.indexOf('audio') !== -1) {
416
-            obtainAudio();
417
-        } else {
418
-            obtainVideo(null);
427
+                resolution || '360');
419 428
         }
420
-    } else {
421
-        this.getUserMediaWithConstraints(
422
-        newDevices,
423
-        function (stream) {
424
-            successCallback(stream);
425
-        },
426
-        function (error) {
427
-            self.errorCallback(error);
428
-        },
429
-        config.resolution || '360');
430
-    }
429
+    }.bind(this));
431 430
 };
432 431
 
433 432
 RTCUtils.prototype.successCallback = function (stream, usageOptions) {
@@ -439,7 +438,7 @@ RTCUtils.prototype.successCallback = function (stream, usageOptions) {
439 438
     return this.handleLocalStream(stream, usageOptions);
440 439
 };
441 440
 
442
-RTCUtils.prototype.errorCallback = function (error) {
441
+RTCUtils.prototype.errorCallback = function (error, resolve) {
443 442
     var self = this;
444 443
     console.error('failed to obtain audio/video stream - trying audio only', error);
445 444
     var resolution = getPreviousResolution(currentResolution);
@@ -452,7 +451,7 @@ RTCUtils.prototype.errorCallback = function (error) {
452 451
     {
453 452
         self.getUserMediaWithConstraints(['audio', 'video'],
454 453
             function (stream) {
455
-                return self.successCallback(stream);
454
+                resolve(self.successCallback(stream));
456 455
             }, function (error) {
457 456
                 return self.errorCallback(error);
458 457
             }, resolution);
@@ -461,12 +460,12 @@ RTCUtils.prototype.errorCallback = function (error) {
461 460
         self.getUserMediaWithConstraints(
462 461
             ['audio'],
463 462
             function (stream) {
464
-                return self.successCallback(stream);
463
+                resolve(self.successCallback(stream));
465 464
             },
466 465
             function (error) {
467 466
                 console.error('failed to obtain audio/video stream - stop',
468 467
                     error);
469
-                return self.successCallback(null);
468
+                resolve(self.successCallback(null));
470 469
             }
471 470
         );
472 471
     }

+ 0
- 1
modules/xmpp/JingleSessionPC.js 查看文件

@@ -9,7 +9,6 @@ var transform = require("sdp-transform");
9 9
 var XMPPEvents = require("../../service/xmpp/XMPPEvents");
10 10
 var RTCBrowserType = require("../RTC/RTCBrowserType");
11 11
 var SSRCReplacement = require("./LocalSSRCReplacement");
12
-var RTC = require("../RTC/RTC");
13 12
 
14 13
 // Jingle stuff
15 14
 function JingleSessionPC(me, sid, connection, service, eventEmitter) {

Loading…
取消
儲存