-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathinternal.go
107 lines (87 loc) · 2.55 KB
/
internal.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
package mediasoup
import (
"encoding/json"
"strings"
)
type internalData struct {
RouterId string `json:"routerId,omitempty"`
TransportId string `json:"transportId,omitempty"`
ProducerId string `json:"producerId,omitempty"`
ConsumerId string `json:"consumerId,omitempty"`
DataProducerId string `json:"dataProducerId,omitempty"`
DataConsumerId string `json:"dataConsumerId,omitempty"`
RtpObserverId string `json:"rtpObserverId,omitempty"`
WebRtcServerId string `json:"webRtcServerId,omitempty"`
}
func (i internalData) HandlerID(method string) string {
switch strings.Split(method, ".")[0] {
case "router":
return i.RouterId
case "transport":
return i.TransportId
case "producer":
return i.ProducerId
case "consumer":
return i.ConsumerId
case "dataProducer":
return i.DataProducerId
case "dataConsumer":
return i.DataConsumerId
case "rtpObserver":
return i.RtpObserverId
case "webRtcServer":
return i.WebRtcServerId
default:
return "undefined"
}
}
const (
NS_MESSAGE_MAX_LEN = 4194308
NS_PAYLOAD_MAX_LEN = 4194304
)
// workerRequest represents the json request sent to the worker
type workerRequest struct {
Id int64 `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Internal internalData `json:"internal,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
}
// workerResponse represents the json response returned from the worker
type workerResponse struct {
data json.RawMessage
err error
}
func (r workerResponse) Unmarshal(v interface{}) error {
if r.err != nil {
return r.err
}
if len(r.data) == 0 {
return nil
}
return json.Unmarshal([]byte(r.data), v)
}
func (r workerResponse) Data() []byte {
return []byte(r.data)
}
func (r workerResponse) Err() error {
return r.err
}
// sentInfo includes rpc info
type sentInfo struct {
method string // method name
request []byte // request json data
payload []byte // payload json data, used by payload channel
respCh chan workerResponse // channel to hold response
}
// workerNotification is the notification meta info sent to worker
type workerNotification struct {
Event string `json:"event,omitempty"`
Internal internalData `json:"internal,omitempty"`
Data interface{} `json:"data,omitempty"`
}
// notification represents a notification of the specified target from worker
type notification struct {
TargetId string `json:"targetId,omitempty"`
Event string `json:"event,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
}