-
Notifications
You must be signed in to change notification settings - Fork 1
DataChannel
send(text: string, to?: Endpoint): Promise<string>
on(event: DataChannelEvent, handler: DataChannelEventHandlers): void
Sends text to a specific endpoint in the call.
-
text
- The data to be sent through the data channel. -
to
- OptionalEndpoint
that should receive the text. If not specified, text is broadcast to all endpoints in the data channel.
-
Promise<string>
- Promise that resolves tostring
which represents the message ID.
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}`));
Configures the event handler for data channel events.
-
event
:DataChannelEvent
- Name of the data channel event. Allowed values are a subset ofDataChannelEvent
. -
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, theEndpoint
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 }
-
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}`)
})