Tutorial: ChannelProvider.onConnection

ChannelProvider.onConnection

Register a listener that is called on every new client connection. It is passed the identity of the connecting client and a payload if it was provided to Channel.connect. If you wish to reject the connection, throw an error. Be sure to synchronously provide an onConnection upon receipt of the channelProvider to ensure all potential client connections are caught by the listener.

Because multiple clients can exist at the same name and uuid, in order to distinguish between individual clients, the identity argument in a provider's onConnection callback contains an endpointId property. When dispatching from a provider to a client, the endpointId property must be provided in order to send an action to a specific client.

Example

(async ()=> {
    const provider = await fin.InterApplicationBus.Channel.create('channelName');

    provider.onConnection(identity => {
        console.log('Client connected', identity);
    });
})();

Reject connection example

(async ()=> {
    const provider = await fin.InterApplicationBus.Channel.create('channelName');

    provider.onConnection(identity => {
        throw new Error('Connection Rejected');
    });
})();