/
netinfo.go
248 lines (210 loc) · 7.01 KB
/
netinfo.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// Code generated by webidl-bind. DO NOT EDIT.
// +build !js
package netinfo
import js "github.com/gowebapi/webapi/core/js"
import (
"github.com/gowebapi/webapi/core"
"github.com/gowebapi/webapi/dom/domcore"
)
// using following types:
// domcore.Event
// domcore.EventHandler
// domcore.EventTarget
// source idl files:
// netinfo.idl
// transform files:
// netinfo.go.md
// workaround for compiler error
func unused(value interface{}) {
// TODO remove this method
}
type Union struct {
Value js.Value
}
func (u *Union) JSValue() js.Value {
return u.Value
}
func UnionFromJS(value js.Value) *Union {
return &Union{Value: value}
}
// enum: ConnectionType
type ConnectionType int
const (
BluetoothConnectionType ConnectionType = iota
CellularConnectionType
EthernetConnectionType
MixedConnectionType
NoneConnectionType
OtherConnectionType
UnknownConnectionType
WifiConnectionType
WimaxConnectionType
)
var connectionTypeToWasmTable = []string{
"bluetooth", "cellular", "ethernet", "mixed", "none", "other", "unknown", "wifi", "wimax",
}
var connectionTypeFromWasmTable = map[string]ConnectionType{
"bluetooth": BluetoothConnectionType, "cellular": CellularConnectionType, "ethernet": EthernetConnectionType, "mixed": MixedConnectionType, "none": NoneConnectionType, "other": OtherConnectionType, "unknown": UnknownConnectionType, "wifi": WifiConnectionType, "wimax": WimaxConnectionType,
}
// JSValue is converting this enum into a javascript object
func (this *ConnectionType) JSValue() js.Value {
return js.ValueOf(this.Value())
}
// Value is converting this into javascript defined
// string value
func (this ConnectionType) Value() string {
idx := int(this)
if idx >= 0 && idx < len(connectionTypeToWasmTable) {
return connectionTypeToWasmTable[idx]
}
panic("unknown input value")
}
// ConnectionTypeFromJS is converting a javascript value into
// a ConnectionType enum value.
func ConnectionTypeFromJS(value js.Value) ConnectionType {
key := value.String()
conv, ok := connectionTypeFromWasmTable[key]
if !ok {
panic("unable to convert '" + key + "'")
}
return conv
}
// enum: EffectiveConnectionType
type EffectiveConnectionType int
const (
_2gEffectiveConnectionType EffectiveConnectionType = iota
_3gEffectiveConnectionType
_4gEffectiveConnectionType
Slow2gEffectiveConnectionType
)
var effectiveConnectionTypeToWasmTable = []string{
"2g", "3g", "4g", "slow-2g",
}
var effectiveConnectionTypeFromWasmTable = map[string]EffectiveConnectionType{
"2g": _2gEffectiveConnectionType, "3g": _3gEffectiveConnectionType, "4g": _4gEffectiveConnectionType, "slow-2g": Slow2gEffectiveConnectionType,
}
// JSValue is converting this enum into a javascript object
func (this *EffectiveConnectionType) JSValue() js.Value {
return js.ValueOf(this.Value())
}
// Value is converting this into javascript defined
// string value
func (this EffectiveConnectionType) Value() string {
idx := int(this)
if idx >= 0 && idx < len(effectiveConnectionTypeToWasmTable) {
return effectiveConnectionTypeToWasmTable[idx]
}
panic("unknown input value")
}
// EffectiveConnectionTypeFromJS is converting a javascript value into
// a EffectiveConnectionType enum value.
func EffectiveConnectionTypeFromJS(value js.Value) EffectiveConnectionType {
key := value.String()
conv, ok := effectiveConnectionTypeFromWasmTable[key]
if !ok {
panic("unable to convert '" + key + "'")
}
return conv
}
// class: NetworkInformation
type NetworkInformation struct {
domcore.EventTarget
}
// NetworkInformationFromJS is casting a js.Value into NetworkInformation.
func NetworkInformationFromJS(value js.Value) *NetworkInformation {
if typ := value.Type(); typ == js.TypeNull || typ == js.TypeUndefined {
return nil
}
ret := &NetworkInformation{}
ret.Value_JS = value
return ret
}
// NetworkInformationFromJS is casting from something that holds a js.Value into NetworkInformation.
func NetworkInformationFromWrapper(input core.Wrapper) *NetworkInformation {
return NetworkInformationFromJS(input.JSValue())
}
// Type returning attribute 'type' with
// type ConnectionType (idl: ConnectionType).
func (_this *NetworkInformation) Type() ConnectionType {
var ret ConnectionType
value := _this.Value_JS.Get("type")
ret = ConnectionTypeFromJS(value)
return ret
}
// EffectiveType returning attribute 'effectiveType' with
// type EffectiveConnectionType (idl: EffectiveConnectionType).
func (_this *NetworkInformation) EffectiveType() EffectiveConnectionType {
var ret EffectiveConnectionType
value := _this.Value_JS.Get("effectiveType")
ret = EffectiveConnectionTypeFromJS(value)
return ret
}
// DownlinkMax returning attribute 'downlinkMax' with
// type float64 (idl: unrestricted double).
func (_this *NetworkInformation) DownlinkMax() float64 {
var ret float64
value := _this.Value_JS.Get("downlinkMax")
ret = (value).Float()
return ret
}
// Downlink returning attribute 'downlink' with
// type float64 (idl: unrestricted double).
func (_this *NetworkInformation) Downlink() float64 {
var ret float64
value := _this.Value_JS.Get("downlink")
ret = (value).Float()
return ret
}
// Rtt returning attribute 'rtt' with
// type int (idl: unsigned long long).
func (_this *NetworkInformation) Rtt() int {
var ret int
value := _this.Value_JS.Get("rtt")
ret = (value).Int()
return ret
}
// SaveData returning attribute 'saveData' with
// type bool (idl: boolean).
func (_this *NetworkInformation) SaveData() bool {
var ret bool
value := _this.Value_JS.Get("saveData")
ret = (value).Bool()
return ret
}
// OnChange returning attribute 'onchange' with
// type domcore.EventHandler (idl: EventHandlerNonNull).
func (_this *NetworkInformation) OnChange() domcore.EventHandlerFunc {
var ret domcore.EventHandlerFunc
value := _this.Value_JS.Get("onchange")
if value.Type() != js.TypeNull && value.Type() != js.TypeUndefined {
ret = domcore.EventHandlerFromJS(value)
}
return ret
}
// event attribute: domcore.Event
func eventFuncNetworkInformation_domcore_Event(listener func(event *domcore.Event, target *NetworkInformation)) js.Func {
fn := func(this js.Value, args []js.Value) interface{} {
var ret *domcore.Event
value := args[0]
incoming := value.Get("target")
ret = domcore.EventFromJS(value)
src := NetworkInformationFromJS(incoming)
listener(ret, src)
return js.Undefined()
}
return js.FuncOf(fn)
}
// AddChange is adding doing AddEventListener for 'Change' on target.
// This method is returning allocated javascript function that need to be released.
func (_this *NetworkInformation) AddEventChange(listener func(event *domcore.Event, currentTarget *NetworkInformation)) js.Func {
cb := eventFuncNetworkInformation_domcore_Event(listener)
_this.Value_JS.Call("addEventListener", "change", cb)
return cb
}
// SetOnChange is assigning a function to 'onchange'. This
// This method is returning allocated javascript function that need to be released.
func (_this *NetworkInformation) SetOnChange(listener func(event *domcore.Event, currentTarget *NetworkInformation)) js.Func {
cb := eventFuncNetworkInformation_domcore_Event(listener)
_this.Value_JS.Set("onchange", cb)
return cb
}