node-red-contrib-samsung-tv-control
node-red-contrib-samsung-tv-control copied to clipboard
Cannot retrieve token
Here is the error log when I try to retrieve the token:
31 Dec 14:13:49 - [red] Uncaught Exception:
31 Dec 14:13:49 - Error: RangeError: Invalid WebSocket frame: invalid status code 1005
at sendKey (/data/node_modules/samsung-tv-control/lib/index.js:62:23)
at WebSocket.ws.on (/data/node_modules/samsung-tv-control/lib/index.js:273:17)
at WebSocket.emit (events.js:198:13)
at Receiver.receiverOnError (/data/node_modules/ws/lib/websocket.js:777:13)
at Receiver.emit (events.js:198:13)
at errorOrDestroy (internal/streams/destroy.js:107:12)
at onwriteError (_stream_writable.js:430:5)
at onwrite (_stream_writable.js:461:5)
at Receiver.startLoop (/data/node_modules/ws/lib/receiver.js:152:5)
at Receiver._write (/data/node_modules/ws/lib/receiver.js:78:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
This may be related to: Toxblh/samsung-tv-control#82 Toxblh/samsung-tv-control#81 Toxblh/samsung-tv-control#112
Same error here...
Did you ever find a fix for this? I get this error after about the 50th key press in a row
any update here?
Nop :(
I actually found a fix for this last night. I'm using the samsung-tv-control
repo, and I just threw up a PR for the fix. Check it out: https://github.com/Toxblh/samsung-tv-control/pull/296
I want to access my Samsung smart tv and for that I am using samsung-tv-control npm package. But unfortunately, I am also still getting this error - > RangeError: Invalid WebSocket frame: invalid status code 1005,
Here is my code nodejs, can you please guide me :
const { Samsung, KEYS, APPS } = require("samsung-tv-control");
const app = express();
let isAvailable = false;
const config = {
debug: true,
ip: "", // i had given IP
mac: "", // i had given mac
nameApp: "NodeJS-Test", // Default: NodeJS
port: 8001, // Default: 8002
token: "", // not sure what to provide here, giving some random value
};
const control = new Samsung(config);
control.turnOn();
app.get("/", async (req, res) => {
res.send("TV control" + JSON.stringify(control));
try {
control.turnOn();
isAvailable = await control.isAvailable();
console.log("isAvailable: ", isAvailable);
control.getAppsFromTV((err, res) => {
if (!err) {
console.log("# Response getAppsFromTV", res);
} else {
console.log("Failed to get Apps: ", err);
}
});
} catch (e) {
console.log(e);
}
try {
isAvailable = await control.isAvailable();
console.log("isAvailable: ", isAvailable);
if (isAvailable) {
try {
control.turnOn();
setTimeout(() => {
control.getToken((token) => {
console.info("# Response getToken:", token);
});
// Send key to TV
control.sendKey(KEYS.KEY_HOME, function (err, res) {
if (!err) {
console.log("# Response sendKey", res);
}
});
// Send text to focused input on TV
control.sendText(
"Text to be inserted in some focused input",
function (err, res) {
if (!err) {
console.log("# Response sendText", res);
}
}
);
// Get all installed apps from TV
control.getAppsFromTV((err, res) => {
if (!err) {
console.log("# Response getAppsFromTV", res);
}
});
}, 6000);
} catch (e) {
console.log(e);
}
}
} catch (err) {
console.log("available error", err);
}
});
app.get("/turnOn", () => {
try {
control.turnOn();
} catch (e) {
console.log(e);
}
});
app.get("/getApps", () => {
if (isAvailable) {
console.log("this works");
control.getAppsFromTV((err, res) => {
if (!err) {
console.log("# Response getAppsFromTV", res);
} else {
console.log("Failed to get Apps: ", err);
}
});
} else {
console.log("err");
}
});
app.listen(3000, () => {
console.log("Server running successfully on 3000");
});