1.7.0 • Published 2 years ago
@chipsgg/openservice-ws-server v1.7.0
Openservice Websocket Server
ratelimits, rpc, event batching, session management
Config Definition
{
port: 3000,
host: '127.0.0.1',
channels: ['public'],
rateLimitDuration: 1000,
rateLimitCount: 10,
parallel: 1,
batchTime: 1,
batchLength: 10,
}
Service Example
// service.js
module.exports = (config, services, emit) => {
const public = {
ping: ({ ... }) => {
return 'pong'
}
}
const actions = (sessionid, channel, action, args) => {
// call remote service
switch(channel) {
case 'public': {
return public(args)
}
}
}
// create server
const socket = await Socket(config, { actions }, (event, ...args) => {
switch(event){
case 'connect': {}
case 'disconnect': {}
case 'err': {}
default:
console.log(event, args)
}
});
return socket
}
API
socket.publish(channel, topic, args)
Publish events to active channel/topic subscribers.
socket.subscribe(topic, sessionid)
Subscribe a sessionid to events from a topic.
socket.unsubscribe(topic, sessionid)
Un-Subscribe a sessionid from events on a topic.
socket.send(channel, sessionid, args)
Send events to a sessionid on a channel.
socket.close()
Close the websocket server conenction.
socket.closeSession(sessionid)
Forcefully close a connection to a sessionid
socket.hasSession(sessionid)
Check if a sessionid is connected.
socket.listSessions()
List all connected sessionids.
socket.cleanup()
Terminate broken session connections.
1.6.2
2 years ago
1.7.0
2 years ago
1.6.1
2 years ago
1.5.0
2 years ago
1.4.0
2 years ago
1.2.5
3 years ago
1.3.1
3 years ago
1.3.0
3 years ago
1.2.4
3 years ago
1.2.3
3 years ago
1.2.2
3 years ago
1.2.1
3 years ago
1.1.20
3 years ago
1.1.18
3 years ago
1.1.17
3 years ago
1.1.16
3 years ago
1.0.16
3 years ago
1.0.15
3 years ago
1.0.14
3 years ago
1.0.13
3 years ago
1.0.12
4 years ago
1.0.11
4 years ago
1.0.10
4 years ago
1.0.9
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago