mustang2247 / jquery-websocket

Automatically exported from code.google.com/p/jquery-websocket
0 stars 0 forks source link

The onopen is never fired. #2

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
I simply do the following command on a ws server:

var ws = $.websocket("ws://127.0.0.1:29999/echo", {
        open: function()
        {
        alert("THIS SHOULD BE DISPLAYED ON OPEN");
        },

        close: function(){  },

        events: {
                message: function(e) { alert(e); $('#content').append(e.data + '<br>') }
        }
});

What is the expected output? What do you see instead?
I expected to see the message "THIS SHOULD BE DISPLAYED ON OPEN" to be displayed

What version of the product are you using? On what operating system?
jQuery Web Sockets Plugin v0.0.1
Firefox 4 or Webkit / Safari 5.0

Please provide any additional information below.
I just suspect the onopen function not to be bound
The following code works like a charm:

        ws = new WebSocket("ws://localhost:29999/websocket");
        ws.onmessage = function(evt) { $("#msg").append("<p>"+evt.data+"</p>"); };
        ws.onclose = function() { debug("socket closed"); };
        ws.onopen = function() {
          debug("connected...");
          ws.send("{\"message\":\"Yo\"}");
        };

Original issue reported on code.google.com by flavien....@gmail.com on 22 Jul 2010 at 1:07

GoogleCodeExporter commented 8 years ago
Move the $.extend($.websocketSettings, s); before the bindings in the source 
code and it will work. He binds the callbacks before he extends the settings 
and therefore the default callbacks is triggered instead.

Original comment by ggus...@gmail.com on 4 Aug 2010 at 3:02

GoogleCodeExporter commented 8 years ago
It works! thank you for your help :-)

Original comment by flavien....@gmail.com on 11 Aug 2010 at 7:21