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 fba04a4 commit 0245b17
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 24 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 <andot@hprose.com>",
"name": "hprose-html5",
"version": "2.0.24",
"version": "2.0.25",
"description": "Hprose is a High Performance Remote Object Service Engine.",
"keywords": [
"hprose",
Expand Down
4 changes: 2 additions & 2 deletions dist/hprose-html5.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions dist/hprose-html5.src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Hprose for HTML5 v2.0.24
// Hprose for HTML5 v2.0.25
// Copyright (c) 2008-2016 http://hprose.com
// Hprose is freely distributable under the MIT license.
// For all details and documentation:
Expand Down Expand Up @@ -5475,7 +5475,7 @@
* *
* hprose websocket client for HTML5. *
* *
* LastModified: Sep 29, 2016 *
* LastModified: Nov 18, 2016 *
* Author: Ma Bingyao <andot@hprose.com> *
* *
\**********************************************************/
Expand Down Expand Up @@ -5573,11 +5573,6 @@
ws.onclose = onclose;
}
function sendAndReceive(request, env) {
if (ws === null ||
ws.readyState === WebSocket.CLOSING ||
ws.readyState === WebSocket.CLOSED) {
connect();
}
var id = getNextId();
var future = new Future();
_futures[id] = future;
Expand All @@ -5591,6 +5586,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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hprose-html5",
"filename": "hprose-html5.js",
"version": "2.0.24",
"version": "2.0.25",
"description": "Hprose is a High Performance Remote Object Service Engine.",
"homepage": "https://github.com/andot/hprose",
"keywords": [
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 HTML5 v2.0.24
// Hprose for HTML5 v2.0.25
// Copyright (c) 2008-2016 http://hprose.com
// Hprose is freely distributable under the MIT license.
// For all details and documentation:
Expand Down
18 changes: 7 additions & 11 deletions src/WebSocketClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* *
* hprose websocket client for HTML5. *
* *
* LastModified: Nov 16, 2016 *
* LastModified: Nov 18, 2016 *
* Author: Ma Bingyao <andot@hprose.com> *
* *
\**********************************************************/
Expand Down Expand Up @@ -101,6 +101,7 @@
ws = null;
}
function connect() {
_ready = new Future();
ws = new WebSocket(self.uri);
ws.binaryType = 'arraybuffer';
ws.onopen = onopen;
Expand All @@ -109,11 +110,6 @@
ws.onclose = onclose;
}
function sendAndReceive(request, env) {
if (ws === null ||
ws.readyState === WebSocket.CLOSING ||
ws.readyState === WebSocket.CLOSED) {
_ready = new Future();
}
var id = getNextId();
var future = new Future();
_futures[id] = future;
Expand All @@ -127,18 +123,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

0 comments on commit 0245b17

Please sign in to comment.