-
Notifications
You must be signed in to change notification settings - Fork 5
/
sdk.go
60 lines (44 loc) · 1.08 KB
/
sdk.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 (
"flag"
"fmt"
"github.com/gorilla/websocket"
"os"
"os/signal"
"syscall"
)
var (
flagPort = flag.Int("port", 0, "streamdeck sdk port")
flagEvent = flag.String("registerEvent", "", "streamdeck sdk register event")
flagInfo = flag.String("info", "", "streamdeck application info")
PluginUUID string
conn *websocket.Conn
closeSdk chan struct{}
)
func init() {
flag.StringVar(&PluginUUID, "pluginUUID", "", "streamdeck plugin uuid")
}
func Open() (error) {
flag.Parse()
closeSdk = make(chan struct{})
c, _, err := websocket.DefaultDialer.Dial(fmt.Sprintf("ws://localhost:%d", *flagPort), nil)
if err != nil {
return err
}
conn = c
go reader()
c.WriteJSON(&openMessage{Event: *flagEvent, UUID: PluginUUID})
return nil
}
// Waits for either the socket to close, or SIGINT/SIGTERM.
// Stream Deck closes the connection as a way to close the plugin,
// but will also SIGTERM/SIGINT as a final resort.
func Wait() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
select {
case <- closeSdk:
case <- sigs:
break
}
}