Control OBS in Love2d via websockets api
- Love2d version used 11.3
- OBS version used 27.0.1
- obs-websocket version used 4.9.1
lunajson
, love2d-lua-websocket
(and src/obsClient.lua
) must be included in your love projects require path
(I prefer using submodules (see mägic.ObsClient-demo for usage) but you can also copying src/obsClient.lua
from this project into yours)
OBS
must have the obs-websocket
plugin installed, see obs-websocket for instructions.
function love.load()
obsClient = require('obsClient').new(host, port) -- defaults to localhost 4444
end
function love.update(dt)
obsClient:update(dt)
end
--obsClient:watchEvent(event_type<string>, func<function>)
obsClient:watchEvent("SwitchScenes", function (data)
print("Current Scene: " .. data["scene-name"])
end)
--obsClient:sendRequest(request_type<string>)
obsClient:sendRequest("StartStreaming")
--obsClient:sendRequest(request_type<string>, func<function>)
obsClient:sendRequest("StartStreaming",
function(data)
if data["status"] == "ok" then
print("Stream is starting")
end
end)
--obsClient:sendRequest(request_type<string>, params<table>)
obsClient:sendRequest("SetCurrentScene", {["scene-name"] = "Scene One"})
--[[obsClient:sendRequest(request_type<string>,
retry<bool>,
message_id<string>,
params<table>,
func<function>)
]]--
obsClient:sendRequest("SetCurrentScene",
true,
{["scene-name"] = "Scene One"},
function(data)
if data["status"] == "ok" then
print("Scene Switched")
end
end)
request_type
must be the first parameter, the rest can be in any order
set retry
to true
to add request to queue to be sent when connection is established, otherwise default false
request is dropped
message_id
will be sent to Obs and used for calling the callback_func
, leaving message_id
blank will auto generate a unique id, you can set your own if required.
TODO
see obs-websockets for list of Events
, Requests
and required parameters.
See mägic.ObsClient-demo for a working demo.