I want to connect to the streamer.bot websocket client using the official streamer.bot client: https://streamerbot.github.io/client/get-started/installation via my iobroker javascript instance in an separate script.
I already figured out, that I have to add the npm source “@streamerbot/client” to my javascript instance:
I also added a streamer bot websocket server for my used ip address seperatly:
Firewall is open.
But the problem is, that I’m not able to construct an appropriate instance with my code:
let sbServerAddress = '192.168.0.38';
let sbServerPort = '9090';
const StreamerbotClient = require('@streamerbot/client');
const client = new StreamerbotClient({
host: sbServerAddress,
port: sbServerPort,
endpoint: '/'
});
I’m always getting the error message: javascript.0 (19364) script.js.streaming.Streamer_bot: TypeError: StreamerbotClient is not a constructor
I tried to make a direct WebSocket connection, which is connecting. I really want to use the specialized client. What are I’m missing?
This is my WebSocket code:
const WebSocketClient = require('websocket').client;
function connectws() {
const ws = new WebSocketClient();
// Reconnect
ws.on('close', function () {
console.log('Websocket closed');
setTimeout(connectws, 5000);
});
ws.on('connectFailed', function(error) {
console.log('Connect Error: ' + error.toString());
});
ws.on('connect', function (connection) {
console.log('Websocket opened');
});
ws.connect("ws://" + sbServerAddress + ":" + sbServerPort + "/", null);
}
connectws();