Przeglądaj źródła

Don't import socket-io instead instantiate once and add as global variable, use rooms as well

sbkwgh 8 lat temu
rodzic
commit
bdee2d894b
2 zmienionych plików z 5 dodań i 2 usunięć
  1. 2 2
      src/components/routes/Index.vue
  2. 3 0
      src/main.js

+ 2 - 2
src/components/routes/Index.vue

@@ -61,8 +61,6 @@
 
 	import AjaxErrorHandler from '../../assets/js/errorHandler'
 
-	let socket = require('socket.io-client')()
-
 	export default {
 		name: 'index',
 		components: {
@@ -200,6 +198,7 @@
 			this.selectedCategory = this.$route.path.split('/')[2].toUpperCase()
 			this.getThreads(true)
 
+			socket.emit('join', 'index')
 			socket.on('new thread', data => {
 				if(data.value === this.selectedCategory || this.selectedCategory == 'ALL') {
 					this.newThreads++
@@ -207,6 +206,7 @@
 			})
 		},
 		destroyed () {
+			socket.emit('leave', 'index')
 			socket.off('new thread')
 		}
 	}

+ 3 - 0
src/main.js

@@ -1,3 +1,6 @@
+import IO from 'socket.io-client'
+window.socket = IO()
+
 import Vue from 'vue'
 import VueRouter from 'vue-router'
 import Vuex from 'vuex'