obs-websocket-community-projects / obs-websocket-js

Consumes https://github.com/obsproject/obs-websocket
MIT License
657 stars 95 forks source link

GetSceneList disconnect socket #340

Closed julio-bandeira closed 9 months ago

julio-bandeira commented 9 months ago

The connection works normally, other commands are working normally, when I make the GetSceneList request the socket disconnects in the code, in the obs it still shows the connection if I try to connect again, instead of replacing the previous connection it creates a new connection and the previous one does not close even with the disconnect command.

const obsWs = new OBSWebSocket()
  const [scenesList, setSceneList] = useState<Array<any>>([])

  const connectWebSocket = () => {
    obsWs.connect(`ws:${device?.ip}:${device?.port}`).then(() => {
      alert('conectado')
    })
  }

  const disconnectWebSocket = () => {
    obsWs.disconnect().then(() => {
      alert('desconectado')
    })
  }

  const showScenesList = () => {
    obsWs.call('GetSceneList').then(async (res) => {
      alert(JSON.stringify(res))
      setSceneList(res.scenes)
    }).catch(err => {
      alert(err)
    })
  }

  const setCurrentScenes = (scene: any) => {
    alert(scene.sceneName)
    obsWs.call('SetCurrentProgramScene', {sceneName: scene.sceneName}).then(async (res) => {
      alert(JSON.stringify(res))
    }).catch(err => {
      alert(err)
    })
  }

Description:

Versions Used (if applicable):

julio-bandeira commented 9 months ago

const obsWs = new OBSWebSocket()

when declared within the body of a rendering function such as the function that returns the react component, when updating a list it generates a new socket