为什么XSockets.WebRTC getUserMedia返回unifined?

时间:2014-03-01 13:05:02

标签: webrtc xsockets.net

我正在使用Xsocket和Xsocket WebRTC。

为什么getUserMedia会返回unifined?

这是我的消费品输出:

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>

1 个答案:

答案 0 :(得分:0)

我看起来你正在使用旧版本的XSockets.WebRTC 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>

我的.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>
祝你好运!