How to use the kalm.listen function in kalm

To help you get started, we’ve selected a few kalm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kalm / kalm.js / examples / chat_websocket / server.js View on Github external
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) => {
github kalm / kalm.js / examples / typescript / server.ts View on Github external
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);
  });

kalm

The socket optimizer

Apache-2.0
Latest version published 2 years ago

Package Health Score

54 / 100
Full package analysis