skip to Main Content

I was trying to make an OBS extension when I ran into a problem with importing the module in the first place. I’m working in ES6, and using the Kruiz Control approach of making OBS load a webpage that connects to a local Websocket, and currently all I’m asking it to do is display the scene it switched to.

I verified that I had obs-websocket-js installed and then searched online about the nuances of import, however the suggested changes- switching out the * for OBSWebSocket, trying to use import ‘obs-websocket-js’, adding/removing type="module" from the script tag, and using require instead of import- yielded similar results.

import * as OBSWebSocket from 'obs-websocket-js'    // The problem line

const obs = new OBSWebSocket();
await obs.connect(IP_REMOVED, PASSWORD_REMOVED)
obs.on('CurrentProgramSceneChanged', scene => {
    console.log(scene)
})

If there’s any alternative, or a fix to this, that would be greatly appreciated.

Edited to include the way the script is loaded.

2

Answers


  1. Chosen as BEST ANSWER

    I resorted to just using Node. This is the finalized code snippet.

        var { default: OBSWebSocket } = require('obs-websocket-js');
    
    const obs = new OBSWebSocket();
    obs.connect('ws://192.168.1.143:4455', "4gPDLLGJhuUoCvOH")
    obs.on('CurrentProgramSceneChanged', scene => {
        console.log(scene.sceneName)
    })
    

  2. Try put semicolon after the package name, like this: import * as OBSWebSocket from 'obs-websocket-js';

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search