Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jnordberg/wsrpc
node.js/browser protobuf rpc over binary websockets
https://github.com/jnordberg/wsrpc
browser nodejs rpc websockets
Last synced: 25 days ago
JSON representation
node.js/browser protobuf rpc over binary websockets
- Host: GitHub
- URL: https://github.com/jnordberg/wsrpc
- Owner: jnordberg
- License: other
- Created: 2017-04-28T15:12:57.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T18:55:57.000Z (about 2 years ago)
- Last Synced: 2024-04-15T00:01:14.372Z (10 months ago)
- Topics: browser, nodejs, rpc, websockets
- Language: TypeScript
- Homepage: https://jnordberg.github.io/wsrpc/
- Size: 2.3 MB
- Stars: 102
- Watchers: 7
- Forks: 11
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [wsrpc](https://github.com/jnordberg/wsrpc) [![Build Status](https://img.shields.io/travis/jnordberg/wsrpc.svg?style=flat-square)](https://travis-ci.org/jnordberg/wsrpc) [![Coverage Status](https://img.shields.io/coveralls/jnordberg/wsrpc.svg?style=flat-square)](https://coveralls.io/github/jnordberg/wsrpc?branch=master) [![Package Version](https://img.shields.io/npm/v/wsrpc.svg?style=flat-square)](https://www.npmjs.com/package/wsrpc) ![License](https://img.shields.io/npm/l/wsrpc.svg?style=flat-square)
node.js/browser protobuf rpc over binary websockets.
* **[Demo](https://johan-nordberg.com/wspainter)** ([source](https://github.com/jnordberg/wsrpc/tree/master/examples/painter))
* [Documentation](https://jnordberg.github.io/wsrpc/)
* [Issues](https://github.com/jnordberg/wsrpc/issues)---
Minimal example
---------------my-service.proto
```protobuf
service MyService {
rpc SayHello (HelloRequest) returns (HelloResponse) {}
}message HelloRequest {
required string name = 1;
}message HelloResponse {
required string text = 1;
}
```server.js
```typescript
const wsrpc = require('wsrpc')
const protobuf = require('protobufjs')const proto = protobuf.loadSync('my-service.proto')
const server = new wsrpc.Server(proto.lookupService('MyService'), { port: 4242 })
server.implement('sayHello', async (request) => {
return {text: `Hello ${ request.name }!`}
})
```client.js
```typescript
const wsrpc = require('wsrpc')
const protobuf = require('protobufjs')const proto = protobuf.loadSync('my-service.proto')
const client = new wsrpc.Client('ws://localhost:4242', proto.lookupService('MyService'))
const response = await client.service.sayHello({name: 'world'})
console.log(response) // Hello world!
```