Home

ondatachannel

Ondatachannel is an event handler in the WebRTC API, attached to RTCPeerConnection. It fires when a data channel is created by the remote peer or when the local peer receives an inbound data channel. This event enables an application to configure and use the incoming RTCDataChannel for bidirectional data transfer.

When the event occurs, the event object includes a channel property, which is the RTCDataChannel associated

Usage typically involves assigning a function to the RTCPeerConnection’s ondatachannel handler. Within that handler, developers obtain

Compatibility and scope: ondatachannel is supported in major browsers that implement the WebRTC DataChannel API. It

with
the
newly
established
data
channel.
If
a
local
peer
creates
a
data
channel
via
createDataChannel
on
its
RTCPeerConnection,
the
remote
peer
will
receive
an
ondatachannel
event
for
the
inbound
channel.
Conversely,
the
local
peer
will
handle
its
own
data
channel
independently,
while
the
remote
side
handles
its
ondatachannel
event
for
the
channel
it
created.
the
RTCDataChannel
from
the
event
and
then
configure
its
event
listeners,
such
as
onopen,
onmessage,
onclose,
and
onerror.
Data
can
then
be
exchanged
using
the
channel’s
send
method
and
by
handling
incoming
messages
on
the
channel’s
onmessage
callback.
The
data
channel
transitions
through
a
lifecycle
from
opening
to
open,
enabling
reliable
or
unordered
data
transfer,
depending
on
the
channel’s
configuration.
plays
a
central
role
in
enabling
peer-to-peer
applications
such
as
file
transfer,
multiplayer
gaming,
and
real-time
messaging
by
coordinating
inbound
data
channels
established
during
signaling
and
negotiation.