Skip to content

Commit

Permalink
Improved WebSocketClient
Browse files Browse the repository at this point in the history
  • Loading branch information
andot committed Nov 17, 2016
1 parent 31169af commit f16cfac
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Ma Bingyao <[email protected]>",
"name": "hprose",
"version": "2.0.22",
"version": "2.0.23",
"description": "Hprose is a High Performance Remote Object Service Engine.",
"keywords": [
"hprose",
Expand Down
6 changes: 3 additions & 3 deletions dist/hprose.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/hprose.min.js

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions dist/hprose.src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Hprose for JavaScript v2.0.22
// Hprose for JavaScript v2.0.23
// Copyright (c) 2008-2016 http://hprose.com
// Hprose is freely distributable under the MIT license.
// For all details and documentation:
Expand Down Expand Up @@ -6804,7 +6804,7 @@
* *
* hprose websocket client for JavaScript. *
* *
* LastModified: Sep 29, 2016 *
* LastModified: Nov 18, 2016 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
Expand Down Expand Up @@ -6913,13 +6913,8 @@
ws.onclose = onclose;
}
function sendAndReceive(request, env) {
if (ws === null ||
ws.readyState === WebSocket.CLOSING ||
ws.readyState === WebSocket.CLOSED) {
connect();
}
var future = new Future();
var id = getNextId();
var future = new Future();
_futures[id] = future;
_envs[id] = env;
if (env.timeout > 0) {
Expand All @@ -6932,6 +6927,11 @@
return e instanceof TimeoutError;
});
}
if (ws === null ||
ws.readyState === WebSocket.CLOSING ||
ws.readyState === WebSocket.CLOSED) {
connect();
}
if (_count < 100) {
++_count;
_ready.then(function() { send(id, request); });
Expand Down
6 changes: 3 additions & 3 deletions example/hprose.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hprose-js",
"filename": "hprose.js",
"version": "2.0.22",
"version": "2.0.23",
"description": "Hprose is a High Performance Remote Object Service Engine.",
"homepage": "https://github.com/hprose",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/CopyRight.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Hprose for JavaScript v2.0.22
// Hprose for JavaScript v2.0.23
// Copyright (c) 2008-2016 http://hprose.com
// Hprose is freely distributable under the MIT license.
// For all details and documentation:
Expand Down
20 changes: 8 additions & 12 deletions src/WebSocketClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* *
* hprose websocket client for JavaScript. *
* *
* LastModified: Nov 16, 2016 *
* LastModified: Nov 18, 2016 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
Expand Down Expand Up @@ -112,6 +112,7 @@
ws = null;
}
function connect() {
_ready = new Future();
ws = new WebSocket(self.uri());
ws.binaryType = 'arraybuffer';
ws.onopen = onopen;
Expand All @@ -120,13 +121,8 @@
ws.onclose = onclose;
}
function sendAndReceive(request, env) {
if (ws === null ||
ws.readyState === WebSocket.CLOSING ||
ws.readyState === WebSocket.CLOSED) {
_ready = new Future();
}
var future = new Future();
var id = getNextId();
var future = new Future();
_futures[id] = future;
_envs[id] = env;
if (env.timeout > 0) {
Expand All @@ -139,18 +135,18 @@
return e instanceof TimeoutError;
});
}
if (ws === null ||
ws.readyState === WebSocket.CLOSING ||
ws.readyState === WebSocket.CLOSED) {
connect();
}
if (_count < 100) {
++_count;
_ready.then(function() { send(id, request); });
}
else {
_requests.push([id, request]);
}
if (ws === null ||
ws.readyState === WebSocket.CLOSING ||
ws.readyState === WebSocket.CLOSED) {
connect();
}
if (env.oneway) { future.resolve(); }
return future;
}
Expand Down
6 changes: 3 additions & 3 deletions test/hprose.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f16cfac

Please sign in to comment.