Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jrmi/wire.io
A client to client websocket channel that handle pub/sub and RPC calls like WAMP protocol. Based on socket.io.
https://github.com/jrmi/wire.io
client-side socket-io socketio websocket
Last synced: 2 months ago
JSON representation
A client to client websocket channel that handle pub/sub and RPC calls like WAMP protocol. Based on socket.io.
- Host: GitHub
- URL: https://github.com/jrmi/wire.io
- Owner: jrmi
- License: mit
- Created: 2020-06-09T19:55:42.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-11-13T09:15:28.000Z (about 1 year ago)
- Last Synced: 2024-10-11T03:19:01.976Z (3 months ago)
- Topics: client-side, socket-io, socketio, websocket
- Language: JavaScript
- Homepage:
- Size: 886 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Wire.io
A web client to client communication channel that mimic [WAMP protocol](https://wamp-proto.org/). You can pub/sub event and make RPC calls directly to other clients through a router.
Way mush simpler and light than Autobahn and don't need a fat router when you need something less powerfull. It based on
venerable and very useful [socket.io](https://socket.io/).Compatible with 2.X and 3.X version of socket.io.
## Usage
Wire.io rely on [socket.io](https://socket.io/) for server and client.
Launch the server without installing with npx:
```sh
npx wire.io # need npm v7 in order to work
```Launch using docker:
```sh
docker run --rm -p 4000:4000 jrmi/wire.io
```## Installation
```sh
npm install wire.io
```### Serve side code
If you want to integrate Wire.io to your existing server, follow this instructions:
```js
import express from 'express';
import { handleWire } from 'wire.io';var app = express();
var http = require('http').createServer(app);
var io = require('socket.io')(http);const port = process.env.PORT || 4000;
http.listen(port, () => {
console.log(`listening on *:${port}`);
});io.on('connection', (socket) => {
const options = { // This are defaults
log: console.log;
logPrefix = '[Wire] '
}
handleWire(socket, options); // Option is optionnal
});
```## Client side code
```js
import io from 'socket.io-client';
import { joinWire } from 'wire.io';const socket = io.connect("", {
'reconnection delay': 0,
'reopen delay': 0,
forceNew: true,
});// Create room object
const room = await joinWire({
socket: socket, // Socket io socket object
room: 'test', // Room name
onJoined = (room) => { // Callback when room is joined (Optionnal)
console.log("Connected to wire.io server with id ", room.userId);
},
onMaster = (room) => { // Callback if the user is the room master i.e. the first user (on next if first quit). (Optionnal)
console.log("You are now master of the room");
},
userId: "myuserid" // To force user id (Optionnal)
});```
## API
All calls are client side. Since you have the room instance you can comunicate with other client with this API.
### .publish("eventName", params, self=false)
Send an event to all other clients in room. Also to self if true.
`params` can be any js type that is serializable.### .subsribe("eventName", callback) -> unsubscribe callback
Subscribe the callback to an event. The callback receive the params data if any.
### .register("functionName", callback) -> unregister callback
Register a function to be called by other clients. If any client use `.call` with the same function name,
the callback will be called with the given parameters.### .call("functionName", params) -> call result
Call a previously registered function. Return the call result.
## Dev installation
First install dependencies:
```sh
npm ci
```Start the server in watch mode:
```sh
npm run dev
```Then run tests:
```sh
npm test
```