-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for nil transceivers on get parameters
For ORTC API senders does not have a transceiver causing panics on getting parameters.
- Loading branch information
1 parent
305fc18
commit 99633ae
Showing
5 changed files
with
146 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// +build !js | ||
|
||
package webrtc | ||
|
||
import ( | ||
"io" | ||
"testing" | ||
"time" | ||
|
||
"github.com/pion/transport/test" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDataChannel_ORTCE2E(t *testing.T) { | ||
lim := test.TimeOut(time.Second * 20) | ||
defer lim.Stop() | ||
|
||
report := test.CheckRoutines(t) | ||
defer report() | ||
|
||
stackA, stackB, err := newORTCPair() | ||
assert.NoError(t, err) | ||
|
||
awaitSetup := make(chan struct{}) | ||
awaitString := make(chan struct{}) | ||
awaitBinary := make(chan struct{}) | ||
stackB.sctp.OnDataChannel(func(d *DataChannel) { | ||
close(awaitSetup) | ||
|
||
d.OnMessage(func(msg DataChannelMessage) { | ||
if msg.IsString { | ||
close(awaitString) | ||
} else { | ||
close(awaitBinary) | ||
} | ||
}) | ||
}) | ||
|
||
assert.NoError(t, signalORTCPair(stackA, stackB)) | ||
|
||
var id uint16 = 1 | ||
dcParams := &DataChannelParameters{ | ||
Label: "Foo", | ||
ID: &id, | ||
} | ||
channelA, err := stackA.api.NewDataChannel(stackA.sctp, dcParams) | ||
assert.NoError(t, err) | ||
|
||
<-awaitSetup | ||
|
||
assert.NoError(t, channelA.SendText("ABC")) | ||
assert.NoError(t, channelA.Send([]byte("ABC"))) | ||
|
||
<-awaitString | ||
<-awaitBinary | ||
|
||
assert.NoError(t, stackA.close()) | ||
assert.NoError(t, stackB.close()) | ||
|
||
// attempt to send when channel is closed | ||
assert.Error(t, channelA.Send([]byte("ABC")), io.ErrClosedPipe) | ||
assert.Error(t, channelA.SendText("test"), io.ErrClosedPipe) | ||
assert.Error(t, channelA.ensureOpen(), io.ErrClosedPipe) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// +build !js | ||
|
||
package webrtc | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/pion/transport/test" | ||
"github.com/pion/webrtc/v3/pkg/media" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_ORTC_Media(t *testing.T) { | ||
lim := test.TimeOut(time.Second * 20) | ||
defer lim.Stop() | ||
|
||
report := test.CheckRoutines(t) | ||
defer report() | ||
|
||
stackA, stackB, err := newORTCPair() | ||
assert.NoError(t, err) | ||
|
||
assert.NoError(t, stackA.api.mediaEngine.RegisterDefaultCodecs()) | ||
assert.NoError(t, stackB.api.mediaEngine.RegisterDefaultCodecs()) | ||
|
||
assert.NoError(t, signalORTCPair(stackA, stackB)) | ||
|
||
track, err := NewTrackLocalStaticSample(RTPCodecCapability{MimeType: MimeTypeVP8}, "video", "pion") | ||
assert.NoError(t, err) | ||
|
||
rtpSender, err := stackA.api.NewRTPSender(track, stackA.dtls) | ||
assert.NoError(t, err) | ||
assert.NoError(t, rtpSender.Send(rtpSender.GetParameters())) | ||
|
||
rtpReceiver, err := stackB.api.NewRTPReceiver(RTPCodecTypeVideo, stackB.dtls) | ||
assert.NoError(t, err) | ||
assert.NoError(t, rtpReceiver.Receive(RTPReceiveParameters{Encodings: []RTPDecodingParameters{ | ||
{RTPCodingParameters: rtpSender.GetParameters().Encodings[0].RTPCodingParameters}, | ||
}})) | ||
|
||
seenPacket, seenPacketCancel := context.WithCancel(context.Background()) | ||
go func() { | ||
track := rtpReceiver.Track() | ||
_, _, err := track.ReadRTP() | ||
assert.NoError(t, err) | ||
|
||
seenPacketCancel() | ||
}() | ||
|
||
func() { | ||
for range time.Tick(time.Millisecond * 20) { | ||
select { | ||
case <-seenPacket.Done(): | ||
return | ||
default: | ||
assert.NoError(t, track.WriteSample(media.Sample{Data: []byte{0xAA}, Duration: time.Second})) | ||
} | ||
} | ||
}() | ||
|
||
assert.NoError(t, rtpSender.Stop()) | ||
assert.NoError(t, rtpReceiver.Stop()) | ||
|
||
assert.NoError(t, stackA.close()) | ||
assert.NoError(t, stackB.close()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters