A web client to client communication channel that mimic WAMP protocol. 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.
Compatible with 2.X and 3.X version of socket.io.
Wire.io rely on socket.io for server and client.
Launch the server without installing with npx:
npx wire.io # need npm v7 in order to work
Launch using docker:
docker run --rm -p 4000:4000 jrmi/wire.io
npm install wire.io
If you want to integrate Wire.io to your existing server, follow this instructions:
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
});
import io from 'socket.io-client';
import { joinWire } from 'wire.io';
const socket = io.connect("<socket server url>", {
'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)
});
All calls are client side. Since you have the room instance you can comunicate with other client with this API.
Send an event to all other clients in room. Also to self if true.
params
can be any js type that is serializable.
Subscribe the callback to an event. The callback receive the params data if any.
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 a previously registered function. Return the call result.
First install dependencies:
npm ci
Start the server in watch mode:
npm run dev
Then run tests:
npm test