forked from emiago/diago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbridge_test.go
84 lines (73 loc) · 2.42 KB
/
bridge_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024, Emir Aganovic
package diago
import (
"bytes"
"io"
"testing"
"github.com/emiago/diago/media"
"github.com/emiago/diago/media/sdp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBridgeProxy(t *testing.T) {
b := NewBridge()
b.waitDialogsNum = 99 // Do not start proxy
incoming := &DialogServerSession{
DialogMedia: DialogMedia{
mediaSession: &media.MediaSession{
Formats: sdp.NewFormats(sdp.FORMAT_TYPE_ALAW),
},
audioReader: bytes.NewBuffer(make([]byte, 9999)),
audioWriter: bytes.NewBuffer(make([]byte, 0)),
RTPPacketReader: media.NewRTPPacketReader(nil, media.CodecAudioAlaw),
RTPPacketWriter: media.NewRTPPacketWriter(nil, media.CodecAudioAlaw),
},
}
outgoing := &DialogClientSession{
DialogMedia: DialogMedia{
mediaSession: &media.MediaSession{
Formats: sdp.NewFormats(sdp.FORMAT_TYPE_ALAW),
},
audioReader: bytes.NewBuffer(make([]byte, 9999)),
audioWriter: bytes.NewBuffer(make([]byte, 0)),
RTPPacketReader: media.NewRTPPacketReader(nil, media.CodecAudioAlaw),
RTPPacketWriter: media.NewRTPPacketWriter(nil, media.CodecAudioAlaw),
},
}
err := b.AddDialogSession(incoming)
require.NoError(t, err)
err = b.AddDialogSession(outgoing)
require.NoError(t, err)
err = b.proxyMedia()
require.ErrorIs(t, err, io.EOF)
// Confirm all data is proxied
assert.Equal(t, 9999, incoming.audioWriter.(*bytes.Buffer).Len())
assert.Equal(t, 9999, outgoing.audioWriter.(*bytes.Buffer).Len())
}
func TestBridgeNoTranscodingAllowed(t *testing.T) {
b := NewBridge()
// b.waitDialogsNum = 99 // Do not start proxy
incoming := &DialogServerSession{
DialogMedia: DialogMedia{
mediaSession: &media.MediaSession{
Formats: sdp.NewFormats(sdp.FORMAT_TYPE_ALAW),
},
// RTPPacketReader: media.NewRTPPacketReader(nil, media.CodecAudioAlaw),
// RTPPacketWriter: media.NewRTPPacketWriter(nil, media.CodecAudioAlaw),
},
}
outgoing := &DialogClientSession{
DialogMedia: DialogMedia{
mediaSession: &media.MediaSession{
Formats: sdp.NewFormats(sdp.FORMAT_TYPE_ULAW),
},
// RTPPacketReader: media.NewRTPPacketReader(nil, media.CodecAudioUlaw),
// RTPPacketWriter: media.NewRTPPacketWriter(nil, media.CodecAudioUlaw),
},
}
err := b.AddDialogSession(incoming)
require.NoError(t, err)
err = b.AddDialogSession(outgoing)
require.Error(t, err)
}