Skip to content

Commit

Permalink
Merge pull request #30 from isaacgr/feature/#29/websocket_client_serv…
Browse files Browse the repository at this point in the history
…er_side

Feature/#29/websocket client server side
isaacgr authored Jul 20, 2019
2 parents 5a8fe21 + c0164c4 commit 5257375
Showing 4 changed files with 622 additions and 24 deletions.
73 changes: 49 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Jaysonic - A persistent JSON-RPC client and server](#jaysonic---a-persistent-json-rpc-client-and-server)
- [List of features](#list-of-features)
- [Download & Installation](#download--installation)
- [Initialization](#initialization)
- [Options](#options)
- [Code Demos](#code-demos) - [TCP](#tcp) - [HTTP](#http) - [WS](#ws)
- [Server side](#server-side)
- [Listening](#listening)
- [Closing the connection](#closing-the-connection)
- [Adding Methods](#adding-methods)
- [Listening for client connections](#listening-for-client-connections)
- [Client Side](#client-side)
- [Connecting](#connecting)
- [Listening for server disconnect](#listening-for-server-disconnect)
- [Making requests](#making-requests)
- [Subscriptions](#subscriptions)
- [Batch Requests](#batch-requests)
- [HTTP Client Requests](#http-client-requests)
- [Notifications](#notifications)
- [HTTP Client Notifications](#http-client-notifications)
- [Contributing](#contributing)
- [Authors or Acknowledgments](#authors-or-acknowledgments)
- [License](#license)
- [List of features](#list-of-features)
- [Download & Installation](#download--installation)
- [Initialization](#initialization)
- [WS Client for browser](#ws-client-for-browser)
- [WS Client for Node](#ws-client-for-node)
- [Options](#options)
- [Code Demos](#code-demos)
- [TCP](#tcp)
- [HTTP](#http)
- [WS](#ws)
- [Server side](#server-side)
- [Listening](#listening)
- [Closing the connection](#closing-the-connection)
- [Adding Methods](#adding-methods)
- [Listening for client connections](#listening-for-client-connections)
- [Client Side](#client-side)
- [Connecting](#connecting)
- [Listening for server disconnect](#listening-for-server-disconnect)
- [Making requests](#making-requests)
- [Subscriptions](#subscriptions)
- [Batch Requests](#batch-requests)
- [HTTP Client Requests](#http-client-requests)
- [Notifications](#notifications)
- [HTTP Client Notifications](#http-client-notifications)
- [Contributing](#contributing)
- [Authors or Acknowledgments](#authors-or-acknowledgments)
- [License](#license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

@@ -44,6 +50,7 @@ A TCP, HTTP and WebSocket server and client that implement the JSON-RPC 2.0 Spec
- TCP server/client
- HTTP server/client
- WebSocket server/client
- WebSocket client supported in the browser
- Automatic increment of request ID
- Associate response ID with request

@@ -68,15 +75,27 @@ const client = new Jaysonic.client.http();
const wss = new Jaysonic.server.ws();
```

**Note that the web socket client can only be run in the browser.**
**Note that there are two web socket clients**
**One can only be run in the browser, and the other can run in a NodeJS environment.**

#### WS Client for browser

To instantiate the web socket client
The browser ws client is based on the `window.WebSocket` class.

```js
const Jaysonic = require("jaysonic/lib/client-ws");
const ws = new Jaysonic.wsclient();
```

#### WS Client for Node

The Node ws client is based on the `ws` library (same as the server).

```js
const Jaysonic = require("jaysonic");
const ws = new Jaysonic.client.ws();
```

### Options

The client and server support changing the JSON-RPC version and the delimiter used. Just pass them in the same object as the host and port to override the defaults.
@@ -166,9 +185,15 @@ const Jaysonic = require("jaysonic");
const socket = require("jaysonic/lib/client-ws");

// client and server with overrides

// client in the browser
const ws = new socket.wsclient({
url: "ws://127.0.0.1:8100"
});
// or to work in node
const ws = new Jaysonic.client.ws({
url: "ws://127.0.0.1:8100"
});

const wss = new Jaysonic.server.ws({
port: 8100
7 changes: 7 additions & 0 deletions src/client/index.js
Original file line number Diff line number Diff line change
@@ -267,3 +267,10 @@ Client.tcp = require("./tcp");
* @static
*/
Client.http = require("./http");

/**
* WebSoket client constructor
* @type ClientWS
* @static
*/
Client.ws = require("./ws");
Loading

0 comments on commit 5257375

Please sign in to comment.