Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Client

Manages socket connections and messages

example
import { Client } from '@cast-web/protocol';

const client = new Client();
// wait for the client to connect
await client.connect({ host: '192.168.1.101' });

client.on('connect', () => console.log('client connect'));
client.on('close', () => console.log('client close'));
client.on('error', error => console.log('client error:', error));
client.on('message', message => console.log('client message:', message));

// create channels here

Hierarchy

Index

Constructors

Methods

Constructors

constructor

Methods

close

  • close(): void
  • Closes the client connection

    remarks

    Important to prevent EventEmitter leaks.

    Returns void

connect

createChannel

  • createChannel<ChannelType>(sourceId: string, destinationId: string, namespace: Namespaces, encoding: "JSON"): Channel<ChannelType>
  • Creates a channel on the client. // TODO: reference Channel

    example
    import { ConnectionChannel, Namespaces } from '@cast-web/types';
    ...
    const connection = client.createChannel<ConnectionChannel>('sender-0', 'receiver-0', Namespaces.Connection, 'JSON');
    

    Type parameters

    • ChannelType: ConnectionChannel | HeartbeatChannel | MediaChannel | ReceiverChannel

    Parameters

    • sourceId: string
    • destinationId: string
    • namespace: Namespaces
    • encoding: "JSON"

    Returns Channel<ChannelType>

    Channel

send

  • send(baseCastMessage: CastMessageBase, data: CastMessages): void
  • Sends a message on the client connection.

    example
    import { Namespaces } from '@cast-web/types';
    ...
    this.bus.send({ 'sender-0', 'receiver-0', Namespaces.Connection }, JSON.stringify({ foo: 'bar' }));
    

    Parameters

    • baseCastMessage: CastMessageBase
    • data: CastMessages

    Returns void

Generated using TypeDoc