Browse Source

Support React Native's MediaStream and its id

The react-native-webrtc implementation that we use on React Native (at
the time of this writing) provides a MediaStream (class) which:

- has no standard constructors but rather has a non-standard
constructor which requires a single argument that represents the id of
the MediaStream instance to initialize, and

- has an id value of type number rather than the standard string.
master
Lyubomir Marinov 9 years ago
parent
commit
3c3e77a607
1 changed files with 23 additions and 5 deletions
  1. 23
    5
      modules/RTC/RTCUtils.js

+ 23
- 5
modules/RTC/RTCUtils.js View File

@@ -673,9 +673,20 @@ var RTCUtils = {
673 673
                     return element;
674 674
                 });
675 675
                 this.getStreamID = function (stream) {
676
-                    // Streams from FF endpoints have the characters '{' and '}'
677
-                    // that make jQuery choke.
678
-                    return SDPUtil.filter_special_chars(stream.id);
676
+                    // A. MediaStreams from FF endpoints have the characters '{'
677
+                    // and '}' that make jQuery choke.
678
+                    // B. The react-native-webrtc implementation that we use on
679
+                    // React Native at the time of this writing returns a number
680
+                    // for the id of MediaStream. Let's just say that a number
681
+                    // contains no special characters.
682
+                    var id = stream.id;
683
+                    // XXX The return statement is affected by automatic
684
+                    // semicolon insertion (ASI). No line terminator is allowed
685
+                    // between the return keyword and the expression.
686
+                    return (
687
+                        (typeof id === 'number')
688
+                            ? id
689
+                            : SDPUtil.filter_special_chars(id));
679 690
                 };
680 691
                 this.getVideoSrc = function (element) {
681 692
                     return element ? element.getAttribute("src") : null;
@@ -852,8 +863,15 @@ var RTCUtils = {
852 863
                 && options.devices.indexOf("desktop") !== -1){
853 864
                 reject(new Error("Desktop sharing is not supported!"));
854 865
             }
855
-            if (RTCBrowserType.isFirefox() ||
856
-                RTCBrowserType.isTemasysPluginUsed()) {
866
+            if (RTCBrowserType.isFirefox()
867
+                    // XXX The react-native-webrtc implementation that we
868
+                    // utilize on React Native at the time of this writing does
869
+                    // not support the MediaStream constructors defined by
870
+                    // https://www.w3.org/TR/mediacapture-streams/#constructors
871
+                    // and instead has a single constructor which expects (an
872
+                    // NSNumber as) a MediaStream ID.
873
+                    || RTCBrowserType.isReactNative()
874
+                    || RTCBrowserType.isTemasysPluginUsed()) {
857 875
                 var GUM = function (device, s, e) {
858 876
                     this.getUserMediaWithConstraints(device, s, e, options);
859 877
                 };

Loading…
Cancel
Save