Files
webrtc/rtcdatachannel.go
Sean DuBois 22bd31d006 Fix all races in example applications
* Add locking around SCTP Assocation
* Add locking around DataChannel
* Add locking around port+global ICE

Closes #46
2018-07-26 00:46:45 -07:00

29 lines
690 B
Go

package webrtc
import (
"sync"
"github.com/pions/webrtc/pkg/datachannel"
)
// RTCDataChannel represents a WebRTC DataChannel
// The RTCDataChannel interface represents a network channel
// which can be used for bidirectional peer-to-peer transfers of arbitrary data
type RTCDataChannel struct {
sync.RWMutex
Onmessage func(datachannel.Payload)
ID uint16
Label string
rtcPeerConnection *RTCPeerConnection
}
// Send sends the passed message to the DataChannel peer
func (r *RTCDataChannel) Send(p datachannel.Payload) error {
if err := r.rtcPeerConnection.networkManager.SendDataChannelMessage(p, r.ID); err != nil {
return &UnknownError{Err: err}
}
return nil
}