Skip to content

Commit

Permalink
Merge pull request #20 from kalm/v3.2.0
Browse files Browse the repository at this point in the history
V3.2.0
  • Loading branch information
fed135 authored Oct 11, 2019
2 parents fac8047 + f583925 commit 55ce276
Show file tree
Hide file tree
Showing 72 changed files with 687 additions and 1,227 deletions.
5 changes: 3 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/*.min.js
*.js
examples
node_modules
node_modules
scripts
10 changes: 8 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"import/resolver": {
"node": {
"paths": ["packages"],
"extensions": [".js", ".json", ".ts"]
"extensions": [".ts", ".spec.ts"]
}
}
},
Expand All @@ -17,6 +17,12 @@
"object-curly-newline": 0,
"no-plusplus": 0,
"no-unused-expressions": 0,
"guard-for-in": 0,
"no-mixed-operators": 0,
"no-param-reassign": 0,
"arrow-parens": [2, "as-needed"],
"import/prefer-default-export": 0,
"no-continue": 0,
"no-unused-vars": 0,
"global-require": 0,
"@typescript-eslint/no-unused-vars": [
Expand All @@ -27,7 +33,7 @@
},
"env": {
"browser": true,
"mocha": true,
"jest": true,
"node": true
}
}
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,18 @@ NTH
docs
yarn.lock
package-lock.json
.vscode
.vscode

# built code
packages/kalm/bin
packages/ipc/bin
packages/tcp/bin
packages/udp/bin
packages/ws/bin

# built types reference
packages/kalm/types.d.ts
packages/ipc/types.d.ts
packages/tcp/types.d.ts
packages/udp/types.d.ts
packages/ws/types.d.ts
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ tslint.json
package-lock.json
yarn.lock
.vscode
.github
.github
jest.config.js
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
language: node_js
cache: yarn
node_js:
- "12"
- "10"
- "8"
script:
- yarn run lint
- yarn run test
- yarn run build
- yarn run bench
sudo: false
install:
- yarn
before_install:
- npm install yarn@^1.13.0
- npm install yarn@^1.19.0
- yarn --version
5 changes: 3 additions & 2 deletions examples/chat/client.js → examples/chat_websocket/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const kalm = require('kalm');
const ws = require('@kalm/ws');

const { randomBytes } = require('crypto');

const Client = kalm.connect({
Expand All @@ -10,8 +11,8 @@ const Client = kalm.connect({
routine: kalm.routines.realtime(),
});

Client.subscribe('r.evt', (evt, frame) => console.log(`${evt.name}: ${evt.msg}`, frame));
Client.subscribe('r.sys', (evt, frame) => console.log(`[System]: ${evt.msg}`, frame));
Client.subscribe('r.evt', (body, frame) => console.log(`${body.name}: ${body.msg}`, frame));
Client.subscribe('r.sys', (body, frame) => console.log(`[System]: ${body.msg}`, frame));

Client.on('connect', () => {
Client.write('c.evt', { name: Client.label, msg: 'Hey everyone!' });
Expand Down
4 changes: 2 additions & 2 deletions examples/chat/server.js → examples/chat_websocket/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const Server = kalm.listen({
});

Server.on('connection', (client) => {
client.subscribe('c.evt', (msg, evt) => {
Server.broadcast('r.evt', msg);
client.subscribe('c.evt', (body, frame) => {
Server.broadcast('r.evt', body);
});

Server.broadcast('r.sys', { msg: 'user joined' });
Expand Down
23 changes: 23 additions & 0 deletions examples/compression/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const kalm = require('kalm');
const ws = require('@kalm/ws');
const snappy = require('snappy');

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

Client.subscribe('foo', (body, frame) => {
snappy.uncompress(body, (decompressedMessage) => {
console.log('Server event', decompressedMessage, frame);
});
});

const payload = {
foo: 'bar',
message: 'hello from the client!',
};

Client.write('foo', snappy.compressSync(Buffer.from(JSON.stringify(payload))));
27 changes: 27 additions & 0 deletions examples/compression/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const kalm = require('kalm');
const ws = require('@kalm/ws');
const snappy = require('snappy');

const provider = kalm.listen({
label: 'internal',
transport: ws(),
port: 3000,
json: false,
routine: kalm.routines.realtime(),
host: '0.0.0.0', // Apply local ip
});

provider.on('connection', (client) => {
client.subscribe('foo', (body, frame) => {
snappy.uncompress(body, (decompressedMessage) => {
console.log('Client event', decompressedMessage, frame);
});
});

const payload = {
foo: 'bar',
message: 'hello from the server!',
};

client.write('foo', snappy.compressSync(Buffer.from(JSON.stringify(payload))));
});
4 changes: 2 additions & 2 deletions examples/distributed_pub_sub/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const Client = kalm.connect({
routine: kalm.routines.realtime(),
});

Client.subscribe('r.evt', (evt, frame) => {
console.log('Relayed event', evt, frame);
Client.subscribe('r.evt', (body, frame) => {
console.log('Relayed event', body, frame);
});

// now send some events
Expand Down
16 changes: 8 additions & 8 deletions examples/distributed_pub_sub/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ providers.forEach((provider) => {

provider.on('connection', (client) => {
if (isIntern) {
client.subscribe('n.add', (msg, evt) => {
client.subscribe('n.add', (body, frame) => {
if (isSeed) {
provider.broadcast('n.add', msg);
} else provider.connect(evt.remote);
provider.broadcast('n.add', body);
} else provider.connect(frame.remote);
});
client.subscribe('n.evt', (msg, evt) => {
client.subscribe('n.evt', (body, frame) => {
providers.forEach((_provider) => {
if (_provider.label === 'external') {
_provider.broadcast('r.evt', msg);
_provider.broadcast('r.evt', body);
}
});
});
} else {
client.subscribe('c.evt', (msg, evt) => {
client.subscribe('c.evt', (body, frame) => {
providers.forEach((_provider) => {
if (_provider.label === 'internal') {
_provider.broadcast('n.evt', msg);
_provider.broadcast('n.evt', body);
} else {
_provider.broadcast('r.evt', msg);
_provider.broadcast('r.evt', body);
}
});
});
Expand Down
19 changes: 19 additions & 0 deletions examples/typescript/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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!');
28 changes: 28 additions & 0 deletions examples/typescript/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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 = {
foo: 'bar',
message: 'hello from the server!',
};

client.write('foo', payload);
});

9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
globals: {
'ts-jest': {
diagnostics: false,
},
},
};
43 changes: 26 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "kalm-lerna",
"private": true,
"version": "3.1.2",
"version": "3.2.0",
"description": "The socket optimizer",
"main": "packages/kalm/bin/kalm.js",
"scripts": {
"lint": "eslint .",
"lint": "eslint **/*.ts **/*.spec.ts",
"lint:fix": "yarn lint --fix",
"test": "yarn workspaces run test --ci && mocha ./tests/integration --exit",
"test": "jest ./packages && jest ./tests/integration --forceExit",
"build": "yarn workspaces run build --ci",
"clean": "yarn workspaces run clean --ci",
"bench": "node ./scripts/benchmarks"
},
"repository": {
Expand All @@ -24,20 +25,28 @@
"contributors": [
"frederic charette <[email protected]>"
],
"typings": "./types.ts",
"workspaces": [ "packages/*" ],
"typings": "./types.d.ts",
"workspaces": [
"packages/*"
],
"husky": {
"hooks": {
"pre-commit": "yarn lint"
}
},
"devDependencies": {
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "^1.10.2",
"@typescript-eslint/parser": "^1.10.0",
"chai": "^4.2.0",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.8.0",
"mocha": "^6.1.0",
"rollup": "^1.15.0",
"socket.io": "^2.2.0",
"socket.io-client": "^2.2.0",
"typescript": "^3.5.0"
"@types/jest": "^24.0.17",
"@types/node": "^12.7.0",
"@typescript-eslint/eslint-plugin": "^2.3.0",
"@typescript-eslint/parser": "^2.3.0",
"eslint": "^6.5.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.18.0",
"husky": "^3.0.8",
"jest": "^24.9.0",
"socket.io": "^2.3.0",
"socket.io-client": "^2.3.0",
"ts-jest": "^24.1.0",
"typescript": "^3.6.0"
}
}
59 changes: 0 additions & 59 deletions packages/ipc/bin/ipc.min.js

This file was deleted.

Loading

0 comments on commit 55ce276

Please sign in to comment.