Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const kalm = require('kalm');
const ws = require('@kalm/ws');
const Server = kalm.listen({
label: 'server',
port: 8800,
transport: ws(),
routine: kalm.routines.tick(5), // Hz
host: '0.0.0.0',
});
Server.on('connection', (client) => {
client.subscribe('c.evt', (body, frame) => {
Server.broadcast('r.evt', body);
});
Server.broadcast('r.sys', { msg: 'user joined' });
});
Server.on('deconnection', (client) => {
import kalm from 'kalm';
import ws from '@kalm/ws';
const provider = kalm.listen({
transport: ws(),
port: 3938,
routine: kalm.routines.tick(5),
host: '0.0.0.0',
});
type MyCustomPayload = {
foo: string
message: string
};
provider.on('connection', (client) => {
client.subscribe('foo', (body: MyCustomPayload, frame) => {
console.log('Client event', body, frame);
});