7.0.0 • Published 1 year ago

kalm v7.0.0

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
1 year ago

Kalm Build Status Snyk Vulnerabilities for GitHub Repo Financial Contributors on Open Collective

Join the chat at https://gitter.im/KALM/home

  • Easy-to-use syntax unified across protocols
  • Flexible and extensible, create your own transports and buffering strategies
  • Can be used between servers or in the browser
  • Lower resource footprint and better throughtput than plain sockets
  • Zero dependencies and can be bundled down to ~5kb!

Performance

The performance gain comes from buffering packets before sending them- eventually sending batches instead of individual packages. The more traffic getting processed, the better the improvement. Many strategies are offered as routines. You can read more about the packet buffering algorithm here

Install

Install the core package

npm install kalm

Install the transport layer ('tcp' for example)

npm install @kalm/tcp

Usage

Server

const kalm = require('kalm');
const ws = require('@kalm/ws');

const server = kalm.listen({
  port: 8800,
  transport: ws(),
  routine: kalm.routines.tick({ hz: 5 }), // Sends packets at a frequency of 5 Hz (200ms)
  host: '0.0.0.0',
});

server.on('connection', (client) => {
  client.subscribe('my-channel', (body, frame) => {
    // Handle messages here
  });

  server.broadcast('my-other-channel', 'some message');
});

Client

const kalm = require('kalm');
const ws = require('@kalm/ws');

const client = kalm.connect({
  host: '0.0.0.0',
  port: 8800,
  transport: ws(),
  routine: kalm.routines.realtime(),
});

client.on('connect', () => {
  client.subscribe('my-other-channel', (body, frame) => {
    // Handle messages here
  });

  client.write('my-channel', 'hello world');
});

To see working implementations, check out our examples folder.

Documentation

[Read more]

Logging

Kalm uses the NODE_DEBUG environment variable. Just include kalm in your value.

Example:

NODE_DEBUG=net,kalm node myApp.js

Events

Kalm offers events to track when packets are processed by routines or when a raw frame is received.

EventPayloadDescription
errorError(server, client) Emits on errors.
readyvoid(server) Indicates that the server is now actively listeneing for new connections
connectionClient(server) Indicates that a client has successfuly connected
connectClient(client) Indicates that a client has successfuly connected
disconnectvoid(client) Indicates that a client has disconnected
frameRawFrame(client) Triggered when recieving a parsed full frame.

Testing

npm test

npm run bench

Contribute

If you think of something that you want, open an issue or file a pull request, we'll be more than happy to take a look!

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

Apache 2.0 (c) 2023 Frederic Charette

7.0.0

1 year ago

6.0.0

3 years ago

5.0.0

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.3.0

4 years ago

3.2.3

4 years ago

3.2.2

4 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.6.1

6 years ago

2.6.0

6 years ago

2.5.1

7 years ago

2.5.0

7 years ago

2.4.0

7 years ago

2.3.0

7 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

1.5.1

7 years ago

2.0.0

7 years ago

1.5.0

7 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.0.4

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

9 years ago

1.0.1

9 years ago

0.0.1

9 years ago

1.0.0

9 years ago