Skip to content

Commit

Permalink
Fix ORTC accept datachannel sctpTransport is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry-tao committed Sep 29, 2022
1 parent 0b3df2b commit cf5631b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions datachannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type DataChannel struct {
// This constructor is part of the ORTC API. It is not
// meant to be used together with the basic WebRTC API.
func (api *API) NewDataChannel(transport *SCTPTransport, params *DataChannelParameters) (*DataChannel, error) {
d, err := api.newDataChannel(params, api.settingEngine.LoggerFactory.NewLogger("ortc"))
d, err := api.newDataChannel(params, nil, api.settingEngine.LoggerFactory.NewLogger("ortc"))
if err != nil {
return nil, err
}
Expand All @@ -80,13 +80,14 @@ func (api *API) NewDataChannel(transport *SCTPTransport, params *DataChannelPara

// newDataChannel is an internal constructor for the data channel used to
// create the DataChannel object before the networking is set up.
func (api *API) newDataChannel(params *DataChannelParameters, log logging.LeveledLogger) (*DataChannel, error) {
func (api *API) newDataChannel(params *DataChannelParameters, sctpTransport *SCTPTransport, log logging.LeveledLogger) (*DataChannel, error) {
// https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #5)
if len(params.Label) > 65535 {
return nil, &rtcerr.TypeError{Err: ErrStringSizeLimit}
}

d := &DataChannel{
sctpTransport: sctpTransport,
statsID: fmt.Sprintf("DataChannel-%d", time.Now().UnixNano()),
label: params.Label,
protocol: params.Protocol,
Expand Down
2 changes: 1 addition & 1 deletion peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ func (pc *PeerConnection) CreateDataChannel(label string, options *DataChannelIn
}
}

d, err := pc.api.newDataChannel(params, pc.log)
d, err := pc.api.newDataChannel(params, nil, pc.log)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sctptransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ ACCEPT:
Ordered: ordered,
MaxPacketLifeTime: maxPacketLifeTime,
MaxRetransmits: maxRetransmits,
}, r.api.settingEngine.LoggerFactory.NewLogger("ortc"))
}, nil, r.api.settingEngine.LoggerFactory.NewLogger("ortc"))
if err != nil {
r.log.Errorf("Failed to accept data channel: %v", err)
r.onError(err)
Expand Down

0 comments on commit cf5631b

Please sign in to comment.