Skip to content

Commit

Permalink
updated READMEs, added description in ts definitions, fixed bugs in tick
Browse files Browse the repository at this point in the history
  • Loading branch information
fed135 committed Mar 17, 2023
1 parent b46e775 commit cb50c29
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 48 deletions.
35 changes: 34 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
# Changelog

## [v7.0.0] - 2023-03-17

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

### Major changes

- Standardized parameter names and expected behavior
- Removed `secure` WS option, instead checking if `cert` and `key` are set
- Routines.dynamic option `hz` is now `maxInterval` and is measured in milliseconds
- Renamed `provider` internally to `server` for easier understanding
- Removed previously deprecated UDP `connectTimeout` option
- Added UDP idle timeout behavior
- Added WS idle timeout behavior
- Added WS Agent option for proxying
- frameId counter now goes up to 0xffffffff before cycling instead of 0xffff

### Bug fixes

- Fixed an issue in Routines.tick where all queues shared the same frameId counter
- Routines.tick option `seed` now correctly sets the `frameId` and starts the counter to match the expected pace
- Fixed references to Node modules in TS definitions

## [v6.1.0] - 2022-09-21

commit [a0e88e3](https://github.com/kalm/kalm.js/commit/a0e88e310d98646b53fbcc56f6efeea4db5e87d8)

### Major changes

- Removed SYN/ACK UDP handshake, which removes the socket timeout behaviour for that transport
- Added error event for UDP packet over the safe limit (16384 bytes), previous behaviour was to crash silently
- Routines are no longer event emitters, but have a size function


## [v6.0.0] - 2021-04-26

commit: [#](https://github.com/kalm/kalm.js/commits)
commit: [47b810d](https://github.com/kalm/kalm.js/commit/47b810d5ab212686c3194d53e781e1728bd735f9)

### Breaking changes

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2022 Frederic Charette
Copyright 2023 Frederic Charette

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

| Version | Supported |
| ------- | ------------------ |
| 7.x | :white_check_mark: |
| 6.x | :white_check_mark: |
| 5.x | :white_check_mark: |
| <= 4.x | :x: |
| <= 5.x | :x: |

## Reporting a Vulnerability

Expand Down
4 changes: 2 additions & 2 deletions packages/kalm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
---

- **Easy-to-use syntax** unified across protocols
- Flexible and extensible, load your own transports and routines
- 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!
Expand Down Expand Up @@ -166,4 +166,4 @@ Support this project with your organization. Your logo will show up here with a

## License

[Apache 2.0](LICENSE) (c) 2022 Frederic Charette
[Apache 2.0](LICENSE) (c) 2023 Frederic Charette
12 changes: 6 additions & 6 deletions packages/kalm/src/routines/dynamic.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export function dynamic({
hz,
maxInterval,
maxPackets = Infinity,
maxBytes = Infinity,
}: { hz: number, maxPackets?: number, maxBytes?: number }): KalmRoutine {
if (hz <= 0 || hz > 1000) {
throw new Error(`Unable to set Hertz value of ${hz}. Must be between 0.1e13 and 1000`);
}: { maxInterval: number, maxPackets?: number, maxBytes?: number }): KalmRoutine {
if (maxInterval < 1) {
throw new Error(`Unable to set millisecond value of ${maxInterval}. Must be above or equal to 1`);
}

return function queue(params: any, routineEmitter: (frameId: number) => any): Queue {
Expand All @@ -17,7 +17,7 @@ export function dynamic({
clearTimeout(timer);
timer = null;
routineEmitter(frameId);
if (++frameId > 0xffff) frameId = 0;
if (++frameId > 0xffffffff) frameId = 0;
numPackets = 0;
totalBytes = 0;
}
Expand Down Expand Up @@ -48,7 +48,7 @@ export function dynamic({
}

if (timer === null) {
timer = setTimeout(_step, Math.round(1000 / hz));
timer = setTimeout(_step, maxInterval);
}

_add(packet);
Expand Down
4 changes: 2 additions & 2 deletions packages/kalm/src/routines/realtime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function realtime(): KalmRoutine {
return function queue(params: { deferred: boolean }, routineEmitter: (frameId: number) => any): Queue {
return function queue(params: { deferred: boolean } = { deferred: false }, routineEmitter: (frameId: number) => any): Queue {
let frameId = 0;

function add(): void {
Expand All @@ -13,7 +13,7 @@ export function realtime(): KalmRoutine {

function _step() {
routineEmitter(frameId);
if (++frameId > 0xffff) frameId = 0;
if (++frameId > 0xffffffff) frameId = 0;
}

function flush(): void {}
Expand Down
16 changes: 11 additions & 5 deletions packages/kalm/src/routines/tick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@ export function tick({ hz, seed = 0 }: { hz: number, seed?: number }): KalmRouti
throw new Error(`Unable to set Hertz value of ${hz}. Must be between 0.1e13 and 1000`);
}

let frameId: number = seed || 0;

return function queue(params: object, routineEmitter: (frameId: number) => any): Queue {
let timer: ReturnType<typeof setTimeout> = null;
const adjustedTime = seed ? Date.now() - seed : 0;
let frameId = Math.floor(adjustedTime / (1000 / hz)) % 0xffffffff;

let timer: ReturnType<typeof setTimeout> = setTimeout(_init, adjustedTime % Math.round(1000 / hz));
let numPackets = 0;

function _step(): void {
frameId++;
routineEmitter(frameId);
numPackets = 0;
if (++frameId > 0xffffffff) frameId = 0;
}

function _init(): void {
clearTimeout(timer);
timer = setInterval(_step, Math.round(1000 / hz));
_step();
}

function add(): void {
numPackets++;
if (timer === null) timer = setInterval(_step, 1000 / hz);
}

return { add, flush: _step, size: () => numPackets };
Expand Down
Loading

0 comments on commit cb50c29

Please sign in to comment.