forked from samwho/streamdeck
-
Notifications
You must be signed in to change notification settings - Fork 1
/
event.go
70 lines (61 loc) · 2.56 KB
/
event.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
package streamdeck
import (
"context"
"encoding/json"
sdcontext "github.com/FlowingSPDG/streamdeck/context"
)
// Event JSON struct. {"action":"com.elgato.example.action1","event":"keyDown","context":"","device":"","payload":{"settings":{},"coordinates":{"column":3,"row":1},"state":0,"userDesiredState":1,"isInMultiAction":false}}
type Event struct {
Action string `json:"action,omitempty"`
Event string `json:"event,omitempty"`
UUID string `json:"uuid,omitempty"`
Context string `json:"context,omitempty"`
Device string `json:"device,omitempty"`
DeviceInfo DeviceInfo `json:"deviceInfo,omitempty"`
Payload json.RawMessage `json:"payload,omitempty"`
}
// DeviceInfo A json object containing information about the device.. {"deviceInfo":{"name":"Device Name","type":0,"size":{"columns":5,"rows":3}}}
type DeviceInfo struct {
DeviceName string `json:"deviceName,omitempty"`
Type DeviceType `json:"type,omitempty"`
Size DeviceSize `json:"size,omitempty"`
}
// DeviceSize The number of columns and rows of keys that the device owns. {"columns":5,"rows":3}
type DeviceSize struct {
Columns int `json:"columns,omitempty"`
Rows int `json:"rows,omitempty"`
}
// DeviceType Type of device. Possible values are kESDSDKDeviceType_StreamDeck (0), kESDSDKDeviceType_StreamDeckMini (1), kESDSDKDeviceType_StreamDeckXL (2), kESDSDKDeviceType_StreamDeckMobile (3), kESDSDKDeviceType_CorsairGKeys (4), kESDSDKDeviceType_StreamDeckPedal (5) and kESDSDKDeviceType_CorsairVoyager (6), kESDSDKDeviceType_StreamDeckPlus (7).
type DeviceType int
const (
// StreamDeck kESDSDKDeviceType_StreamDeck (0)
StreamDeck DeviceType = iota
// StreamDeckMini kESDSDKDeviceType_StreamDeckMini (1)
StreamDeckMini
// StreamDeckXL kESDSDKDeviceType_StreamDeckXL (2)
StreamDeckXL
// StreamDeckMobile kESDSDKDeviceType_StreamDeckMobile (3)
StreamDeckMobile
// CorsairGKeys kESDSDKDeviceType_CorsairGKeys (4)
CorsairGKeys
// StreamDeckPedal kESDSDKDeviceType_StreamDeckPedal (5)
StreamDeckPedal
// CorsairVoyager kESDSDKDeviceType_CorsairVoyager (6)
CorsairVoyager
// StreamDeckPlus kESDSDKDeviceType_StreamDeckPlus (7)
StreamDeckPlus
)
// NewEvent Generate new event from specified name and payload. payload will be converted to JSON
func NewEvent(ctx context.Context, name string, payload any) Event {
p, err := json.Marshal(payload)
if err != nil {
panic(err)
}
return Event{
Event: name,
Action: sdcontext.Action(ctx),
Context: sdcontext.Context(ctx),
Device: sdcontext.Device(ctx),
Payload: p,
}
}