Skip to content

Commit ee4ff16

Browse files
authored
Merge pull request #15 from oxygens/master
Tests.
2 parents 7260e42 + 00d1356 commit ee4ff16

20 files changed

+1412
-598
lines changed

README.MD

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ For WebSocket client support in Node.js and browsers, `JSONRPC.Plugins.Client.We
2121

2222
On the Node.js side, this library is tested to work with [websockets/ws](https://github.com/websockets/ws). Other `WebSocketServer` implementations are supported if API compatible with `websockets/ws` (constructor and events), or made compatible through an adapter.
2323

24+
There is a wrapper for [uWebSockets](https://github.com/uWebSockets/uWebSockets) in `JSONRPC.WebSocketAdapters.uws.WebSocketWrapper`. All obtained `uws.WebSocket` instances (from the `connection` event, or instantiated directly) must be wrapped (and thus replaced) with an instance of this class.
25+
2426
#### HTTP
2527

26-
`JSONRPC.Client` has embeded support for HTTP requests, through [fetch](https://developer.mozilla.org/en/docs/Web/API/Fetch_API) (polyfills for older browsers exist, and work just fine).
28+
`JSONRPC.Client` has embeded support for HTTP requests, through [fetch](https://developer.mozilla.org/en/docs/Web/API/Fetch_API) (polyfills for older browsers exist, and work just fine). `JSONRPC.Server` has the `attachToHTTPServer` method.
2729

2830
#### Other
2931

@@ -233,7 +235,8 @@ const wsJSONRPCRouter = new JSONRPC.BidirectionalWebsocketRouter(jsonrpcServer);
233235
// Optional.
234236
wsJSONRPCRouter.on("madeReverseCallsClient", (clientReverseCalls) => { /*add plugins or just setup the client even further*/ });
235237

236-
// Alternatively reuse existing web server: const webSocketServer = new WebSocketServer({server: httpServerInstance});
238+
// Alternatively reuse existing web server:
239+
// const webSocketServer = new WebSocketServer({server: httpServerInstance});
237240
const webSocketServer = new WebSocketServer({port: 8080});
238241
webSocketServer.on("error", (error) => {console.error(error); process.exit(1);});
239242

@@ -261,7 +264,7 @@ jsonrpcServer.addPlugin(new JSONRPC.Plugins.Server.AuthenticationSkip());
261264
jsonrpcServer.addPlugin(new JSONRPC.Plugins.Server.AuthorizeAll());
262265

263266

264-
const webSocket = new WebSocket("ws://localhost/api");
267+
const webSocket = new WebSocket("ws://localhost:8080/api");
265268
await new Promise((fnResolve, fnReject) => {
266269
webSocket.addEventListener("open", fnResolve);
267270
webSocket.addEventListener("error", fnReject);

bug.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const WebSocket = require("uws");
2+
const WebSocketServer = WebSocket.Server;
3+
4+
5+
(async () => {
6+
const webSocketServer = new WebSocketServer({port: 8080});
7+
webSocketServer.on("error", console.error);
8+
webSocketServer.on("connection", console.log);
9+
webSocketServer.on("message", console.log);
10+
11+
12+
13+
const webSocket = new WebSocket("ws://localhost:8080/api");
14+
await new Promise((fnResolve, fnReject) => {
15+
webSocket.on("open", fnResolve);
16+
webSocket.on("error", fnReject);
17+
});
18+
19+
let str10MBPayload = "";
20+
let nIterator = 0;
21+
while(str10MBPayload.length < 10 * 1024 * 1024 /*10 MB*/)
22+
{
23+
str10MBPayload += str10MBPayload + "_" + (++nIterator);
24+
}
25+
26+
webSocket.on("close", process.exit);
27+
webSocket.send(str10MBPayload);
28+
})();

builds/browser/es5/jsonrpc.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builds/browser/es5/jsonrpc.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)