forked from jiyeyuran/mediasoup-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirect_transport.go
118 lines (98 loc) · 2.7 KB
/
direct_transport.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package mediasoup
type DirectTransportOptions struct {
/**
* Maximum allowed size for direct messages sent from DataProducers.
* Default 262144.
*/
MaxMessageSize uint32 `json:"maxMessageSize,omitempty"`
/**
* Custom application data.
*/
AppData interface{} `json:"appData,omitempty"`
}
type directTransportData struct{}
/**
* DirectTransport
* @emits rtcp - (packet: []byte)
* @emits trace - (trace: TransportTraceEventData)
*/
type DirectTransport struct {
ITransport
logger Logger
internal internalData
channel *Channel
payloadChannel *PayloadChannel
}
func newDirectTransport(params transportParams) ITransport {
params.data = transportData{
transportType: TransportType_Direct,
}
params.logger = NewLogger("DirectTransport")
transport := &DirectTransport{
ITransport: newTransport(params),
logger: params.logger,
internal: params.internal,
channel: params.channel,
payloadChannel: params.payloadChannel,
}
transport.handleWorkerNotifications()
return transport
}
/**
* Observer.
*
* @override
* @emits close
* @emits newdataproducer - (dataProducer: DataProducer)
* @emits newdataconsumer - (dataProducer: DataProducer)
* @emits trace - (trace: TransportTraceEventData)
*/
func (transport *DirectTransport) Observer() IEventEmitter {
return transport.ITransport.Observer()
}
/**
* NO-OP method in DirectTransport.
*
* @override
*/
func (transport *DirectTransport) Connect(TransportConnectOptions) error {
transport.logger.Debug("connect()")
return nil
}
/**
* @override
*/
func (transport *DirectTransport) setMaxIncomingBitrate(bitrate int) error {
return NewUnsupportedError("setMaxIncomingBitrate() not implemented in DirectTransport")
}
/**
* Send RTCP packet.
*/
func (transport *DirectTransport) SendRtcp(rtcpPacket []byte) error {
return transport.payloadChannel.Notify("transport.sendRtcp", transport.internal, nil, rtcpPacket)
}
func (transport *DirectTransport) handleWorkerNotifications() {
transport.channel.On(transport.Id(), func(event string, data TransportTraceEventData) {
switch event {
case "trace":
transport.SafeEmit("trace", data)
// Emit observer event.
transport.Observer().SafeEmit("trace", data)
default:
transport.logger.Error(`ignoring unknown event "%s" in channel listener`, event)
}
})
transport.payloadChannel.On(transport.Id(), func(event string, data, payload []byte) {
switch event {
case "rtcp":
if transport.Closed() {
return
}
transport.SafeEmit("rtcp", payload)
// Emit observer event.
transport.Observer().SafeEmit("rtcp", payload)
default:
transport.logger.Error(`ignoring unknown event "%s" in payload channel listener`, event)
}
})
}