Skip to content

Commit

Permalink
early draft of v4
Browse files Browse the repository at this point in the history
  • Loading branch information
fed135 committed Mar 18, 2020
1 parent e6191a5 commit aa5fe42
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions packages/kalm/src/components/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export function Client(params: ClientConfig, emitter: NodeJS.EventEmitter, handl
const channels: ChannelList = {};
const socket: Socket = params.transport(params, emitter);

if (!socket.connect) throw new Error('Transport is not valid, it may not have been invoked, see: https://github.com/kalm/kalm.js#documentation');
if (!socket.connect) {
throw new Error('Transport is not valid, it may not have been invoked, see: https://github.com/kalm/kalm.js#documentation');
}

function _createChannel(channel: string): Channel {
const channelEmitter: NodeJS.EventEmitter = new EventEmitter();
Expand All @@ -25,7 +27,9 @@ export function Client(params: ClientConfig, emitter: NodeJS.EventEmitter, handl
}

function _wrap(event: RawFrame): void {
const payload: Buffer = params.framing === 'kalm' ? serializeLegacy(event.frameId, channels[event.channel], event.packets) : Buffer.from(JSON.stringify({ frameId: event.frameId, channel: event.channel, packets: event.packets }));
const payload: Buffer = params.framing === 'kalm'
? serializeLegacy(event.frameId, channels[event.channel], event.packets)
: Buffer.from(JSON.stringify({ frameId: event.frameId, channel: event.channel, packets: event.packets }));
socket.send(handle, payload);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/kalm/src/components/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export function Provider(params: ClientConfig, emitter: NodeJS.EventEmitter): Pr
const connections = [];
const socket: Socket = params.transport(params, emitter);

if (!socket.bind) throw new Error('Transport is not valid, it may not have been invoked, see: https://github.com/kalm/kalm.js#documentation');
if (!socket.bind) {
throw new Error('Transport is not valid, it may not have been invoked, see: https://github.com/kalm/kalm.js#documentation');
}

function broadcast(channel: string, payload: Serializable): void {
connections.forEach(c => c.write(channel, payload));
Expand Down
4 changes: 3 additions & 1 deletion packages/kalm/src/kalm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ function validateOptions(options: ProviderConfig): void {
throw new Error(`Routine is not a function (${options.routine}), see: https://github.com/kalm/kalm.js#documentation`);
}
const testChannel = options.routine('test', {}, {}, {});
if (!testChannel.add) throw new Error('Routine is not valid, it may not have been invoked, see: https://github.com/kalm/kalm.js#documentation');
if (!testChannel.add) {
throw new Error('Routine is not valid, it may not have been invoked, see: https://github.com/kalm/kalm.js#documentation');
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/kalm/src/utils/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function serializeLegacy(frameId: number, channel: Channel, packets: Buff
...packets.map((packet: Buffer) => {
if (!(packet instanceof Buffer)) throw new Error(`Cannot send packet ${packet}. Must be of type Buffer`);
return Buffer.concat([doubleIndiceBuffer(packet.length), packet]);
})
}),
]);
}

Expand Down

0 comments on commit aa5fe42

Please sign in to comment.