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;
|
||||
}
|
||||
|
||||
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
|
||||
if (supportsBinaryClipboard()) {
|
||||
// explicitly request permission to the clipboard
|
||||
|
@ -1860,13 +1846,12 @@ const UI = {
|
|||
* ==============*/
|
||||
|
||||
_identify(e) {
|
||||
UI.identify()
|
||||
UI.rfb.identify(UI.monitors)
|
||||
},
|
||||
|
||||
identify(data) {
|
||||
const screenID = UI.monitors[0].id
|
||||
const screen = data.screens.find(el => el.id === screenID)
|
||||
document.getElementById('noVNC_identify_monitor').innerHTML = screen.num
|
||||
document.getElementById('noVNC_identify_monitor').innerHTML = '1'
|
||||
document.getElementById('noVNC_identify_monitor').classList.add("show")
|
||||
setTimeout(() => {
|
||||
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.updateMonitors(screenPlan)
|
||||
UI.rfb.identify(UI.monitors)
|
||||
UI._identify(UI.monitors)
|
||||
},
|
||||
|
||||
//Helper to add options to dropdown.
|
||||
|
|
|
@ -9,17 +9,22 @@ const UI = {
|
|||
connected: false,
|
||||
screenID: null,
|
||||
screen: {},
|
||||
supportsBroadcastChannel: (typeof BroadcastChannel !== "undefined"),
|
||||
controlChannel: null,
|
||||
//Initial Loading of the UI
|
||||
prime() {
|
||||
this.start();
|
||||
console.log('prime')
|
||||
},
|
||||
|
||||
//Render default UI
|
||||
start() {
|
||||
console.log('prime')
|
||||
window.addEventListener("beforeunload", (e) => {
|
||||
if (UI.rfb) {
|
||||
UI.disconnect();
|
||||
}
|
||||
console.log('beforeunload')
|
||||
});
|
||||
|
||||
|
||||
|
@ -28,7 +33,7 @@ const UI = {
|
|||
},
|
||||
|
||||
addDefaultHandlers() {
|
||||
document.getElementById('noVNC_connect_button').addEventListener('click', UI.connect);;
|
||||
document.getElementById('noVNC_connect_button').addEventListener('click', UI.connect);
|
||||
},
|
||||
|
||||
getSetting(name, isBool, default_value) {
|
||||
|
@ -47,6 +52,7 @@ const UI = {
|
|||
},
|
||||
|
||||
connect() {
|
||||
console.log('connect')
|
||||
UI.rfb = new RFB(document.getElementById('noVNC_container'),
|
||||
document.getElementById('noVNC_keyboardinput'),
|
||||
"", //URL
|
||||
|
@ -93,24 +99,11 @@ const UI = {
|
|||
UI.rfb.enableQOI = true;
|
||||
}
|
||||
|
||||
this._supportsBroadcastChannel = (typeof BroadcastChannel !== "undefined");
|
||||
if (this._supportsBroadcastChannel) {
|
||||
this._controlChannel = new BroadcastChannel("registrationChannel");
|
||||
this._controlChannel.onmessage = (event) => {
|
||||
switch (event.data.eventType) {
|
||||
case 'identify':
|
||||
UI.identify(event.data)
|
||||
break;
|
||||
case 'secondarydisconnected':
|
||||
UI.updateVisualState('disconnected');
|
||||
console.log(UI.screenID)
|
||||
break;
|
||||
if (UI.supportsBroadcastChannel) {
|
||||
console.log('add event listener')
|
||||
UI.controlChannel = new BroadcastChannel("registrationChannel");
|
||||
UI.controlChannel.addEventListener('message', UI.handleControlMessage)
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//attach this secondary display to the primary display
|
||||
if (UI.screenID === null) {
|
||||
|
@ -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) {
|
||||
document.documentElement.classList.remove("noVNC_connecting");
|
||||
document.documentElement.classList.remove("noVNC_connected");
|
||||
|
@ -164,10 +168,12 @@ const UI = {
|
|||
document.documentElement.classList.add("noVNC_disconnecting");
|
||||
break;
|
||||
case 'disconnected':
|
||||
console.log('disconnected')
|
||||
document.documentElement.classList.add("noVNC_disconnected");
|
||||
if (connect_el.classList.contains("noVNC_hidden")) {
|
||||
connect_el.classList.remove('noVNC_hidden');
|
||||
}
|
||||
UI.disconnect()
|
||||
break;
|
||||
case 'reconnecting':
|
||||
transitionElem.textContent = _("Reconnecting...");
|
||||
|
@ -264,6 +270,11 @@ const UI = {
|
|||
disconnect() {
|
||||
if (UI.rfb) {
|
||||
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