-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.go
150 lines (126 loc) · 3.22 KB
/
app.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
package main
import (
"time"
"github.com/hypebeast/go-osc/osc"
)
const (
// Replay Buffer
ReplayBufferToggle = "/avatar/parameters/OBSReplayBufferToggle"
ReplayBufferCapture = "/avatar/parameters/OBSReplayBufferCapture"
ReplayBufferStatus = "/avatar/parameters/OBSReplayBufferStatus"
// Recording
RecordToggle = "/avatar/parameters/OBSRecordToggle"
RecordStatus = "/avatar/parameters/OBSRecordStatus"
// Stream
StreamToggle = "/avatar/parameters/OBSStreamToggle"
StreamStatus = "/avatar/parameters/OBSStreamStatus"
// Scene Switch
SceneSwitchSelector = "/avatar/parameters/OBSSceneSwitchSelector"
)
func pollStatus() {
poller := time.NewTicker(500 * time.Millisecond)
for {
<-poller.C
runPoller()
}
}
func runPoller() {
// Get Stream Status
isStreaming, err := _obs.GetStatusStream()
if err != nil {
_log.Error(err)
return
}
_log.Debugf("IsStreaming: %v", isStreaming)
msg := osc.NewMessage(StreamStatus)
msg.Append(isStreaming)
_osc.GetClient().Client().Send(msg)
// Get Record Status
isRecording, err := _obs.GetStatusRecord()
if err != nil {
_log.Error(err)
return
}
_log.Debugf("IsRecording: %v", isRecording)
msg = osc.NewMessage(RecordStatus)
msg.Append(isRecording)
_osc.GetClient().Client().Send(msg)
// Get Instant Replay Status
isInstantReplay, err := _obs.GetStatusInstantReplay()
if err != nil {
_log.Error(err)
return
}
_log.Debugf("IsInstantReplay: %v", isInstantReplay)
msg = osc.NewMessage(ReplayBufferStatus)
msg.Append(isInstantReplay)
_osc.GetClient().Client().Send(msg)
// Get Current Scene
currentSceneNumber, err := _obs.GetCurrentSceneNumber()
if err != nil {
_log.Error(err)
}
_log.Debugf("ActiveScene: %v", currentSceneNumber)
if currentSceneNumber >= 0 {
msg = osc.NewMessage(SceneSwitchSelector)
msg.Append(int32(currentSceneNumber))
_osc.GetClient().Client().Send(msg)
}
}
func start() {
// Build Hooks for Replay Buffer
_osc.GetServer().AddBooleanListener(ReplayBufferToggle, func(b bool) {
_log.Debugf("ReplayBufferToggle Invoked with value %v", b)
if !b {
return
}
if err := _obs.ToggleInstantReplay(); err != nil {
_log.Error(err)
}
})
_osc.GetServer().AddBooleanListener(ReplayBufferCapture, func(b bool) {
_log.Debugf("ReplayBufferCapture Invoked with value %v", b)
if !b {
return
}
if err := _obs.SaveInstantReplay(); err != nil {
_log.Error(err)
}
})
// Build Hooks for Record
_osc.GetServer().AddBooleanListener(RecordToggle, func(b bool) {
_log.Debugf("RecordToggle Invoked with value %v", b)
if !b {
return
}
if err := _obs.ToggleRecord(); err != nil {
_log.Error(err)
}
})
// Build Hooks for Stream
_osc.GetServer().AddBooleanListener(StreamToggle, func(b bool) {
_log.Debugf("StreamToggle Invoked with value %v", b)
if !b {
return
}
if err := _obs.ToggleStream(); err != nil {
_log.Error(err)
}
})
// Build Hooks for Scene Selector
_osc.GetServer().AddIntegerListener(SceneSwitchSelector, func(v int) {
_log.Debugf("StreamToggle Invoked with value %v", v)
// If value less than 1, ignore
if v < 1 {
return
}
if err := _obs.ToggleToSceneNumber(v); err != nil {
_log.Error(err)
}
})
// Poll?
go pollStatus()
// Start Server
_osc.GetServer().Start()
<-hold()
}