Skip to content

Instantly share code, notes, and snippets.

@bekharsky
Last active April 10, 2023 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bekharsky/80fce4263304eedcec7a46045b1a0ebd to your computer and use it in GitHub Desktop.
Save bekharsky/80fce4263304eedcec7a46045b1a0ebd to your computer and use it in GitHub Desktop.
const WebSocket = require('ws');
const tvIP = '192.168.3.6';
const ws = new WebSocket(`wss://${tvIP}:8002/api/v2/channels/samsung.remote.control`, { rejectUnauthorized: false });
ws.onopen = () => console.log('opened.');
ws.onclose = () => console.log('closed.');
ws.onmessage = message => {
const data = JSON.parse(message.data);
if (data.event === 'ms.channel.connect') {
ws.send(JSON.stringify({
method: 'ms.remote.control',
params: {
TypeOfRemote: 'SendRemoteKey',
Cmd: 'Click',
Option: 'false',
DataOfCmd: 'KEY_MUTE',
}
}));
setTimeout(() => ws.close(), 1000);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment