How to use @kalm/ws - 2 common examples

To help you get started, we’ve selected a few @kalm/ws 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 / typescript / client.ts View on Github external
import kalm from 'kalm';
import ws from '@kalm/ws';

const client = kalm.connect({
  transport: ws(),
  port: 3938,
  routine: kalm.routines.realtime(),
});

type MyCustomPayload = {
  foo: string
  message: string
};

client.subscribe('r.evt', (body: MyCustomPayload, frame) => {
  console.log('Server event', body, frame);
});

client.write('c.evt', 'hello world!');
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);
  });

  const payload: MyCustomPayload = {

@kalm/ws

WebSocket transport for Kalm

Apache-2.0
Latest version published 1 year ago

Package Health Score

61 / 100
Full package analysis

Popular @kalm/ws functions