WEBRTC - Socket node.js

1

I'm developing an application using the following socket system (Using FireBase) for communication:

openSocket: function(config) {
                var channel = config.channel || location.href.replace( /\/|:|#|%|\.|\[|\]/g , '');
                var socket = new Firebase('https://webrtc.firebaseIO.com/' + channel);

                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;
            }

When I try to create a local signaling server using:

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

                var SIGNALING_SERVER = 'http://localhost: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
                        }));
                    };
                }
            }

The application simply stops responding. It does not even generate any errors on the console. Could someone help me?

    
asked by anonymous 09.01.2017 / 18:56

1 answer

0

Your error is in these lines:

websocket.push = websocket.send;
websocket.send = function(data) {
    websocket.push(JSON.stringify({
        data: data,
        channel: config.channel
    }));
};

On the first line you're saying that push will send , in the second you define send , but the first thing you do in send is to call push , in doing so you are creating a stack overflow exception, since you created an infinite recursion situation. When entering the send method, it is called the push method, but the push method is the send method, do you understand?

    
10.01.2017 / 06:53