WEBRTC - Socket Node.js

Asked

Viewed 73 times

1

I am 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 signage 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 fails to respond. It doesn’t even generate an error in the console. Someone could help me?

1 answer

0

Your mistake is on these lines:

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

In the first line you’re saying that push will be send, on Monday you define send, only that the first thing you do in send is to call push, In doing so you are creating a stack overflow exception (Exception stack overflow), as you have created an infinite recursion situation. When entering the send method, the push method is called, but the push method is the send method, you see ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.