-
Notifications
You must be signed in to change notification settings - Fork 5
/
connection.go
60 lines (49 loc) · 1.88 KB
/
connection.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
package sdk
import (
"github.com/valyala/fastjson"
)
func reader() {
var p fastjson.Parser
var event, context, action, deviceId string
var payload *fastjson.Value
for {
_, message, err := conn.ReadMessage()
if err != nil {
close(closeSdk)
return
}
v, err := p.ParseBytes(message)
if err != nil {
continue
}
event = JsonStringValue(v, CommonEvent)
context = JsonStringValue(v, CommonContext)
action = JsonStringValue(v, CommonAction)
deviceId = JsonStringValue(v, CommonDevice)
payload = v.Get(CommonPayload)
switch event {
case EventKeyDown:
handleEvent(EventKeyDown, &KeyDownEvent{action, context, payload, deviceId})
case EventKeyUp:
handleEvent(EventKeyUp, &KeyUpEvent{action, context, payload, deviceId})
case EventWillAppear:
handleEvent(EventWillAppear, &WillAppearEvent{action, context, payload, deviceId})
case EventWillDisappear:
handleEvent(EventWillDisappear, &WillDisappearEvent{action, context, payload, deviceId})
case EventDeviceDidConnect:
handleEvent(EventDeviceDidConnect, &DeviceConnectEvent{deviceId, v.Get(CommonDeviceInfo)})
case EventDeviceDidDisconnect:
handleEvent(EventDeviceDidDisconnect, &DeviceDisconnectEvent{deviceId})
case EventSendToPlugin:
handleEvent(EventSendToPlugin, &SendToPluginEvent{action, context, payload, deviceId})
case EventDidReceiveSettings:
handleEvent(EventDidReceiveSettings, &ReceiveSettingsEvent{action, context, deviceId, payload.Get("settings")})
case EventDidReceiveGlobalSettings:
handleEvent(EventDidReceiveGlobalSettings, &GlobalSettingsEvent{payload.Get("settings")})
case EventApplicationDidLaunch:
handleEvent(EventApplicationDidLaunch, &ApplicationLaunchEvent{JsonStringValue(payload, "application")})
case EventApplicationDidTerminate:
handleEvent(EventApplicationDidTerminate, &ApplicationTerminateEvent{JsonStringValue(payload, "application")})
}
}
}