-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOBS2.ahk
More file actions
151 lines (133 loc) · 2.8 KB
/
OBS2.ahk
File metadata and controls
151 lines (133 loc) · 2.8 KB
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
#NoEnv
#NoTrayIcon
#SingleInstance, Force
SetBatchLines, -1
#Include, <nm_msg>
DetectHiddenWindows, On
global willDelete := false
IfWinNotExist, ahk_exe obs64.exe
{
nmMsg("OBS Not Detected!",2)
ExitApp
}
new LlamadaWS("ws://127.0.0.1:4455")
return
class LlamadaWS extends WebSocket
{
OnOpen(Event)
{
Authenticate =
(
{
"op": 1,
"d": {
"rpcVersion": 1,
"eventSubscriptions": 33
}
}
)
this.Send(Authenticate)
Sleep, 250
Command =
(
{
"op": 6,
"d": {
"requestType": "StopRecord",
"requestId": "f819dcf0-89cc-11eb-8f0e-382c4ac93b9c"
}
}
)
this.Send(Command)
nmMsg("Recording stopped")
MsgBox 0x34, Keep Video?, Do you want to keep last video you recorded?
IfMsgBox No, {
willDelete := true
}
}
OnMessage(Event)
{
Sleep, 2000
this.Close()
}
OnClose(Event)
{
this.Disconnect()
if (willDelete) {
Loop, Files, V:\VIDEO\*.mp4
{
if(newest < A_LoopFileTimeCreated)
{
newest := A_LoopFileTimeCreated
fileToDelete := A_LoopFileFullPath
}
}
FileDelete, %fileToDelete%
}
ExitApp
}
__Delete()
{
ExitApp
}
}
; ************************
; WEB SOCKET STUFF
; ************************
class WebSocket
{
__New(WS_URL)
{
static wb
; Create an IE instance
Gui, +hWndhOld
Gui, New, +hWndhWnd
this.hWnd := hWnd
Gui, Add, ActiveX, vWB, Shell.Explorer
Gui, %hOld%: Default
; Write an appropriate document
WB.Navigate("about:<!DOCTYPE html><meta http-equiv='X-UA-Compatible'"
. "content='IE=edge'><body></body>")
while (WB.ReadyState < 4)
sleep, 50
this.document := WB.document
; Add our handlers to the JavaScript namespace
this.document.parentWindow.ahk_savews := this._SaveWS.Bind(this)
this.document.parentWindow.ahk_event := this._Event.Bind(this)
this.document.parentWindow.ahk_ws_url := WS_URL
; Add some JavaScript to the page to open a socket
Script := this.document.createElement("script")
Script.text := "ws = new WebSocket(ahk_ws_url);"
. "ws.onopen = function(event){ ahk_event('Open', event); };"
. "ws.onclose = function(event){ ahk_event('Close', event); };"
. "ws.onerror = function(event){ ahk_event('Error', event); };"
. "ws.onmessage = function(event){ ahk_event('Message', event); };"
this.document.body.appendChild(Script)
}
; Called by the JS in response to WS events
_Event(EventName, Event)
{
this["On" EventName](Event)
}
; Sends data through the WebSocket
Send(Data)
{
this.document.parentWindow.ws.send(Data)
}
; Closes the WebSocket connection
Close(Code:=1000, Reason:="")
{
this.document.parentWindow.ws.close(Code, Reason)
}
; Closes and deletes the WebSocket, removing
; references so the class can be garbage collected
Disconnect()
{
if this.hWnd
{
this.Close()
Gui, % this.hWnd ": Destroy"
this.hWnd := False
}
}
}