Skip to content

Commit f8816cc

Browse files
authored
V8.0.0 (#44)
* updating toolchain, documentation, fixing WS and WebRTC * major overhaul * fixed linting, types, tests * fixed tests and udp events, removed node 18 support * finalized publish details and bumped engines requirements * fixed typos, example links and removed badges from readme * fixed ws for older node versions * replaced yarn with npm in GHA * fixed typo in GHA * replaced ts-node with tsx for benchmarks because esm * wrapped udp send
1 parent f016617 commit f8816cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1849
-1535
lines changed

.eslintignore

Lines changed: 0 additions & 6 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/master-status.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node-version: [14.x, 16.x, 18.x]
15+
node-version: [20.x, 22.x, 24.x]
1616

1717
steps:
1818
- uses: actions/checkout@v1
@@ -22,10 +22,10 @@ jobs:
2222
node-version: ${{ matrix.node-version }}
2323
- name: npm install, build, and test
2424
run: |
25-
yarn
26-
yarn run build
27-
yarn run lint
28-
yarn run test
29-
yarn run bench
25+
npm i
26+
npm run build
27+
npm run lint
28+
npm run test
29+
npm run bench
3030
env:
3131
CI: true

.github/workflows/pr-validation.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node-version: [18.x, 20.x]
15+
node-version: [20.x, 22.x, 24.x]
1616

1717
steps:
1818
- uses: actions/checkout@v1
@@ -22,10 +22,10 @@ jobs:
2222
node-version: ${{ matrix.node-version }}
2323
- name: npm install, build, and test
2424
run: |
25-
yarn
26-
yarn run build
27-
yarn run lint
28-
yarn run test
29-
yarn run bench
25+
npm i
26+
npm run build
27+
npm run lint
28+
npm run test
29+
npm run bench
3030
env:
3131
CI: true

.gitignore

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,25 @@ packages/ipc/bin
4949
packages/tcp/bin
5050
packages/udp/bin
5151
packages/ws/bin
52-
packages/webrtc/bin
52+
53+
# distribution code
54+
packages/kalm/dist
55+
packages/ipc/dist
56+
packages/tcp/dist
57+
packages/udp/dist
58+
packages/ws/dist
5359

5460
# publish-only files
5561
packages/kalm/LICENSE
5662
packages/ipc/LICENSE
5763
packages/tcp/LICENSE
5864
packages/udp/LICENSE
5965
packages/ws/LICENSE
60-
packages/webrtc/LICENSE
6166

6267
packages/kalm/CHANGELOG.md
6368
packages/ipc/CHANGELOG.md
6469
packages/tcp/CHANGELOG.md
6570
packages/udp/CHANGELOG.md
6671
packages/ws/CHANGELOG.md
67-
packages/webrtc/CHANGELOG.md
72+
73+
packages/kalm/types.d.ts

CHANGELOG.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
# Changelog
22

3-
## [v7.0.0] - 2023-03-17
3+
## [v8.0.0] - 2025-07-30
44

55
commit [#](https://github.com/kalm/kalm.js/commits)
66

7+
### Breaking changes
8+
9+
- Updated bundling for greater compatibility (exports *may* behave differently)
10+
- Deprecated the WebRTC Transport (too convoluted to fit the Kalm model)
11+
- Changed the signature of the `frame` event handler from `(frame: RawFrame, payloadBytes: number)` to `({ body: RawFrame, payloadBytes: number})` to ensure all event handlers only have one arguments.
12+
13+
### Minor changes
14+
15+
- Added support for the new native WS APIs in Node 22 and later
16+
- Removed yarn from the toolchain. There's no reason to keep it now that NPM workspaces are more mature.
17+
- Deprecated the `agent` property for the WS Transport
18+
- Migrated the underlying Node EventEmitter to the cross-platform EventTarget system. A translation layer should keep end-user code intact.
19+
- Fixed server connections not getting cleaned up
20+
- Removed empty channels from frame payloads, saving bandwidth
21+
- Changed the subscribe handler's second argument name from `frame` to `context`, to reduce confusion with its nested `frame` property.
22+
- Fixed missing UDP client `connect` event.
23+
- Removed the potentially misleading argument in the `connect` event since it only exposes the unbound socket.
24+
- Bumped engines requirement to Node 20.x
25+
26+
27+
## [v7.0.0] - 2023-03-17
28+
29+
commit [99a3ab9](https://github.com/kalm/kalm.js/commit/99a3ab9c495f6f50d7d4b4a0f478a213cc0ce484)
30+
731
### Major changes
832

933
- Standardized parameter names and expected behavior

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2023 Frederic Charette
1+
Copyright 2025 Frederic Charette
22

33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.

eslint.config.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import eslint from '@eslint/js';
2+
import { globalIgnores } from 'eslint/config';
3+
import tseslint from 'typescript-eslint';
4+
import jestConfig from 'eslint-plugin-jest';
5+
import spacing from '@stylistic/eslint-plugin';
6+
7+
export default tseslint.config(
8+
eslint.configs.recommended,
9+
tseslint.configs.recommended,
10+
jestConfig.configs['flat/recommended'],
11+
spacing.configs.recommended,
12+
{
13+
rules: {
14+
'@stylistic/semi': [2, 'always'],
15+
'@typescript-eslint/no-explicit-any': 0,
16+
'@typescript-eslint/no-require-imports': 1,
17+
'jest/no-done-callback': 0,
18+
'jest/no-conditional-expect': 0,
19+
},
20+
},
21+
globalIgnores(['**/bin', '**/dist', '**/*.js']),
22+
);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Binary messages and compression example
2+
3+
This example shows how to send binary messages and how to add compression.
4+
5+
# Requirements
6+
7+
- The clients can run in either the browser or in Node.js.
8+
- The server must run in a Node.js environment.
9+
- NPM or other package manager to install `kalm`, `@kalm/ws` and the compression library of your choice. In this example, we are using `snappy`.
10+
11+
# Testing
12+
13+
Launch the server first:
14+
15+
```
16+
node ./server.js
17+
```
18+
19+
It should log that the server is ready to receive new connections. At this stage, launch any number of clients:
20+
21+
```
22+
node ./client.js
23+
```
24+
25+
The clients should connect to the server and send an "hello world!" message.
26+
27+
In turn, the server will both respond to that client: "hello from the server!" and broadcast to all clients "A new client has connected!"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { connect, routines } from 'kalm';
2+
import ws from '@kalm/ws';
3+
import { compressSync, uncompress } from 'snappy';
4+
5+
/**
6+
* Creates a kalm client that uses the Websocket transport.
7+
* It will attempt to connect to a server located at the address '0.0.0.0' on port 3938.
8+
*
9+
* The realtime routine will emit messages as soon as possible. While this is ideal in a few scenarios, for instance when the client does not send a lot of events,
10+
* it does not leverage the benefits of buffering and may cause slowdowns if many messages are sent rapidly.
11+
*
12+
* To ensure that the message sent is not coerced into JSON, we must pass the `json:false` parameter.
13+
*/
14+
const client = connect({
15+
transport: ws({}),
16+
json: false,
17+
port: 3938,
18+
host: '0.0.0.0',
19+
routine: routines.realtime(),
20+
});
21+
22+
/**
23+
* An example interface for messages sent between client and server
24+
*/
25+
type MyCustomPayload = {
26+
message: string
27+
};
28+
29+
/**
30+
* To confirm that the client has succesfully connected to the server, listen to the 'connect' event.
31+
*/
32+
client.on('connect', () => {
33+
/**
34+
* Once a client has connected, we subscribe to messages sent on the "foo" channel.
35+
*/
36+
client.subscribe('foo', (body: Buffer, context) => {
37+
/**
38+
* When we receive a message on the foo channel, we also receive information about the frame and context.
39+
* We'll need to decompress the buffer to read it.
40+
*
41+
* body: <Buffer>
42+
* context: {
43+
* client: <Client>,
44+
* frame: {
45+
* channel: "foo",
46+
* id: 1,
47+
* messageIndex: 1,
48+
* payloadBytes: 22,
49+
* payloadMessages: 1,
50+
* }
51+
* }
52+
*/
53+
uncompress(body).then((decompressedMessage) => {
54+
console.log('Server event', JSON.parse(decompressedMessage.toString()) as MyCustomPayload, context);
55+
});
56+
});
57+
58+
/**
59+
* To send messages from the client to the server, simply `write` to the desired channel.
60+
*/
61+
client.write('foo', compressSync(Buffer.from(JSON.stringify({ message: 'hello world!' }))));
62+
});

0 commit comments

Comments
 (0)