Multiple instances on the same machine insist on using the same websocket.

AaronD

Active Member
It used to work, using the snap version that was version 27 or maybe slightly less, with the plugin preinstalled, and I used it to have a Slave instance follow a Master one on the same machine, using this python script:
Python:
#!/usr/bin/env python

import re
import sys
import subprocess

from obswebsocket import obsws, events, requests


wsSlv = obsws("localhost", 4456, "NotTheRealPassword!")
try:
    wsSlv.connect()
except:
    print("Error: Could not connect to OBS Slave")
    sys.exit(-1)


def on_switch(message):
    name = message.getSceneName()
    if re.match("Camera.*", name):
        wsSlv.call(requests.SetCurrentScene("Camera"))
    if re.match("Feature.*", name):
        wsSlv.call(requests.SetCurrentScene("Feature"))
    if re.match("Voiceover.*", name):
        wsSlv.call(requests.SetCurrentScene("Voiceover"))


wsMst = obsws("localhost", 4455, "NotTheRealPassword!")
wsMst.register(on_switch, events.SwitchScenes)
try:
    wsMst.connect()
except:
    try:
        wsSlv.disconnect()
    except:
        pass
    print("Error: Could not connect to OBS Master")
    sys.exit(-2)


# Expect a dialog command and message, to be passed as arguments to this script
# Closing the dialog is taken as a shutdown command, so this doesn't return until then
subprocess.run(sys.argv[1:])


# Disconnect from both, if possible
# If not, don't worry about it; it probably is already

try:
    wsMst.disconnect()
except:
    pass

try:
    wsSlv.disconnect()
except:
    pass

sys.exit(0)
Now, with version 28 installed from OBS's PPA, which of course has websockets built-in, I can't set multiple instances differently. Different profiles, different scene collections, and they still insist on using the same websocket. I also tried to disable one and enable the other, so that the Advanced Scene Switcher plugin might send a message straight across, but I can't even do that. They completely insist on having the exact same settings in their entirety.

Is there a solution to this? Can two instances of OBS 28 on the same machine be made to use different websocket settings?
 

Jay F. Jay

New Member
Hi Arron, I am also looking to the same functionality back!
I sent a message weeks ago, but did not get to find a solution.
 

Jay F. Jay

New Member
Arron,
I found a workaround for this, by managing the global.ini file and changing the port number before launching each instances of OBS.
Not ideal, but it works.
 

AaronD

Active Member
Okay. I can see how that would work. I might even be able to automate it in my management script, probably by swapping out the entire file:
Code:
rename global.ini -> global.ini.default

rename global.ini.master -> global.ini
start obs master
wait 10 sec
rename global.ini -> global.ini.master

rename global.ini.slave -> global.ini
start obs slave
wait 10 sec

wait for done

close obs slave
wait 10 sec
rename global.ini -> global.ini.slave

rename global.ini.master -> global.ini
close obs master
wait 10 sec
rename global.ini -> global.ini.master

rename global.ini.default -> global.ini
It would sure be nice though, to store the WebSocket settings in the Profile or Scene Collection instead of Global.

There is also a way to make the function that I want, without this trick, but it's a bit more Rube-Goldbergy in terms of signal flow:

I might look at changing it to this one here.
 

AaronD

Active Member
Okay. I can see how that would work. I might even be able to automate it in my management script, probably by swapping out the entire file:
Code:
rename global.ini -> global.ini.default

rename global.ini.master -> global.ini
start obs master
wait 10 sec
rename global.ini -> global.ini.master

rename global.ini.slave -> global.ini
start obs slave
wait 10 sec

wait for done

close obs slave
wait 10 sec
rename global.ini -> global.ini.slave

rename global.ini.master -> global.ini
close obs master
wait 10 sec
rename global.ini -> global.ini.master

rename global.ini.default -> global.ini
It would sure be nice though, to store the WebSocket settings in the Profile or Scene Collection instead of Global.

There is also a way to make the function that I want, without this trick, but it's a bit more Rube-Goldbergy in terms of signal flow:

I might look at changing it to this one here.
It took some fiddling with a slightly inconsistent API, but it works! That cleans things up at least a *little* bit, and moves some logic away from where a user might mess it up. Thank you!



The inconsistency is:

Python:
message="Feature"
OBS_Master_Request.call_vendor_request(vendor_name="AdvancedSceneSwitcher", request_type="AdvancedSceneSwitcherMessage", request_data={"message": message})
OBS_Slave_Request.set_current_program_scene(message)

The call_vendor_request() takes three named parameters, while set_current_program_scene() takes a single parameter that can't be named. Any name throws an error.

Meanwhile, the documentation says:

Yes, technically, the python page does give the example correctly, but why doesn't "copy/paste/rename" just work, following only the two protocol pages?
Maybe it's a python thing? Where a single parameter can't be named? Or maybe it's specific to that library?

Anyway, it works, with that caveat.
 
Top