forked from metal3d/kurento-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDispatcherOneToMany.go
93 lines (73 loc) · 2.06 KB
/
DispatcherOneToMany.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
package kurento
import (
"errors"
"fmt"
)
type IDispatcherOneToMany interface {
SetSource(source HubPort) error
RemoveSource() error
}
// A `Hub` that sends a given source to all the connected sinks
type DispatcherOneToMany struct {
Hub
}
// Return contructor params to be called by "Create".
func (elem *DispatcherOneToMany) getConstructorParams(from IMediaObject, options map[string]interface{}) map[string]interface{} {
// Create basic constructor params
ret := map[string]interface{}{
"mediaPipeline": fmt.Sprintf("%s", from),
}
// then merge options
mergeOptions(ret, options)
return ret
}
// Sets the source port that will be connected to the sinks of every `HubPort` of
// the dispatcher
func (elem *DispatcherOneToMany) SetSource(source HubPort) error {
req := elem.getInvokeRequest()
params := make(map[string]interface{})
setIfNotEmpty(params, "source", source)
req["params"] = map[string]interface{}{
"operation": "setSource",
"object": elem.Id,
"operationParams": params,
}
// Call server and wait response
responses, err := elem.connection.Request(req)
if err != nil {
return err
}
select {
case response := <-responses:
// Returns error or nil
if response.Error != nil {
return errors.New(fmt.Sprintf("[%d] %s %s", response.Error.Code, response.Error.Message, response.Error.Data))
}
case <-elem.connection.closeSig:
return ErrConnectionClosing
}
return nil
}
// Remove the source port and stop the media pipeline.
func (elem *DispatcherOneToMany) RemoveSource() error {
req := elem.getInvokeRequest()
req["params"] = map[string]interface{}{
"operation": "removeSource",
"object": elem.Id,
}
// Call server and wait response
responses, err := elem.connection.Request(req)
if err != nil {
return err
}
select {
case response := <-responses:
// Returns error or nil
if response.Error != nil {
return errors.New(fmt.Sprintf("[%d] %s %s", response.Error.Code, response.Error.Message, response.Error.Data))
}
case <-elem.connection.closeSig:
return ErrConnectionClosing
}
return nil
}