Closed funkyfunked closed 8 months ago
I am having the same issue. It seems like the connection cannot be reestablished after the TV is rebooted
I tested further - I don't think it's a problem on my end.
Reinstalled and changed everything server related to my NAS running debian. Same problem, exactly the same behaviour of reconnection error after reboot/power cycle. MAybe important to know - it does only happen if the TV is really powered off. If I press the power button for 2 sec so that the bootup screen is shown, it doesn't reconnect to the server 100% of attempts.
If I just let the TV sleep for 1 min (short press of power button), it may still work, but not always.
Here is some more info:
TV Tizen OS 7 (Samsung S90C)
Server: Debian 11.7 Node.js v21.5.0
Debug output of the server (see my comment in the last lines):
root@nas:/opt/tizenserver/TizenTube# node . (node:2955452) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time (Use
node --trace-warnings ...
to show where the warning was created) ADB connection established Config read failed: SyntaxError: Unexpected token u in JSON at position 0 undefined Key event: keydown 40 40 false undefined Key event: keyup 40 40 false undefined Key event: keydown 38 38 false undefined Key event: keyup 38 38 false undefined Adding notification container undefined Key event: keydown 404 404 false undefined Taking over! undefined Showing and focusing! undefined uiContainer focused! undefined Key event: keyup 404 404 false undefined Taking over! undefined Key event: keydown 27 27 false undefined uiContainer key event: keydown 27 undefined uiContainer blured! undefined Key event: keyup 27 27 false undefined Key event: keydown 406 406 false undefined Taking over! undefined Showing and focusing! undefined speedUIContainer focused! undefined Key event: keyup 406 406 false undefined Taking over! undefined Key event: keydown 27 27 false undefined speedUIContainer key event: keydown 27 undefined speedUIContainer blured! undefined Key event: keyup 27 27 false undefined Key event: keydown 39 39 false undefined Key event: keyup 39 39 false undefined Key event: keydown 37 37 false undefined Key event: keyup 37 37 false undefined Key event: keydown 40 40 false undefined Key event: keyup 40 40 false undefined Key event: keydown 38 38 false undefined Key event: keyup 38 38 false undefined Key event: keydown 13 13 false undefined Key event: keyup 13 13 false undefined hashchange RV1HKodAvo0&list=RDCMUCQvTDmHza8erxZqDkjQ4bQQ null null true undefined RV1HKodAvo0&list=RDCMUCQvTDmHza8erxZqDkjQ4bQQ Got it: undefined undefined RV1HKodAvo0&list=RDCMUCQvTDmHza8erxZqDkjQ4bQQ No segments found. undefined Key event: keydown 13 13 false undefined Key event: keyup 13 13 false undefined Key event: keydown 27 27 false undefined Key event: keyup 27 27 false undefined Key event: keydown 27 27 false undefined Key event: keyup 27 27 false undefined hashchange [object Object] RV1HKodAvo0&list=RDCMUCQvTDmHza8erxZqDkjQ4bQQ undefined Key event: keydown 27 27 false undefined Key event: keyup 27 27 false undefined Key event: keydown 27 27 false undefined Key event: keyup 27 27 false undefined Key event: keydown 40 40 false undefined Key event: keyup 40 40 false undefined Key event: keydown 13 13 false undefined Key event: keyup 13 13 false undefined Config read failed: SyntaxError: Unexpected token u in JSON at position 0 undefined Key event: keydown 40 40 false undefined Key event: keyup 40 40 false undefined Key event: keydown 13 13 false undefined Key event: keyup 13 13 false undefined ADB connection closed, reconnecting... <---------- COMMENT: Right here the TV is restarted, then it doesn't work anymore ADB connection established
I see something like that happening as well, but this happens on a single connection try. It connects, disconnects and directly reconnects in a single Launcher start. Afterwards the Launcher does not do anything (loading circle is turning for 2-3 secs and then nothing, I see the home screen of the TV again.) As also reported in https://github.com/reisxd/TizenTube/issues/29#issuecomment-1874144027
ADB connection established ADB connection closed, reconnecting... ADB connection established
My assumption is that the "ADB connection closed, reconnecting..." is leading to the same issue as when the TV would turn off.
Using the same TV Model: Tizen OS 7 (Samsung S90C)
Same problem here (it works but when tv is restarted, launcher doesn't do anything and it returns to the main menu).
I am using pm2 but I was curious on how guys do you keep the script (index.js) running ?
Also, it would be interesting to know what is the OS / configuration of each, especially those who have no issues. I am running the script on my Rasperry Pi 3B+ running on raspbian and connected to network via wifi.
TV is on Tizen OS 5 (Samsung UE50RU) (tbc)
Same problem here (it works but when tv is restarted, launcher doesn't do anything and it returns to the main menu).
I am using pm2 but I was curious on how guys do you keep the script (index.js) running ?
Also, it would be interesting to know what is the OS / configuration of each, especially those who have no issues. I am running the script on my Rasperry Pi 3B+ running on raspbian and connected to network via wifi.
TV is on Tizen OS 5 (Samsung UE50RU) (tbc)
There is a problem with the adb (re-)connection to the server in the latest release. I switched to an older commit that uses sdb instead of adb. Everything works for me now with this release:
https://github.com/reisxd/TizenTube/tree/5a01cb03abe69e3ed7983d6fdb34cdd898575777
Sometimes the launcher closes after the first launch on the TV, but the second time it always works for me. I also set the server up with pm2 to automatically restart the server in case of a crash.
You can read up on it on discord, thanks to the suggestion of SomeOne who found the solution.
You can also only partially revert to this commit to keep the latest updates (play/pause button on remote working for example).
Have fun :)
Hello @funkyfunked, do you want to test my attempt ? Launch first try even after reboot index.js
import { WebSocketServer } from 'ws';
import adbhost from 'adbhost';
import startDebugging from './debuggerController.js';
import Config from './config.json' assert { type: 'json' };
var adb_exists=false;
var executed_launcher=false;
var mute_logs=false;
var multiple_fail=0;
var adb;
AdbConnection();
function AdbConnection() {
if(adb_exists){
// Close the existing connection before reconnecting
adb._stream.end();
// Remove previous event handlers before attaching new ones
adb._stream.removeAllListeners('error');
adb._stream.removeAllListeners('connect');
}
// Attempt to create a new ADB connection
createAdbConnection();
}
function createAdbConnection() {
//Create connection
adb = adbhost.createConnection({ host: Config.tvIP, port: 26101 });
//Handler for successful connection
adb._stream.on('connect', () => {
console.log('ADB connection established');
multiple_fail=0;
mute_logs=false;
// Re-Launch the app, otherwise we would need to start the launcher manually again (needs testing but seems fine)
// Do that only if it was a reconnect and that the launcher was previously launched
if(adb_exists && executed_launcher){
const shellCmd = adb.createStream(`shell:0 debug ${Config.appId}${Config.isTizen3 ? ' 0' : ''}`);
shellCmd.on('data', data => {
const dataString = data.toString();
if (dataString.includes('debug')) {
const port = dataString.substr(dataString.indexOf(':') + 1, 6).replace(' ', '');
startDebugging(port);
}
});
}
});
// Handler for error of connection (with recursivity for reconnecting)
adb._stream.on('error', () => {
if(!mute_logs){ //Mute logs if too many retries
console.log('ADB connection closed, reconnecting...');
multiple_fail++;
if(multiple_fail>5){
mute_logs=true;
console.log('Continuing retries silently...');
}
}
AdbConnection(); //Retry connection
});
adb_exists=true;
}
const wss = new WebSocketServer({ port: 3000 });
wss.on('connection', ws => {
ws.on('message', message => {
let msg;
try {
msg = JSON.parse(message.toString());
} catch {
ws.send(JSON.stringify({
error: 'Invalid data'
}));
return;
}
switch (msg.e) {
case 'launch': {
ws.send(JSON.stringify({
ok: true
}));
executed_launcher=true;
// Launch the app
const shellCmd = adb.createStream(`shell:0 debug ${Config.appId}${Config.isTizen3 ? ' 0' : ''}`);
shellCmd.on('data', data => {
const dataString = data.toString();
if (dataString.includes('debug')) {
const port = dataString.substr(dataString.indexOf(':') + 1, 6).replace(' ', '');
startDebugging(port);
}
});
break;
}
default: {
ws.send(JSON.stringify({
error: 'Unknown event'
}));
break;
}
}
});
});
// If the server is running on Android and the CWD is /, change it (required for the Android app)
if (process.cwd() === '/' && process.platform === 'android') {
process.chdir('/data/user/0/io.gh.reisxd.tizentube/files/tizentube');
}
Works like a charm for me now, even after TV reboot. Thank you very much @ThowZzy!
Maybe open a PR with this code if it works for everyone?
Yeah I might, im already submitting these on discord to reis for his opinion.
I wrote another approach if you want, its a bit cleaner. (this time I edited also the debugger file)
Edit : It is merged to main
Hello,
I'm running the node server on Ubuntu 22.04, and it works GREAT connecting for the first time, however:
If I turn off the TV, then turn it on again the Launcher-app is running in a time-out, or doesn't do anything at all.
It seems the Launcher on the TV cannot reconnect to the server after a reboot of the TV.
If i restart the server the Launcher can connect and run perfectly again - until the next reboot and so on.
I ran 'node .' in debug mode on the server. Here is the output. I started the Launcher the first time connecting to fresh started server and played a video. After that I rebooted the TV and tried to run the Launcher-app again. The Launcher won't start anymore.
Anyone else experiencing this or is it just me? Why can't the Launcher reconnect?
Here is the complete log output:
tizenserver.log