jquery-websocket
stefanobasili / jquery-websocket Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/jquery-websocket
Automatically exported from code.google.com/p/jquery-websocket
jquery-websocket
What steps will reproduce the problem?
Running the example
What is the expected output? What do you see instead?
See the example.
What version of the product are you using? On what operating system?
v0.0.1 in Chromium v5.0.308.0 on MacOS
Please provide any additional information below.
I get the error text and code in Chromium Developer Tools.
Original issue reported on code.google.com by [email protected]
on 31 Jan 2010 at 12:11
What steps will reproduce the problem?
1. Create a WebSocket through your API
2. Send a message before the "open" or "onopen" was triggered
What is the expected output? What do you see instead?
I expect that the message is not sent but kept in a cache. When the connection
is etablished, the message is sent.
Or maybe the send function returns me "false", or the send function throws an
error, or I expect I could choose different behavior through your WebSocket
options.
As to me, the best behavior would be : the send function waits for the
websocket to connect and if the websocket do not connect until a fixed delay (5
sec?), an error is thrown.
Instead, I see this error:
"Uncaught Error: INVALID_STATE_ERR: DOM Exception 11"
return this._send($.toJSON(m)); // jquery.websocket-0.0.1.js:39
$.extend.websocket.ws.send
What version of the product are you using? On what operating system?
Windows XP + Chrome 17.0.963.56 m
jquery-1.7.1.min.js
jquery.websocket-0.0.1.js
jquery.json-2.3.min.js
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 27 Feb 2012 at 3:46
Seeing as there's been no maintenance on this for a couple of years and I
needed a fix, I forked this at https://github.com/dchelimsky/jquery-websocket.
Please feel free to submit issues and/or pull requests there, or just fork it
if you want to take ownership of it.
Cheers,
David
Original issue reported on code.google.com by [email protected]
on 20 Sep 2012 at 8:50
But it would work on Firefox if you add these lines:
function isset(variable)
{
return typeof variable !== "undefined"
}
if (! isset(WebSocket))
WebSocket = MozWebSocket;
I hope you will do :)
Original issue reported on code.google.com by [email protected]
on 27 Feb 2012 at 2:52
What steps will reproduce the problem?
1.
<script>
...
ws = $.websocket("ws://somedomain.com:8088", {
open: function() {
alert('open');
},
close: function() {
alert('close');
},
events: {
say: function(e) {
alert(e.data.name);
alert(e.data.text);
}
}
});
...
</script>
binding not work
2. because:
<script>
ws._settings = $.extend($.websocketSettings, s);
</script>
is AFTER binding
3. solution:
need remove it BEFORE binding
<script>
(function($){
$.extend({
websocketSettings: {
open: function(){},
close: function(){},
message: function(){},
options: {},
events: {}
},
websocket: function(url, s) {
var ws = WebSocket ? new WebSocket( url ) : {
send: function(m){ return false },
close: function(){}
};
/* extend before binding */
ws._settings = $.extend($.websocketSettings, s);
$(ws)
.bind('open', $.websocketSettings.open)
.bind('close', $.websocketSettings.close)
.bind('message', $.websocketSettings.message)
.bind('message', function(e){
var m = $.evalJSON(e.originalEvent.data);
var h = $.websocketSettings.events[m.type];
if (h) h.call(this, m);
});
ws._send = ws.send;
ws.send = function(type, data) {
var m = {type: type};
m = $.extend(true, m, $.extend(true, {}, $.websocketSettings.options, m));
if (data)
m['data'] = data;
return this._send($.toJSON(m));
}
$(window).unload(function(){ ws.close(); ws = null });
return ws;
}
});
})(jQuery);
</script>
/* patch from fish9370 */
Original issue reported on code.google.com by [email protected]
on 1 Aug 2013 at 7:38
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 [email protected]
on 22 Jul 2010 at 1:07
The "error" event is not bound.
Is it normal?
Why didn't you add the onerror WebSocket function?
Original issue reported on code.google.com by [email protected]
on 27 Feb 2012 at 3:52
I update the code for fix bind problem and catch the exception.
Below is updated the code.
/*
* jQuery Web Sockets Plugin v0.0.1
* http://code.google.com/p/jquery-websocket/
*
* This document is licensed as free software under the terms of the
* MIT License: http://www.opensource.org/licenses/mit-license.php
*
* Copyright (c) 2010 by shootaroo (Shotaro Tsubouchi).
*/
(function($){
$.extend({
websocketSettings: {
open: function(){},
close: function(){},
message: function(){},
options: {},
events: {}
},
websocket: function(url, s) {
var ws = WebSocket ? new WebSocket( url ) : {
send: function(m){ return false },
close: function(){}
};
ws._settings = $.extend($.websocketSettings, s);
$(ws)
.bind('open', $.websocketSettings.open)
.bind('close', $.websocketSettings.close)
.bind('message', $.websocketSettings.message)
.bind('message', function(e){
var m = $.evalJSON(e.originalEvent.data);
var h = $.websocketSettings.events[m.type];
if (h) h.call(this, m);
});
ws._send = ws.send;
ws.send = function(type, data) {
var m = {command: type};
m = $.extend(true, m, $.extend(true, {}, $.websocketSettings.options, m));
if (data) m['data'] = data;
try{
this._send($.toJSON(m));
}
catch(ex)
{
alert(ex);
return false;
}
return true;
}
$(window).unload(function(){ ws.close(); ws = null });
return ws;
}
});
})(jQuery);
Original issue reported on code.google.com by [email protected]
on 2 Apr 2011 at 12:42
Event.data returns undefined. To get data from the message, you have to access
event.originalEvent.data. Is this a bug?
Original issue reported on code.google.com by jonahbron.d
on 27 Nov 2010 at 12:46
What steps will reproduce the problem?
1. Create a web page that opens two WebSockets to a defined Server.
2. Implement a simple ping-pong message protocol, where both sockets expect a
pong message on their own socket after they have sent a message.
3. Let both websockets send a ping message.
The expected output is that each socket receives a pong. Instead both pongs
message events are handled by one client socket message handler, the one that
was created last.
This was tested with latest Chrome and Firefox browsers using the HTML5
WebSocket class. I am using version 0.0.1 of jquery-websocket.
Analyzing the issue we found that the jquery-websocket-0.0.1 script is faulty
as described below:
After initialisation of the local variable 'ws', 'ws._settings' is set to the
merge result of the jquery static 'websocketSettings' and input parameter 's'.
but the extend function modifies the first argument and so the static variable
gets poisoned each time a new websocket is created. This lead to other strange
symptoms as well, when we tried to reinstanciate the broken socket.
We wrote a fix for this issue, please update.
Original issue reported on code.google.com by [email protected]
on 14 Aug 2012 at 2:20
Attachments:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.