Explorar el Código

fix(WS): leaving a page doesn't clear listeners from old page e.g. switching stations

Signed-off-by: Jonathan <theflametrooper@gmail.com>
Jonathan hace 4 años
padre
commit
eba2bde79f
Se han modificado 2 ficheros con 10 adiciones y 3 borrados
  1. 0 1
      frontend/src/pages/Home.vue
  2. 10 2
      frontend/src/ws.js

+ 0 - 1
frontend/src/pages/Home.vue

@@ -615,7 +615,6 @@ export default {
 		});
 
 		this.socket.on("event:station.nextSong", res => {
-			console.log("NEXT SONG!");
 			const station = this.stations.find(
 				station => station._id === res.data.stationId
 			);

+ 10 - 2
frontend/src/ws.js

@@ -36,16 +36,24 @@ export default {
 		onDisconnect.temp = [];
 	},
 
-	destroyListeners: () =>
+	destroyListeners() {
 		Object.keys(CB_REFS).forEach(id => {
 			if (
 				id.indexOf("$event:") !== -1 &&
 				id.indexOf("$event:keep.") === -1
 			)
 				delete CB_REFS[id];
-		}),
+		});
+
+		// destroy all listeners that aren't site-wide
+		Object.keys(this.socket.dispatcher.listeners).forEach(type => {
+			if (type.indexOf("keep.") === -1 && type !== "ready")
+				delete this.socket.dispatcher.listeners[type];
+		});
+	},
 
 	destroyModalListeners(modal) {
+		// destroy all listeners for a specific modal
 		Object.keys(this.socket.dispatcher.listeners).forEach(type =>
 			this.socket.dispatcher.listeners[type].forEach((element, index) => {
 				if (element.options && element.options.modal === modal)