Try removing event listener
This commit is contained in:
parent
51022df869
commit
ac42423e5f
21
app/ui.js
21
app/ui.js
|
@ -1446,20 +1446,6 @@ const UI = {
|
||||||
UI.rfb.enableQOI = true;
|
UI.rfb.enableQOI = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._supportsBroadcastChannel = (typeof BroadcastChannel !== "undefined");
|
|
||||||
if (this._supportsBroadcastChannel) {
|
|
||||||
this._controlChannel = new BroadcastChannel("registrationChannel");
|
|
||||||
this._controlChannel.addEventListener('message', (event) => {
|
|
||||||
switch (event.data.eventType) {
|
|
||||||
case 'identify':
|
|
||||||
UI.identify(event.data)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Only explicitly request permission to clipboard on browsers that support binary clipboard access
|
//Only explicitly request permission to clipboard on browsers that support binary clipboard access
|
||||||
if (supportsBinaryClipboard()) {
|
if (supportsBinaryClipboard()) {
|
||||||
// explicitly request permission to the clipboard
|
// explicitly request permission to the clipboard
|
||||||
|
@ -1860,13 +1846,12 @@ const UI = {
|
||||||
* ==============*/
|
* ==============*/
|
||||||
|
|
||||||
_identify(e) {
|
_identify(e) {
|
||||||
|
UI.identify()
|
||||||
UI.rfb.identify(UI.monitors)
|
UI.rfb.identify(UI.monitors)
|
||||||
},
|
},
|
||||||
|
|
||||||
identify(data) {
|
identify(data) {
|
||||||
const screenID = UI.monitors[0].id
|
document.getElementById('noVNC_identify_monitor').innerHTML = '1'
|
||||||
const screen = data.screens.find(el => el.id === screenID)
|
|
||||||
document.getElementById('noVNC_identify_monitor').innerHTML = screen.num
|
|
||||||
document.getElementById('noVNC_identify_monitor').classList.add("show")
|
document.getElementById('noVNC_identify_monitor').classList.add("show")
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
document.getElementById('noVNC_identify_monitor').classList.remove("show")
|
document.getElementById('noVNC_identify_monitor').classList.remove("show")
|
||||||
|
@ -2855,7 +2840,7 @@ const UI = {
|
||||||
|
|
||||||
// UI.rfb.applyScreenPlan(screenPlan); // applyScreenPlan is triggered in UI.updateMonitors
|
// UI.rfb.applyScreenPlan(screenPlan); // applyScreenPlan is triggered in UI.updateMonitors
|
||||||
UI.updateMonitors(screenPlan)
|
UI.updateMonitors(screenPlan)
|
||||||
UI.rfb.identify(UI.monitors)
|
UI._identify(UI.monitors)
|
||||||
},
|
},
|
||||||
|
|
||||||
//Helper to add options to dropdown.
|
//Helper to add options to dropdown.
|
||||||
|
|
|
@ -9,17 +9,22 @@ const UI = {
|
||||||
connected: false,
|
connected: false,
|
||||||
screenID: null,
|
screenID: null,
|
||||||
screen: {},
|
screen: {},
|
||||||
|
supportsBroadcastChannel: (typeof BroadcastChannel !== "undefined"),
|
||||||
|
controlChannel: null,
|
||||||
//Initial Loading of the UI
|
//Initial Loading of the UI
|
||||||
prime() {
|
prime() {
|
||||||
this.start();
|
this.start();
|
||||||
|
console.log('prime')
|
||||||
},
|
},
|
||||||
|
|
||||||
//Render default UI
|
//Render default UI
|
||||||
start() {
|
start() {
|
||||||
|
console.log('prime')
|
||||||
window.addEventListener("beforeunload", (e) => {
|
window.addEventListener("beforeunload", (e) => {
|
||||||
if (UI.rfb) {
|
if (UI.rfb) {
|
||||||
UI.disconnect();
|
UI.disconnect();
|
||||||
}
|
}
|
||||||
|
console.log('beforeunload')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +33,7 @@ const UI = {
|
||||||
},
|
},
|
||||||
|
|
||||||
addDefaultHandlers() {
|
addDefaultHandlers() {
|
||||||
document.getElementById('noVNC_connect_button').addEventListener('click', UI.connect);;
|
document.getElementById('noVNC_connect_button').addEventListener('click', UI.connect);
|
||||||
},
|
},
|
||||||
|
|
||||||
getSetting(name, isBool, default_value) {
|
getSetting(name, isBool, default_value) {
|
||||||
|
@ -47,6 +52,7 @@ const UI = {
|
||||||
},
|
},
|
||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
|
console.log('connect')
|
||||||
UI.rfb = new RFB(document.getElementById('noVNC_container'),
|
UI.rfb = new RFB(document.getElementById('noVNC_container'),
|
||||||
document.getElementById('noVNC_keyboardinput'),
|
document.getElementById('noVNC_keyboardinput'),
|
||||||
"", //URL
|
"", //URL
|
||||||
|
@ -93,25 +99,12 @@ const UI = {
|
||||||
UI.rfb.enableQOI = true;
|
UI.rfb.enableQOI = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._supportsBroadcastChannel = (typeof BroadcastChannel !== "undefined");
|
if (UI.supportsBroadcastChannel) {
|
||||||
if (this._supportsBroadcastChannel) {
|
console.log('add event listener')
|
||||||
this._controlChannel = new BroadcastChannel("registrationChannel");
|
UI.controlChannel = new BroadcastChannel("registrationChannel");
|
||||||
this._controlChannel.onmessage = (event) => {
|
UI.controlChannel.addEventListener('message', UI.handleControlMessage)
|
||||||
switch (event.data.eventType) {
|
|
||||||
case 'identify':
|
|
||||||
UI.identify(event.data)
|
|
||||||
break;
|
|
||||||
case 'secondarydisconnected':
|
|
||||||
UI.updateVisualState('disconnected');
|
|
||||||
console.log(UI.screenID)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//attach this secondary display to the primary display
|
//attach this secondary display to the primary display
|
||||||
if (UI.screenID === null) {
|
if (UI.screenID === null) {
|
||||||
const screen = UI.rfb.attachSecondaryDisplay();
|
const screen = UI.rfb.attachSecondaryDisplay();
|
||||||
|
@ -131,6 +124,17 @@ const UI = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleControlMessage(event) {
|
||||||
|
switch (event.data.eventType) {
|
||||||
|
case 'identify':
|
||||||
|
UI.identify(event.data)
|
||||||
|
break;
|
||||||
|
case 'secondarydisconnected':
|
||||||
|
UI.updateVisualState('disconnected');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
updateVisualState(state) {
|
updateVisualState(state) {
|
||||||
document.documentElement.classList.remove("noVNC_connecting");
|
document.documentElement.classList.remove("noVNC_connecting");
|
||||||
document.documentElement.classList.remove("noVNC_connected");
|
document.documentElement.classList.remove("noVNC_connected");
|
||||||
|
@ -164,10 +168,12 @@ const UI = {
|
||||||
document.documentElement.classList.add("noVNC_disconnecting");
|
document.documentElement.classList.add("noVNC_disconnecting");
|
||||||
break;
|
break;
|
||||||
case 'disconnected':
|
case 'disconnected':
|
||||||
|
console.log('disconnected')
|
||||||
document.documentElement.classList.add("noVNC_disconnected");
|
document.documentElement.classList.add("noVNC_disconnected");
|
||||||
if (connect_el.classList.contains("noVNC_hidden")) {
|
if (connect_el.classList.contains("noVNC_hidden")) {
|
||||||
connect_el.classList.remove('noVNC_hidden');
|
connect_el.classList.remove('noVNC_hidden');
|
||||||
}
|
}
|
||||||
|
UI.disconnect()
|
||||||
break;
|
break;
|
||||||
case 'reconnecting':
|
case 'reconnecting':
|
||||||
transitionElem.textContent = _("Reconnecting...");
|
transitionElem.textContent = _("Reconnecting...");
|
||||||
|
@ -264,6 +270,11 @@ const UI = {
|
||||||
disconnect() {
|
disconnect() {
|
||||||
if (UI.rfb) {
|
if (UI.rfb) {
|
||||||
UI.rfb.disconnect();
|
UI.rfb.disconnect();
|
||||||
|
if (UI.supportsBroadcastChannel) {
|
||||||
|
console.log('remove')
|
||||||
|
UI.controlChannel.removeEventListener('message', UI.handleControlMessage);
|
||||||
|
UI.rfb.removeEventListener("connect", UI.connectFinished);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue