本地WebRTC信令服务器

时间:2015-12-01 03:05:54

标签: node.js html5 websocket webrtc

我在webRTC网站上使用firebase信令服务器。

我被告知我可以使用websocket来实现我自己的本地信令服务器。

我在Link上尝试了这个例子,但它确实有效。当我更换我的firebase代码时,它无法正常工作。

Firebase代码

var config = {
            openSocket: function(config) {

                var channel = config.channel || location.href.replace(/\/|:|#|%|\.|\[|\]/g, '');
                var socket = new Firebase('https://webrtc.firebaseIO.com/' + channel); //EXTERNAL SERVER need change
                socket.channel = channel;
                socket.on("child_added", function(data) {
                    config.onmessage && config.onmessage(data.val());
                });
                socket.send = function(data) {
                    this.push(data);
                };
                config.onopen && setTimeout(config.onopen, 1);
                socket.onDisconnect().remove();
                return socket;

            },

通过nodejs代码的Websocket

var channelName = location.href.replace(/\/|:|#|%|\.|\[|\]/g, ''); // using URL as room-name

            var SIGNALING_SERVER = 'ws://172.20.34.132:12034';
            connection.openSignalingChannel = function(config) {
                config.channel = config.channel || this.channel;
                var websocket = new WebSocket(SIGNALING_SERVER);
                websocket.channel = config.channel;
                websocket.onopen = function() {
                    websocket.push(JSON.stringify({
                        open: true,
                        channel: config.channel
                    }));
                    if (config.callback)
                        config.callback(websocket);
                };
                websocket.onmessage = function(event) {
                    config.onmessage(JSON.parse(event.data));
                };
                websocket.push = websocket.send;
                websocket.send = function(data) {
                    websocket.push(JSON.stringify({
                        data: data,
                        channel: config.channel
                    }));
                };
            }

0 个答案:

没有答案