Wraps a channel on a client bus.
import { Client } from '@cast-web/protocol'; import { ConnectionChannel, HeartbeatChannel, ReceiverChannel, Namespaces, } from '@cast-web/types'; const client = new Client(); // wait for the client to connect await client.connect({ host: '192.168.1.101' }); // create channels const connection = client.createChannel<ConnectionChannel>('sender-0', 'receiver-0', Namespaces.Connection, 'JSON'); const heartbeat = client.createChannel<HeartbeatChannel>('sender-0', 'receiver-0', Namespaces.Heartbeat, 'JSON'); const receiver = client.createChannel<ReceiverChannel>('sender-0', 'receiver-0', Namespaces.Receiver, 'JSON'); // listen to channel events (receiver as an example) receiver.on('connect', () => console.log('receiver connect')); receiver.on('close', () => console.log('receiver close')); receiver.on('error', error => console.log('receiver error:', error)); receiver.on('message', message => console.log('receiver message:', message)); // connect to the receiver connection.send({ type: 'CONNECT' }); // start the heartbeat setInterval(() => heartbeat.send({ type: 'PING' }), 5000);
Closes the channel
This is important to prevent EventEmitter leaks.
Sends data on the channel.
// ConnectionChannel connection.send({ type: 'CONNECT' });
depend on channel type
void
Decodes data received on a channel
JS expresion of the data.
Encodes data to be sent on a channel.
Encoded data.
Generated using TypeDoc
Wraps a channel on a client bus.