2014-03-01 94 views
1

我正在使用Xsocket和Xsocket WebRTC。爲什麼XSockets.WebRTC getUserMedia返回未定義?

爲什麼getUserMedia返回未定義?

這裏是我的consule輸出:

This appears to be Chrome 

This appears to be Chrome 

XSockets.WebRTC.latest.js:98 

Connection 
Object 
ClientGuid: "80e0b08757ef429ea1e87c83e75295f5" 
StorageGuid: "893c286b06f443c5b97f19c701fcde13" 
clientType: "RFC6455" 
__proto__: Object 
default.html:18 

event.returnValue is deprecated. Please use the standard event.preventDefault() instead. 

MediaStream添加到PeerConnection等不確定

**Here is my full code:** 

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <script src="Scripts/jquery-1.9.0.js"></script> 
    <script src="Scripts/XSockets.latest.js"></script> 
    <script src="Scripts/adapter.js"></script> 
    <script src="Scripts/XSockets.WebRTC.latest.js"></script> 

    <script> 
     var conn = undefined; 
     var webRTC = undefined; 

     $(function() { 
      ws = new XSockets.WebSocket('ws://127.0.0.1:4502/Generic'); 


      ws.subscribe(XSockets.Events.open, function (conn) { 
       console.log("Connection", conn) 
      }); 

      webRTC = new XSockets.WebRTC(ws, { 
       onContextCreated: function (ctx) { 
        console.log("ctx", ctx); 
       }, 
       onContextChange: function (changes) { 

       }, 
       onLocalStream: function (stream) { 
        console.log("stream", stream); 
        attachMediaStream(document.querySelector("#localVideo"), stream); 
       }, 
       onRemoteStream: function (stream) { 
        console.log("stream", stream); 
        attachMediaStream(document.querySelector("#remoteVideo"), stream); 
       } 
      }); 



      $('#button-start').on('click', function() { 
       webRTC.getUserMedia({audio: true, video: true}, function (result) { 
        console.log("MediaStream is added to the PeerConnection" , result); 
       }); 
      }); 


     }); 

    </script> 
    <title></title> 
</head> 
<body> 
    <button id="button-start">Start</button> 

    <video id="localVideo" autoplay /> 

    <video id="remoteVideo" autoplay /> 
</body> 
</html> 

回答

0

我看起來像你正在使用的XSockets.WebRTC的舊版本drprecated API,我會盡力在這裏爲您發佈一個快速解決方案。我建議你看看Git的這個回購; https://github.com/XSockets/WebRTC

在您提供的代碼中,您應該將XSockets.WebRTC()的init移動到代理的公開回調中;我也不知道你使用的是/ Generic,不會工作,要使用的控制器是「Broker」,如下所示。

var ws, rtc; 
    var myCtx = "1265343559964af892b7ba86205e5927"; 

    $(function() { 
     ws = new XSockets.WebSocket("ws://127.0.0.1:4502/Broker"); 
     ws.onopen = function(c) { 

      rtc = new XSockets.WebRTC(ws);     

      rtc.onpeerconnectioncreated = function(peer) { 
       console.log("created a peer", peer); 

      }; 

      rtc.onpeerconnectionlost = function(peer) { 
       console.log("lost a peer", peer); 

      }; 


      rtc.oncontextcreated = function(ctx) { 
       console.log("ctx", ctx); 
      }; 
      rtc.onlocalstream = function(stream) { 
       attachMediaStream(document.querySelector("#myvideo"), stream); 
      }; 

      rtc.getUserMedia(rtc.userMediaConstraints.qvga(false), function() { 
       console.log("Yeah, Video"); 

       // Lets use a static context i.e 
       rtc.changeContext(myCtx); 

      }); 

      rtc.onremotestream = function(event) { 
       var v = $("<video>").attr("autoplay", "autoplay").appendTo("div"); 
       attachMediaStream($(v).get(0), event.stream); 
      }; 
     }; 

    }); 
</script> 

Futher我的.html頁面上包含以下HTML

<body> 
    <div></div> 
    <video id="myvideo" autoplay></video> 
</body> 

還要確保您有

<script src="Scripts/jquery-2.1.0.min.js"></script> 
<script src="Scripts/XSockets.latest.js"></script> 
<script src="Scripts/XSockets.WebRTC.latest.js"></script> 

祝你好運!