Skip to content

Commit

Permalink
Merge pull request #14 from vzakharchenko/Black_screen_afterinstallat…
Browse files Browse the repository at this point in the history
…ion_on_tv

Black screen after installation on TV
  • Loading branch information
vzakharchenko authored Mar 7, 2021
2 parents 858bec9 + 0774783 commit ba8ef9f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 37 deletions.
Binary file modified CameraDevice/CameraDevice.wgt
Binary file not shown.
86 changes: 49 additions & 37 deletions CameraDevice/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
const serverInfo = {
ip: localStorage.getItem('SERVER.IP') || '0.0.0.0', // <-- Server IP
port: localStorage.getItem('SERVER.PORT') || '3004',
inited: localStorage.getItem('SERVER.INITED') || false,
};

let queue = [];
Expand All @@ -15,6 +16,7 @@ let changeChannel = false;
const next = () => {
const xhr = new XMLHttpRequest();
const url = `http://${serverInfo.ip}:${serverInfo.port}/next?width=${window.screen.width}&height=${window.screen.height}`;
xhr.withCredentials = true;
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === xhr.DONE) {
Expand Down Expand Up @@ -51,24 +53,54 @@ const prev = () => {
xhr.send(null);
};

const getInfo = (callback, error) => {
if (!serverInfo.inited) {
window.location.href = '/server.html';
} else {
const xhr = new XMLHttpRequest();
const url = `http://${serverInfo.ip}:${serverInfo.port}/info?width=${window.screen.width}&height=${window.screen.height}`;
xhr.open('GET', url, true);
xhr.withCredentials = true;
xhr.onreadystatechange = function () {
if (xhr.readyState === xhr.DONE) {
if (xhr.status === 200) {
callback(JSON.parse(xhr.responseText));
} else {
window.location.href = '/server.html';
}
}
};
xhr.onerror = function (e) {
window.location.href = '/server.html';
console.error(xhr.statusText);
};
xhr.send();
}
};

const reload = () => {
const xhr = new XMLHttpRequest();
const url = `http://${serverInfo.ip}:${serverInfo.port}/reload?width=${window.screen.width}&height=${window.screen.height}`;
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === xhr.DONE) {
if (xhr.status === 200) {
console.log(xhr.responseText);
location.reload();
} else {
console, error('There was a problem with the request.');
if (serverInfo.inited) {
const xhr = new XMLHttpRequest();
const url = `http://${serverInfo.ip}:${serverInfo.port}/reload?width=${window.screen.width}&height=${window.screen.height}`;
xhr.withCredentials = true;
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === xhr.DONE) {
if (xhr.status === 200) {
console.log(xhr.responseText);
location.reload();
} else {
console.error('There was a problem with the request.');
}
}
}
};
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
xhr.send(null);
};
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
xhr.send();
} else {
getInfo();
}
};

function getChannel(ch) {
Expand All @@ -90,7 +122,7 @@ const sel0 = (c) => {
console.log(xhr.responseText);
location.reload();
} else {
console, error('There was a problem with the request.');
console.error('There was a problem with the request.');
}
}
};
Expand All @@ -114,26 +146,6 @@ const sel = (c) => {
}
};

const getInfo = (callback, error) => {
const xhr = new XMLHttpRequest();
const url = `http://${serverInfo.ip}:${serverInfo.port}/info?width=${window.screen.width}&height=${window.screen.height}`;
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === xhr.DONE) {
if (xhr.status === 200) {
callback(JSON.parse(xhr.responseText));
} else {
window.location.href = '/server.html';
}
}
};
xhr.onerror = function (e) {
window.location.href = '/server.html';
console.error(xhr.statusText);
};
xhr.send(null);
};

//
// channelList()

Expand Down
1 change: 1 addition & 0 deletions CameraDevice/server.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
if (xhr.status === 200) {
localStorage.setItem("SERVER.IP", ip);
localStorage.setItem("SERVER.PORT", port);
localStorage.setItem("SERVER.INITED", 'true');
window.location.href = '/index.html'
} else {
console.error(xhr.responseText);
Expand Down

0 comments on commit ba8ef9f

Please sign in to comment.