forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtcsctptransport.go
71 lines (53 loc) · 1.67 KB
/
rtcsctptransport.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
package webrtc
import (
"math"
)
// RTCSctpTransport provides details about the SCTP transport.
type RTCSctpTransport struct {
// Transport represents the transport over which all SCTP packets for data
// channels will be sent and received.
Transport *RTCDtlsTransport
// State represents the current state of the SCTP transport.
State RTCSctpTransportState
// MaxMessageSize represents the maximum size of data that can be passed to
// RTCDataChannel's send() method.
MaxMessageSize float64
// MaxChannels represents the maximum amount of RTCDataChannel's that can
// be used simultaneously.
MaxChannels *uint16
// OnStateChange func()
// dataChannels
// dataChannels map[uint16]*RTCDataChannel
}
func newRTCSctpTransport() *RTCSctpTransport {
res := &RTCSctpTransport{
State: RTCSctpTransportStateConnecting,
}
res.updateMessageSize()
res.updateMaxChannels()
return res
}
func (r *RTCSctpTransport) updateMessageSize() {
var remoteMaxMessageSize float64 = 65536 // TODO: get from SDP
var canSendSize float64 = 65536 // TODO: Get from SCTP implementation
r.MaxMessageSize = r.calcMessageSize(remoteMaxMessageSize, canSendSize)
}
func (r *RTCSctpTransport) calcMessageSize(remoteMaxMessageSize, canSendSize float64) float64 {
switch {
case remoteMaxMessageSize == 0 &&
canSendSize == 0:
return math.Inf(1)
case remoteMaxMessageSize == 0:
return canSendSize
case canSendSize == 0:
return remoteMaxMessageSize
case canSendSize > remoteMaxMessageSize:
return remoteMaxMessageSize
default:
return canSendSize
}
}
func (r *RTCSctpTransport) updateMaxChannels() {
val := uint16(65535)
r.MaxChannels = &val // TODO: Get from implementation
}