Repository navigation
Expand file tree
/
Copy pathwrapper.go
More file actions
107 lines (87 loc) · 2.06 KB
/
Copy pathwrapper.go
File metadata and controls
107 lines (87 loc) · 2.06 KB
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 webrtc
/*
#include "wrapper.h"
*/
import "C"
import (
"runtime"
"unsafe"
)
func InitializeSSL() {
C.WebRTC_InitializeSSL()
}
func CleanupSSL() {
C.WebRTC_CleanupSSL()
}
type (
Factory struct{ ptr C.Factory }
MediaStream struct{ ptr C.MediaStream }
PeerConnection struct{ ptr C.PeerConnection }
)
func New() *Factory {
inner := C.WebRTC_PeerConnectionFactory_Create()
outer := &Factory{inner}
runtime.SetFinalizer(outer, (*Factory).free)
return outer
}
func (f *Factory) free() {
if f != nil {
C.WebRTC_PeerConnectionFactory_Free(f.ptr)
}
}
func (f *Factory) CreatePeerConnection(servers []*ICEServer, constraints []*MediaConstraint, observer PeerConnectionObserver) *PeerConnection {
var (
pservers unsafe.Pointer
pconstraints unsafe.Pointer
)
if len(servers) > 0 {
pservers = unsafe.Pointer(&servers[0])
}
if len(constraints) > 0 {
pconstraints = unsafe.Pointer(&constraints[0])
}
inner := C.WebRTC_PeerConnection_Create(f.ptr,
pservers, C.int(len(servers)),
pconstraints, C.int(len(constraints)),
register(observer))
outer := &PeerConnection{inner}
runtime.SetFinalizer(outer, (*PeerConnection).free)
return outer
}
func (s *PeerConnection) free() {
if s != nil {
C.WebRTC_PeerConnection_Free(s.ptr)
}
}
func (s *PeerConnection) UpdateIce(servers []*ICEServer, constraints []*MediaConstraint) bool {
var (
pservers unsafe.Pointer
pconstraints unsafe.Pointer
)
if len(servers) > 0 {
pservers = unsafe.Pointer(&servers[0])
}
if len(constraints) > 0 {
pconstraints = unsafe.Pointer(&constraints[0])
}
if s != nil {
ok := C.WebRTC_PeerConnection_UpdateICE(s.ptr,
pservers, C.int(len(servers)),
pconstraints, C.int(len(constraints)))
if ok == 1 {
return true
}
}
return false
}
func (f *Factory) CreateMediaStream(label string) *MediaStream {
inner := C.WebRTC_CreateMediaStreamWithLabel(f.ptr, C.CString(label))
outer := &MediaStream{inner}
runtime.SetFinalizer(outer, (*MediaStream).free)
return outer
}
func (s *MediaStream) free() {
if s != nil {
C.WebRTC_MediaStream_Free(s.ptr)
}
}