Skip to content

DataChannel

Ajša Terko edited this page Feb 15, 2024 · 7 revisions



send(text, to)

Description

Sends text to a specific endpoint in the call.

Arguments

  • text - The data to be sent through the data channel.
  • to - Optional Endpoint that should receive the text. If not specified, text is broadcast to all endpoints in the data channel.

Returns

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();

let roomCall = infobipRTC.joinRoom('test_room', RoomCallOptions.builder().setDataChannel(true).build());
roomCall.dataChannel()
    .send('Hello world!')
    .then(id => console.log(`Sent text with id: ${id}`));



on(event, handler)

Description

Configures the event handler for data channel events.

Arguments

  • event: DataChannelEvent - Name of the data channel event. Allowed values are a subset of DataChannelEvent.

  • handler: DataChannelEventHandlers - Function that will be called when specified event occurs, with exactly one parameter being passed to the function containing event information. Depending on the event, the passed parameter will contain a set of fields that will describe the event, namely:

    • TEXT_DELIVERED_EVENT - The data received in this event includes: the ID associated with the text, the date, and a boolean representing whether the text was delivered successfully or not.

      event = { id: string, date: Date, delivered: boolean }
    • TEXT_RECEIVED_EVENT - The data received in this event includes: the text, the Endpoint representing the sender, a boolean which represents whether the text is sent directly to its recipient or not, and the date.

      event = { text: string, from: Endpoint, isDirect: boolean, date: Date }
    • BROADCAST_TEXT_RECEIVED_EVENT - The data received in this event includes: the text and the date.

      event = { text: string, date: Date }

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();

let roomCall = infobipRTC.joinRoom('test_room', RoomCallOptions.builder().setDataChannel(true).build());
let dataChannel = roomCall.dataChannel();

dataChannel.on(DataChannelEvent.TEXT_DELIVERED_EVENT, (event) => {
    let delivered = event.delivered ? 'delivered' : 'not delivered';
    console.log(`Text with id ${event.id} was ${delivered}.`);
})

dataChannel.on(DataChannelEvent.TEXT_RECEIVED_EVENT, (event) => {
    console.log(`Received text ${event.text} from ${event.from.identifier}.`)
});

dataChannel.on(DataChannelEvent.BROADCAST_TEXT_RECEIVED_EVENT, (event) => {
    console.log(`Received broadcast: ${event.text}`)
})

Tutorials

Migration guides

Reference documentation

Clone this wiki locally