summaryrefslogtreecommitdiff
path: root/src/obswebsocket.cr
diff options
context:
space:
mode:
Diffstat (limited to 'src/obswebsocket.cr')
-rw-r--r--src/obswebsocket.cr23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/obswebsocket.cr b/src/obswebsocket.cr
index 3ab7836..968957f 100644
--- a/src/obswebsocket.cr
+++ b/src/obswebsocket.cr
@@ -119,7 +119,7 @@ module OBSWebSocket
end
self.reqchan.send( { reschan, request.to_s } )
end
- def initialize( uri : String )
+ def initialize( uri : String, password : String | Nil = nil )
spawn do
loop do
obs_pubsub = HTTP::WebSocket.new( URI.parse( uri ), HTTP::Headers{"Cookie" => "SESSIONID=1235", "Sec-WebSocket-Protocol" => "obswebsocket.json"} )
@@ -177,8 +177,25 @@ module OBSWebSocket
end
case json["op"].as_i64
when 0 # hello
- json_text = %({"op":1,"d":{"rpcVersion":1,"eventSubscriptions":526335}})
- self.send( json_text )
+
+ hello = JSON.build do |j|
+ j.object do
+ j.field "op", 1
+ j.field "d" do
+ j.object do
+ j.field "rpcVersion", 1
+ j.field "eventSubscriptions", 526335
+ if json["d"]["authentication"]? && password
+ secret = Base64.encode(OpenSSL::Digest.new("sha256").update( password + json["d"]["authentication"]["salt"].as_s ).final).chomp
+ auth = Base64.encode(OpenSSL::Digest.new("sha256").update( secret + json["d"]["authentication"]["challenge"].as_s ).final).chomp
+ j.field "authentication", auth
+ end
+ end
+ end
+ end
+ end
+
+ self.send( hello.to_s )
when 2 # identified
@negotiated = true
@connecterror = 0