Fire DataChannel.onOpen when already negotiated

Fix regression from 0180ee. Before Datachannels would always fire
OnOpen. Now they only fire when DCEP ACK is received. This caused
OnOpen to not be fired for negotiated channels. This re-enables
the previous behavior of firing OnOpen for negotiated channels.
This commit is contained in:
Eric Daniels
2021-11-01 11:22:39 -04:00
committed by Sean DuBois
parent 979aefd702
commit 5dc7245bee
2 changed files with 5 additions and 4 deletions

View File

@@ -169,7 +169,7 @@ func (d *DataChannel) open(sctpTransport *SCTPTransport) error {
dc.OnBufferedAmountLow(d.onBufferedAmountLow)
d.mu.Unlock()
d.handleOpen(dc, false)
d.handleOpen(dc, false, d.negotiated)
return nil
}
@@ -263,7 +263,7 @@ func (d *DataChannel) onMessage(msg DataChannelMessage) {
handler(msg)
}
func (d *DataChannel) handleOpen(dc *datachannel.DataChannel, isRemote bool) {
func (d *DataChannel) handleOpen(dc *datachannel.DataChannel, isRemote, isAlreadyNegotiated bool) {
d.mu.Lock()
d.dataChannel = dc
d.mu.Unlock()
@@ -272,7 +272,8 @@ func (d *DataChannel) handleOpen(dc *datachannel.DataChannel, isRemote bool) {
// Fire the OnOpen handler immediately not using pion/datachannel
// * detached datachannels have no read loop, the user needs to read and query themselves
// * remote datachannels should fire OnOpened. This isn't spec compliant, but we can't break behavior yet
if d.api.settingEngine.detach.DataChannels || isRemote {
// * already negotiated datachannels should fire OnOpened
if d.api.settingEngine.detach.DataChannels || isRemote || isAlreadyNegotiated {
d.onOpen()
} else {
dc.OnOpen(func() {

View File

@@ -195,7 +195,7 @@ func (r *SCTPTransport) acceptDataChannels(a *sctp.Association) {
}
<-r.onDataChannel(rtcDC)
rtcDC.handleOpen(dc, true)
rtcDC.handleOpen(dc, true, dc.Config.Negotiated)
r.lock.Lock()
r.dataChannelsOpened++