Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot retrieve token #54

Open
damajor opened this issue Dec 31, 2020 · 6 comments
Open

Cannot retrieve token #54

damajor opened this issue Dec 31, 2020 · 6 comments

Comments

@damajor
Copy link

damajor commented Dec 31, 2020

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

@stingone
Copy link

Same error here...

@Neilshweky
Copy link

Did you ever find a fix for this? I get this error after about the 50th key press in a row

@Neilshweky
Copy link

any update here?

@damajor
Copy link
Author

damajor commented Apr 14, 2023

Nop :(

@Neilshweky
Copy link

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: Toxblh/samsung-tv-control#296

@Axe-Pearl
Copy link

Axe-Pearl commented Apr 26, 2023

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");
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants