mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 23:26:58 +08:00

This change adapts pion/ice to use a new interface for most network related operations. The interface was formerly a simple struct vnet.Net which was originally intended to facilicate testing. By replacing it with an interface we have greater flexibility and allow users to hook into the networking stack by providing their own implementation of the interface.
66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
//go:build !js
|
|
// +build !js
|
|
|
|
package webrtc
|
|
|
|
import (
|
|
"io"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/pion/transport/v2/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.ErrorIs(t, channelA.Send([]byte("ABC")), io.ErrClosedPipe)
|
|
assert.ErrorIs(t, channelA.SendText("test"), io.ErrClosedPipe)
|
|
assert.ErrorIs(t, channelA.ensureOpen(), io.ErrClosedPipe)
|
|
}
|