Events

Managing the Notifications Connection

By default, the VoiceLayer SDK will manage the connection to the VoiceLayer server for receiving notifications for you. After successfully logging in the SDK will connect and begin listening for notifications. Upon logging out the SDK will automatically disconnect. Additionally if the device loses it's network connection the SDK will automatically reconnect when the connection is restored.

If you would like to manually manage this connection you can do so using the connect and disconnect methods on the VoiceLayerClient:

// Start listening for notifications
client.connect();

// Stop listening for notifications
client.disconnect();

Subscribing to Events

To receive events for channels you are associated with you should first subscribe to channel notifications:

VoiceLayerChannel channel = channel.subscribe();

or

channel.subscribe(new VoiceLayerChannelSubscriptionCallback() {

    @Override
    public void onSubscribedToChannelEvents(VoiceLayerChannel channel, VoiceLayerException exception) {

    }

    @Override
    public void onUnsubscribeFromChannelEvents(VoiceLayerChannel channel, VoiceLayerException exception) {

    }

});

If you no longer wish to receive channel events for a specific channel you can unsubscribe from events as follows:

VoiceLayerChannel channel = channel.unsubscribe();

or

channel.unsubscribe(new VoiceLayerChannelSubscriptionCallback() {

    @Override
    public void onSubscribedToChannelEvents(VoiceLayerChannel channel, VoiceLayerException exception) {

    }

    @Override
    public void onUnsubscribeFromChannelEvents(VoiceLayerChannel channel, VoiceLayerException exception) {

    }

});