diff --git a/datachannel.go b/datachannel.go index 4c52b68d..06c4a665 100644 --- a/datachannel.go +++ b/datachannel.go @@ -84,6 +84,7 @@ func (api *API) newDataChannel(params *DataChannelParameters, log logging.Levele return &DataChannel{ label: params.Label, + protocol: params.Protocol, id: ¶ms.ID, ordered: params.Ordered, maxPacketLifeTime: params.MaxPacketLifeTime, @@ -141,6 +142,7 @@ func (d *DataChannel) open(sctpTransport *SCTPTransport) error { Priority: datachannel.ChannelPriorityNormal, ReliabilityParameter: reliabilityParameteer, Label: d.label, + Protocol: d.protocol, LoggerFactory: d.api.settingEngine.LoggerFactory, } diff --git a/datachannel_test.go b/datachannel_test.go index 83092d6e..bfe7eefd 100644 --- a/datachannel_test.go +++ b/datachannel_test.go @@ -295,7 +295,7 @@ func TestDataChannelParameters(t *testing.T) { offerPC, answerPC, dc, done := setUpDataChannelParametersTest(t, options) // Check if parameters are correctly set - assert.Equal(t, dc.Protocol(), protocol, "Protocol should match DataChannelInit") + assert.Equal(t, protocol, dc.Protocol(), "Protocol should match DataChannelInit") answerPC.OnDataChannel(func(d *DataChannel) { // Make sure this is the data channel we were looking for. (Not the one @@ -304,7 +304,7 @@ func TestDataChannelParameters(t *testing.T) { return } // Check if parameters are correctly set - assert.Equal(t, d.Protocol(), protocol, "Protocol should match what channel creator declared") + assert.Equal(t, protocol, d.Protocol(), "Protocol should match what channel creator declared") done <- true }) diff --git a/datachannelparameters.go b/datachannelparameters.go index dbf3dc9d..6c924903 100644 --- a/datachannelparameters.go +++ b/datachannelparameters.go @@ -3,6 +3,7 @@ package webrtc // DataChannelParameters describes the configuration of the DataChannel. type DataChannelParameters struct { Label string `json:"label"` + Protocol string `json:"protocol"` ID uint16 `json:"id"` Ordered bool `json:"ordered"` MaxPacketLifeTime *uint16 `json:"maxPacketLifeTime"` diff --git a/errors.go b/errors.go index af602afb..d1b4821d 100644 --- a/errors.go +++ b/errors.go @@ -83,4 +83,8 @@ var ( // ErrIncorrectSDPSemantics indicates that the PeerConnection was configured to // generate SDP Answers with different SDP Semantics than the received Offer ErrIncorrectSDPSemantics = errors.New("offer SDP semantics does not match configuration") + + // ErrProtocolTooLarge indicates that value given for a DataChannelInit protocol is + //longer then 65535 bytes + ErrProtocolTooLarge = errors.New("protocol is larger then 65535 bytes") ) diff --git a/go.mod b/go.mod index 77fdb1c4..d8fada32 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/pion/webrtc/v2 go 1.12 require ( - github.com/pion/datachannel v1.4.6 + github.com/pion/datachannel v1.4.7 github.com/pion/dtls v1.5.1 github.com/pion/ice v0.6.0 github.com/pion/logging v0.2.2 diff --git a/go.sum b/go.sum index 319f8745..ea1fba3a 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,8 @@ github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/pion/datachannel v1.4.6 h1:ALIwApJIxXOxA142PwJ7abvHwVdicVMqjkQNZC1WxLU= -github.com/pion/datachannel v1.4.6/go.mod h1:k02QlG7ZByXzavnjWj3gP3W1474H4ifzxSx2Y0Q5kvc= +github.com/pion/datachannel v1.4.7 h1:tKTEiDhZ+4yJOfa5/H2+Bwrk4uq49T9vItxlEaT74uo= +github.com/pion/datachannel v1.4.7/go.mod h1:k02QlG7ZByXzavnjWj3gP3W1474H4ifzxSx2Y0Q5kvc= github.com/pion/dtls v1.5.1 h1:LcCs1l9fzsHC4y+ENjLyuxOAe+k0DV65T2n4tjwM7xw= github.com/pion/dtls v1.5.1/go.mod h1:CjlPLfQdsTg3G4AEXjJp8FY5bRweBlxHrgoFrN+fQsk= github.com/pion/ice v0.6.0 h1:SfzZ/9z6hqclDOwbeSppuP7AugnHJ0Sek6y+3OukG2M= @@ -54,7 +54,6 @@ github.com/pion/stun v0.3.3 h1:brYuPl9bN9w/VM7OdNzRSLoqsnwlyNvD9MVeJrHjDQw= github.com/pion/stun v0.3.3/go.mod h1:xrCld6XM+6GWDZdvjPlLMsTU21rNxnO6UO8XsAvHr/M= github.com/pion/transport v0.6.0/go.mod h1:iWZ07doqOosSLMhZ+FXUTq+TamDoXSllxpbGcfkCmbE= github.com/pion/transport v0.7.0/go.mod h1:iWZ07doqOosSLMhZ+FXUTq+TamDoXSllxpbGcfkCmbE= -github.com/pion/transport v0.8.7 h1:t7uYhWOoljd82rnkLH+H2Lw7/IGA5kV9Bl5sWrmcYSc= github.com/pion/transport v0.8.7/go.mod h1:lpeSM6KJFejVtZf8k0fgeN7zE73APQpTF83WvA1FVP8= github.com/pion/transport v0.8.8/go.mod h1:lpeSM6KJFejVtZf8k0fgeN7zE73APQpTF83WvA1FVP8= github.com/pion/transport v0.8.9 h1:3PUZULb0WZd/QNfXKKMwcUHzLR+XfNem6lF2M9UrxSU= diff --git a/peerconnection.go b/peerconnection.go index 210ad11e..1fd6671f 100644 --- a/peerconnection.go +++ b/peerconnection.go @@ -1441,6 +1441,17 @@ func (pc *PeerConnection) CreateDataChannel(label string, options *DataChannelIn if options.MaxRetransmits != nil { params.MaxRetransmits = options.MaxRetransmits } + + // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #10) + if options.Protocol != nil { + params.Protocol = *options.Protocol + } + + // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #11) + if len(params.Protocol) > 65535 { + pc.mu.Unlock() + return nil, &rtcerr.TypeError{Err: ErrProtocolTooLarge} + } } // pion/webrtc#748 diff --git a/sctptransport.go b/sctptransport.go index 813ca4ee..b323e557 100644 --- a/sctptransport.go +++ b/sctptransport.go @@ -169,6 +169,7 @@ func (r *SCTPTransport) acceptDataChannels(a *sctp.Association) { rtcDC, err := r.api.newDataChannel(&DataChannelParameters{ ID: sid, Label: dc.Config.Label, + Protocol: dc.Config.Protocol, Ordered: ordered, MaxPacketLifeTime: maxPacketLifeTime, MaxRetransmits: maxRetransmits,