mirror of
https://github.com/pion/webrtc.git
synced 2025-10-09 00:50:12 +08:00
@@ -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,
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
})
|
||||
|
||||
|
@@ -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"`
|
||||
|
@@ -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")
|
||||
)
|
||||
|
2
go.mod
2
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
|
||||
|
5
go.sum
5
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=
|
||||
|
@@ -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
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user