Documentation ¶
Overview ¶
Package datachannel implements WebRTC Data Channels
Index ¶
- Constants
- Variables
- func TryMarshalUnmarshal(msg []byte) int
- type ChannelType
- type Config
- type DataChannel
- func Accept(a *sctp.Association, config *Config, existingChannels ...*DataChannel) (*DataChannel, error)
- func Client(stream *sctp.Stream, config *Config) (*DataChannel, error)
- func Dial(a *sctp.Association, id uint16, config *Config) (*DataChannel, error)
- func Server(stream *sctp.Stream, config *Config) (*DataChannel, error)
- func (c *DataChannel) BufferedAmount() uint64
- func (c *DataChannel) BufferedAmountLowThreshold() uint64
- func (c *DataChannel) BytesReceived() uint64
- func (c *DataChannel) BytesSent() uint64
- func (c *DataChannel) Close() error
- func (c *DataChannel) MessagesReceived() uint32
- func (c *DataChannel) MessagesSent() uint32
- func (c *DataChannel) OnBufferedAmountLow(f func())
- func (c *DataChannel) OnOpen(f func())
- func (c *DataChannel) Read(p []byte) (int, error)
- func (c *DataChannel) ReadDataChannel(p []byte) (int, bool, error)
- func (c *DataChannel) SetBufferedAmountLowThreshold(th uint64)
- func (c *DataChannel) SetReadDeadline(t time.Time) error
- func (c *DataChannel) SetWriteDeadline(t time.Time) error
- func (c *DataChannel) StreamIdentifier() uint16
- func (c *DataChannel) Write(p []byte) (n int, err error)
- func (c *DataChannel) WriteDataChannel(p []byte, isString bool) (n int, err error)
- type ReadDeadliner
- type ReadWriteCloser
- type ReadWriteCloserDeadliner
- type Reader
- type WriteDeadliner
- type Writer
Constants ¶
const ( ChannelPriorityBelowNormal uint16 = 128 ChannelPriorityNormal uint16 = 256 ChannelPriorityHigh uint16 = 512 ChannelPriorityExtraHigh uint16 = 1024 )
ChannelPriority enums
Variables ¶
var ( // ErrDataChannelMessageTooShort means that the data isn't long enough to be a valid DataChannel message ErrDataChannelMessageTooShort = errors.New("DataChannel message is not long enough to determine type") // ErrInvalidPayloadProtocolIdentifier means that we got a DataChannel messages with a Payload Protocol Identifier // we don't know how to handle ErrInvalidPayloadProtocolIdentifier = errors.New("DataChannel message Payload Protocol Identifier is value we can't handle") // ErrInvalidChannelType means that the remote requested a channel type that we don't support ErrInvalidChannelType = errors.New("invalid Channel Type") // ErrInvalidMessageType is returned when a DataChannel Message has a type we don't support ErrInvalidMessageType = errors.New("invalid Message Type") // ErrExpectedAndActualLengthMismatch is when the declared length and actual length don't match ErrExpectedAndActualLengthMismatch = errors.New("expected and actual length do not match") // ErrUnexpectedDataChannelType is when a message type does not match the expected type ErrUnexpectedDataChannelType = errors.New("expected and actual message type does not match") )
Functions ¶
func TryMarshalUnmarshal ¶ added in v1.5.8
TryMarshalUnmarshal attempts to marshal and unmarshal a message. Added for fuzzing.
Types ¶
type ChannelType ¶
type ChannelType byte
ChannelType determines the reliability of the WebRTC DataChannel
const ( // ChannelTypeReliable determines the Data Channel provides a // reliable in-order bi-directional communication. ChannelTypeReliable ChannelType = 0x00 // ChannelTypeReliableUnordered determines the Data Channel // provides a reliable unordered bi-directional communication. ChannelTypeReliableUnordered ChannelType = 0x80 // ChannelTypePartialReliableRexmit determines the Data Channel // provides a partially-reliable in-order bi-directional communication. // User messages will not be retransmitted more times than specified in the Reliability Parameter. ChannelTypePartialReliableRexmit ChannelType = 0x01 // ChannelTypePartialReliableRexmitUnordered determines // the Data Channel provides a partial reliable unordered bi-directional communication. // User messages will not be retransmitted more times than specified in the Reliability Parameter. ChannelTypePartialReliableRexmitUnordered ChannelType = 0x81 // ChannelTypePartialReliableTimed determines the Data Channel // provides a partial reliable in-order bi-directional communication. // User messages might not be transmitted or retransmitted after // a specified life-time given in milli- seconds in the Reliability Parameter. // This life-time starts when providing the user message to the protocol stack. ChannelTypePartialReliableTimed ChannelType = 0x02 // The Data Channel provides a partial reliable unordered bi-directional // communication. User messages might not be transmitted or retransmitted // after a specified life-time given in milli- seconds in the Reliability Parameter. // This life-time starts when providing the user message to the protocol stack. ChannelTypePartialReliableTimedUnordered ChannelType = 0x82 )
ChannelType enums
func (ChannelType) String ¶ added in v1.5.6
func (c ChannelType) String() string
type Config ¶
type Config struct { ChannelType ChannelType Negotiated bool Priority uint16 ReliabilityParameter uint32 Label string Protocol string LoggerFactory logging.LoggerFactory }
Config is used to configure the data channel.
type DataChannel ¶
type DataChannel struct { Config // contains filtered or unexported fields }
DataChannel represents a data channel
func Accept ¶
func Accept(a *sctp.Association, config *Config, existingChannels ...*DataChannel) (*DataChannel, error)
Accept is used to accept incoming data channels over SCTP
func Client ¶
func Client(stream *sctp.Stream, config *Config) (*DataChannel, error)
Client opens a data channel over an SCTP stream
func Dial ¶
func Dial(a *sctp.Association, id uint16, config *Config) (*DataChannel, error)
Dial opens a data channels over SCTP
func Server ¶
func Server(stream *sctp.Stream, config *Config) (*DataChannel, error)
Server accepts a data channel over an SCTP stream
func (*DataChannel) BufferedAmount ¶ added in v1.3.0
func (c *DataChannel) BufferedAmount() uint64
BufferedAmount returns the number of bytes of data currently queued to be sent over this stream.
func (*DataChannel) BufferedAmountLowThreshold ¶ added in v1.3.0
func (c *DataChannel) BufferedAmountLowThreshold() uint64
BufferedAmountLowThreshold returns the number of bytes of buffered outgoing data that is considered "low." Defaults to 0.
func (*DataChannel) BytesReceived ¶ added in v1.4.4
func (c *DataChannel) BytesReceived() uint64
BytesReceived returns the number of bytes received
func (*DataChannel) BytesSent ¶ added in v1.4.4
func (c *DataChannel) BytesSent() uint64
BytesSent returns the number of bytes sent
func (*DataChannel) Close ¶
func (c *DataChannel) Close() error
Close closes the DataChannel and the underlying SCTP stream.
func (*DataChannel) MessagesReceived ¶ added in v1.4.4
func (c *DataChannel) MessagesReceived() uint32
MessagesReceived returns the number of messages received
func (*DataChannel) MessagesSent ¶ added in v1.4.4
func (c *DataChannel) MessagesSent() uint32
MessagesSent returns the number of messages sent
func (*DataChannel) OnBufferedAmountLow ¶ added in v1.3.0
func (c *DataChannel) OnBufferedAmountLow(f func())
OnBufferedAmountLow sets the callback handler which would be called when the number of bytes of outgoing data buffered is lower than the threshold.
func (*DataChannel) OnOpen ¶ added in v1.5.0
func (c *DataChannel) OnOpen(f func())
OnOpen sets an event handler which is invoked when a DATA_CHANNEL_ACK message is received. The handler is called only on thefor the channel opened https://datatracker.ietf.org/doc/html/draft-ietf-rtcweb-data-protocol-09#section-5.2
func (*DataChannel) Read ¶
func (c *DataChannel) Read(p []byte) (int, error)
Read reads a packet of len(p) bytes as binary data
func (*DataChannel) ReadDataChannel ¶
func (c *DataChannel) ReadDataChannel(p []byte) (int, bool, error)
ReadDataChannel reads a packet of len(p) bytes
func (*DataChannel) SetBufferedAmountLowThreshold ¶ added in v1.3.0
func (c *DataChannel) SetBufferedAmountLowThreshold(th uint64)
SetBufferedAmountLowThreshold is used to update the threshold. See BufferedAmountLowThreshold().
func (*DataChannel) SetReadDeadline ¶ added in v1.5.3
func (c *DataChannel) SetReadDeadline(t time.Time) error
SetReadDeadline sets a deadline for reads to return
func (*DataChannel) SetWriteDeadline ¶ added in v1.5.10
func (c *DataChannel) SetWriteDeadline(t time.Time) error
SetWriteDeadline sets a deadline for writes to return, only available if the BlockWrite is enabled for sctp
func (*DataChannel) StreamIdentifier ¶
func (c *DataChannel) StreamIdentifier() uint16
StreamIdentifier returns the Stream identifier associated to the stream.
func (*DataChannel) Write ¶
func (c *DataChannel) Write(p []byte) (n int, err error)
Write writes len(p) bytes from p as binary data
func (*DataChannel) WriteDataChannel ¶
func (c *DataChannel) WriteDataChannel(p []byte, isString bool) (n int, err error)
WriteDataChannel writes len(p) bytes from p
type ReadDeadliner ¶ added in v1.5.4
ReadDeadliner extends an io.Reader to expose setting a read deadline.
type ReadWriteCloser ¶
ReadWriteCloser is an extended io.ReadWriteCloser that also implements our Reader and Writer.
type ReadWriteCloserDeadliner ¶ added in v1.5.10
type ReadWriteCloserDeadliner interface { ReadWriteCloser ReadDeadliner WriteDeadliner }
ReadWriteCloserDeadliner is an extended ReadWriteCloser that also implements r/w deadline.
type WriteDeadliner ¶ added in v1.5.10
WriteDeadliner extends an io.Writer to expose setting a write deadline.