├── examples
├── painter
│ ├── client
│ │ ├── canvas.js
│ │ ├── contents
│ │ │ ├── index.json
│ │ │ ├── style.css
│ │ │ └── paint.ts
│ │ ├── config.json
│ │ └── templates
│ │ │ └── index.html
│ ├── tsconfig.json
│ ├── README.md
│ ├── package.json
│ ├── Makefile
│ ├── protocol
│ │ └── service.proto
│ ├── shared
│ │ ├── paint.ts
│ │ └── brush.json
│ └── server
│ │ └── server.ts
└── ping
│ ├── package.json
│ ├── service.proto
│ ├── server.js
│ └── ping.js
├── docs
├── README.md
├── assets
│ └── images
│ │ ├── icons.png
│ │ ├── icons@2x.png
│ │ ├── widgets.png
│ │ └── widgets@2x.png
├── interfaces
│ ├── irpcmessage.html
│ ├── iprotobuftype.html
│ ├── iserverevents.html
│ ├── iclientevents.html
│ └── iserveroptions.html
├── index.html
└── globals.html
├── ws-browser.js
├── .gitignore
├── src
├── index.ts
├── utils.ts
├── server.ts
└── client.ts
├── test
├── tsconfig.json
└── index.ts
├── .travis.yml
├── tslint.json
├── tsconfig.json
├── protocol
├── test.proto
└── rpc.proto
├── package.json
├── LICENSE
├── Makefile
└── README.md
/examples/painter/client/canvas.js:
--------------------------------------------------------------------------------
1 | module.exports = window
2 |
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | Served at
2 |
--------------------------------------------------------------------------------
/ws-browser.js:
--------------------------------------------------------------------------------
1 | module.exports = window.WebSocket || window.MozWebSocket
--------------------------------------------------------------------------------
/examples/painter/client/contents/index.json:
--------------------------------------------------------------------------------
1 | {
2 | "template": "index.html"
3 | }
4 |
--------------------------------------------------------------------------------
/docs/assets/images/icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jnordberg/wsrpc/HEAD/docs/assets/images/icons.png
--------------------------------------------------------------------------------
/docs/assets/images/icons@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jnordberg/wsrpc/HEAD/docs/assets/images/icons@2x.png
--------------------------------------------------------------------------------
/docs/assets/images/widgets.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jnordberg/wsrpc/HEAD/docs/assets/images/widgets.png
--------------------------------------------------------------------------------
/docs/assets/images/widgets@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jnordberg/wsrpc/HEAD/docs/assets/images/widgets@2x.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | lib3/
3 | lib6/
4 | coverage/
5 | **/protocol/*
6 | !**/protocol/*.proto
7 | .nyc_output/
8 |
--------------------------------------------------------------------------------
/examples/ping/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "wsrpc-example-node",
3 | "private": true,
4 | "dependencies": {
5 | "wsrpc": ">=1.1.0"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | export {Server, Connection, IServerEvents, IServerOptions} from './server'
2 | export {Client, IClientEvents, IClientOptions} from './client'
3 | export const version: string = require('../package').version
4 |
--------------------------------------------------------------------------------
/test/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "lib": ["es2015"],
4 | "module": "commonjs",
5 | "moduleResolution": "node",
6 | "target": "es6"
7 | },
8 | "include": [
9 | "*.ts"
10 | ]
11 | }
--------------------------------------------------------------------------------
/examples/painter/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "lib": [
4 | "dom",
5 | "es2015"
6 | ],
7 | "module": "commonjs",
8 | "moduleResolution": "node",
9 | "target": "es3"
10 | }
11 | }
--------------------------------------------------------------------------------
/examples/ping/service.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | service PingService {
4 | rpc Ping (Ping) returns (Pong) {}
5 | }
6 |
7 | message Ping {
8 | bytes nonce = 1;
9 | }
10 |
11 | message Pong {
12 | bytes nonce = 1;
13 | uint32 time = 2;
14 | }
15 |
--------------------------------------------------------------------------------
/examples/painter/README.md:
--------------------------------------------------------------------------------
1 |
2 | # wsrpc-example-painter
3 |
4 | Live version [up here](https://johan-nordberg.com/wspainter)
5 |
6 | ## Develop
7 |
8 | In two separate terminals run:
9 |
10 | ```
11 | make preview
12 | ```
13 |
14 | and
15 |
16 | ```
17 | make server
18 | ```
19 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "8"
4 | - "10"
5 | after_success:
6 | - "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
7 | env:
8 | - CXX=g++-4.8
9 | addons:
10 | apt:
11 | sources:
12 | - ubuntu-toolchain-r-test
13 | packages:
14 | - g++-4.8
15 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "defaultSeverity": "error",
3 | "extends": ["tslint:recommended"],
4 | "rules": {
5 | "max-classes-per-file": false,
6 | "no-bitwise": false,
7 | "no-var-requires": false,
8 | "quotemark": [true, "single", "avoid-escape"],
9 | "semicolon": [true, "never"]
10 | }
11 | }
--------------------------------------------------------------------------------
/examples/painter/client/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "browserify": {
3 | "watchify": false,
4 | "extensions": [".js", ".ts"],
5 | "plugins": ["tsify"]
6 | },
7 | "nunjucks": {
8 | "autoescape": false
9 | },
10 | "plugins": [
11 | "wintersmith-browserify",
12 | "wintersmith-nunjucks",
13 | "wintersmith-livereload"
14 | ]
15 | }
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "declaration": true,
4 | "lib": ["es2015"],
5 | "module": "commonjs",
6 | "moduleResolution": "node",
7 | "noImplicitAny": true,
8 | "noImplicitThis": true,
9 | "outDir": "lib",
10 | "strictNullChecks": true,
11 | "target": "es6"
12 | },
13 | "include": [
14 | "src/*.ts"
15 | ]
16 | }
--------------------------------------------------------------------------------
/protocol/test.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | message Empty {}
4 |
5 | service TestService {
6 | rpc Echo (TextMessage) returns (TextMessage) {}
7 | rpc Upper (TextMessage) returns (TextMessage) {}
8 | rpc NotImplemented (EmptyMessage) returns (EmptyMessage) {}
9 | }
10 |
11 | message EmptyMessage {}
12 |
13 | message TextMessage {
14 | required string text = 1;
15 | }
16 |
17 | message EventRequest {
18 | required string name = 1;
19 | required uint32 delay = 2;
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/examples/painter/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "wsrpc-example-painter",
3 | "private": true,
4 | "browser": {
5 | "canvas": "./client/canvas.js"
6 | },
7 | "dependencies": {
8 | "@types/lru-cache": "^5.1.0",
9 | "@types/sharp": "^0.23.0",
10 | "canvas": "^2.6.0",
11 | "lru-cache": "^5.1.1",
12 | "protobufjs": "^6.8.8",
13 | "sharp": "^0.23.1",
14 | "ts-node": "^8.4.1",
15 | "tsify": "^4.0.0",
16 | "typescript": "^3.6.4",
17 | "wintersmith": "^2.5.0",
18 | "wintersmith-browserify": "^1.3.0",
19 | "wintersmith-livereload": "^1.0.0",
20 | "wintersmith-nunjucks": "^2.0.0",
21 | "wsrpc": "^1.4.1"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/protocol/rpc.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | message Message {
4 | enum Type { REQUEST = 1; RESPONSE = 2; EVENT = 3; }
5 | required Type type = 1;
6 | optional Request request = 2;
7 | optional Response response = 3;
8 | optional Event event = 4;
9 | }
10 |
11 | message Request {
12 | required string method = 1;
13 | required uint32 seq = 2;
14 | optional bytes payload = 3;
15 | }
16 |
17 | message Response {
18 | required uint32 seq = 1;
19 | required bool ok = 2;
20 | optional bytes payload = 3;
21 | optional string error = 4;
22 | }
23 |
24 | message Event {
25 | required string name = 1;
26 | optional bytes payload = 2;
27 | }
28 |
--------------------------------------------------------------------------------
/examples/painter/Makefile:
--------------------------------------------------------------------------------
1 |
2 | PATH := $(PATH):$(PWD)/node_modules/.bin
3 | SHELL := env PATH=$(PATH) /bin/bash
4 |
5 | .PHONY: preview
6 | preview: node_modules protocol/service.d.ts protocol/service.js
7 | wintersmith preview --chdir client
8 |
9 | .PHONY: server
10 | preview: node_modules protocol/service.d.ts protocol/service.js
11 | ts-node server/server.ts
12 |
13 | protocol/service.js: node_modules protocol/service.proto
14 | pbjs -t static-module -w commonjs protocol/service.proto -o protocol/service.js
15 |
16 | protocol/service.d.ts: node_modules protocol/service.js
17 | pbts -o protocol/service.d.ts protocol/service.js
18 |
19 | node_modules:
20 | npm install
21 |
22 | .PHONY: clean
23 | clean:
24 | rm -f protocol/service.js
25 | rm -f protocol/service.d.ts
26 |
27 | .PHONY: distclean
28 | distclean: clean
29 | rm -rf node_modules
30 |
--------------------------------------------------------------------------------
/examples/painter/protocol/service.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | service Painter {
4 | rpc GetCanvas (CanvasRequest) returns (CanvasResponse) {}
5 | rpc Paint (PaintEvent) returns (Empty) {}
6 | }
7 |
8 | message Empty {}
9 |
10 | message Position {
11 | required int32 x = 1;
12 | required int32 y = 2;
13 | }
14 |
15 | message PaintEvent {
16 | required Position pos = 1;
17 | required uint32 size = 3;
18 | required uint32 color = 4;
19 | }
20 |
21 | message StatusEvent {
22 | required uint32 users = 1;
23 | }
24 |
25 | message CanvasRequest {
26 | enum Encoding {
27 | PNG = 1;
28 | JPEG = 2;
29 | WEBP = 3;
30 | }
31 | required Position offset = 1;
32 | required uint32 width = 2;
33 | required uint32 height = 3;
34 | required Encoding encoding = 4;
35 | }
36 |
37 | message CanvasResponse {
38 | required bytes image = 1;
39 | }
40 |
--------------------------------------------------------------------------------
/examples/ping/server.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | const wsrpc = require('wsrpc')
4 | const protobuf = require('protobufjs')
5 |
6 | const proto = protobuf.loadSync('service.proto')
7 | const service = proto.lookupService('PingService')
8 |
9 | const server = new wsrpc.Server(service, {port: 4242})
10 |
11 | server.implement('ping', async (request) => {
12 | return {nonce: request.nonce, time: Date.now()}
13 | })
14 | /*
15 | // node <7.6 version
16 | server.implement('ping', (request) => {
17 | return Promise.resolve({nonce: request.nonce, time: Date.now()})
18 | })
19 | */
20 |
21 | server.on('listening', () => {
22 | console.log(`listening on ${ server.options.port }`)
23 | })
24 |
25 | server.on('error', (error) => {
26 | console.warn('error', error)
27 | })
28 |
29 | server.on('connection', (connection) => {
30 | console.log(`connection ${ connection.id }`)
31 | connection.once('close', () => {
32 | console.log(`connection ${ connection.id } closed`)
33 | })
34 | })
35 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "wsrpc",
3 | "version": "1.4.1",
4 | "description": "node.js/browser protobuf rpc over binary websockets",
5 | "author": "Johan Nordberg",
6 | "license": "BSD-3-Clause",
7 | "main": "./lib6/index",
8 | "typings": "./lib6/index",
9 | "browser": {
10 | "./lib6/index": "./lib3/client.js",
11 | "ws": "./ws-browser.js"
12 | },
13 | "files": [
14 | "lib3/*",
15 | "lib6/*",
16 | "protocol/*",
17 | "ws-browser.js"
18 | ],
19 | "repository": {
20 | "type": "git",
21 | "url": "https://github.com/jnordberg/wsrpc"
22 | },
23 | "scripts": {
24 | "prepublishOnly": "make lint && make test && make docs && make lib",
25 | "test": "make ci-test"
26 | },
27 | "keywords": [
28 | "protobuf",
29 | "protobuffer",
30 | "protocol buffer",
31 | "rpc",
32 | "websocket",
33 | "websockets",
34 | "ws"
35 | ],
36 | "dependencies": {
37 | "protobufjs": "^6.8.8",
38 | "ws": "^7.2.0",
39 | "verror": "^1.10.0"
40 | },
41 | "devDependencies": {
42 | "@types/mocha": "^5.2.7",
43 | "@types/node": "^12.11.5",
44 | "@types/verror": "^1.9.3",
45 | "@types/ws": "^6.0.3",
46 | "coveralls": "^3.0.7",
47 | "mocha": "^6.2.2",
48 | "nyc": "^14.1.1",
49 | "ts-node": "^8.4.1",
50 | "tslint": "^5.20.0",
51 | "typedoc": "^0.15.0",
52 | "typescript": "^3.6.4"
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Copyright (c) 2017 Johan Nordberg. All Rights Reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 |
7 | 1. Redistribution of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | 2. Redistribution in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | 3. Neither the name of the copyright holder nor the names of its contributors
15 | may be used to endorse or promote products derived from this software without
16 | specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 | OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
29 | You acknowledge that this software is not designed, licensed or intended for use
30 | in the design, construction, operation or maintenance of any military facility.
31 |
--------------------------------------------------------------------------------
/examples/painter/client/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | wsrpc - painter example
6 |
7 |
8 |
9 | {{ livereloadScript }}
10 |
11 |
12 | wsrpc on GitHub