Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| adee8ba51c | |||
| 3675cfb798 | |||
| 1222308201 | |||
| 8c9ae84740 | |||
| d404c78c46 |
@@ -1,4 +1,6 @@
|
||||
.git
|
||||
.gitignore
|
||||
.npmignore
|
||||
.redcar
|
||||
.travis.yml
|
||||
node_modules
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
=== 0.4.1 / 2012-02-26
|
||||
|
||||
* Treat anything other than a Buffer as a string when calling send()
|
||||
|
||||
|
||||
=== 0.4.0 / 2012-02-13
|
||||
|
||||
* Add ping() method to server-side WebSocket and EventSource
|
||||
|
||||
@@ -62,7 +62,9 @@ var instance = {
|
||||
DEFAULT_RETRY: 5,
|
||||
|
||||
send: function(message, options) {
|
||||
message = message.replace(/(\r\n|\r|\n)/g, '$1data: ');
|
||||
if (this.readyState !== API.OPEN) return false;
|
||||
|
||||
message = String(message).replace(/(\r\n|\r|\n)/g, '$1data: ');
|
||||
options = options || {};
|
||||
|
||||
var frame = '';
|
||||
@@ -72,7 +74,10 @@ var instance = {
|
||||
|
||||
try {
|
||||
this._stream.write(frame, 'utf8');
|
||||
} catch (e) {}
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
ping: function() {
|
||||
|
||||
@@ -43,6 +43,8 @@ var API = {
|
||||
if (this.readyState === API.CLOSED)
|
||||
return false;
|
||||
|
||||
if (!(data instanceof Buffer)) data = String(data);
|
||||
|
||||
var frame = this._parser.frame(data, type, errorType);
|
||||
try {
|
||||
this._stream.write(frame, 'binary');
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
, "author" : "James Coglan <jcoglan@gmail.com> (http://jcoglan.com/)"
|
||||
, "keywords" : ["websocket", "eventsource"]
|
||||
|
||||
, "version" : "0.4.0"
|
||||
, "version" : "0.4.1"
|
||||
, "engines" : {"node": ">=0.4.0"}
|
||||
, "main" : "./lib/faye/websocket"
|
||||
, "devDependencies" : {"jsclass": ""}
|
||||
|
||||
@@ -60,13 +60,13 @@ JS.ENV.WebSocketSteps = JS.Test.asyncSteps({
|
||||
callback()
|
||||
},
|
||||
|
||||
send_message: function(callback) {
|
||||
this._ws.send("I expect this to be echoed")
|
||||
send_message: function(message, callback) {
|
||||
this._ws.send(message)
|
||||
setTimeout(callback, 100)
|
||||
},
|
||||
|
||||
check_response: function(callback) {
|
||||
this.assertEqual( "I expect this to be echoed", this._message )
|
||||
check_response: function(message, callback) {
|
||||
this.assertEqual( message, this._message )
|
||||
callback()
|
||||
},
|
||||
|
||||
@@ -116,8 +116,26 @@ JS.ENV.ClientSpec = JS.Test.describe("Client", function() { with(this) {
|
||||
|
||||
it("can send and receive messages", function() { with(this) {
|
||||
listen_for_message()
|
||||
send_message()
|
||||
check_response()
|
||||
send_message("I expect this to be echoed")
|
||||
check_response("I expect this to be echoed")
|
||||
}})
|
||||
|
||||
it("sends numbers as strings", function() { with(this) {
|
||||
listen_for_message()
|
||||
send_message(13)
|
||||
check_response("13")
|
||||
}})
|
||||
|
||||
it("sends booleans as strings", function() { with(this) {
|
||||
listen_for_message()
|
||||
send_message(false)
|
||||
check_response("false")
|
||||
}})
|
||||
|
||||
it("sends arrays as strings", function() { with(this) {
|
||||
listen_for_message()
|
||||
send_message([13,14,15])
|
||||
check_response("13,14,15")
|
||||
}})
|
||||
}})
|
||||
|
||||
@@ -129,7 +147,7 @@ JS.ENV.ClientSpec = JS.Test.describe("Client", function() { with(this) {
|
||||
|
||||
it("cannot send and receive messages", function() { with(this) {
|
||||
listen_for_message()
|
||||
send_message()
|
||||
send_message("I expect this to be echoed")
|
||||
check_no_response()
|
||||
}})
|
||||
}})
|
||||
|
||||
Reference in New Issue
Block a user