Browse Source

修复用户在线状态会自动掉线的问题。

mxd 3 years ago
parent
commit
39609fc01f

+ 5 - 9
src/components/panel/footer/magic-online.vue

@@ -33,19 +33,15 @@ const addUser = user => {
 		users.push(user)
 	}
 }
-let timer = null
 bus.$event(Socket.LOGIN_RESPONSE, ([ret, user]) => {
 	activateUserFiles.value = {}
 	users.splice(0, users.length)
-	if(timer !== null){
-		clearInterval(timer)
-	}
 	if(ret === '1') {
-		timer = setInterval(() => bus.send(Socket.PING, new Date().getTime()), 10000)
 		addUser(user)
-	} else if (ret === '-1'){
 	}
-	
+})
+bus.$event(Socket.PING, () => {
+	bus.send(Socket.PONG)
 })
 bus.$event(Socket.USER_LOGIN, ([user]) => {
 	if(constants.CLIENT_ID !== user.cid ){
@@ -55,7 +51,7 @@ bus.$event(Socket.USER_LOGIN, ([user]) => {
 			duration: 3000
 		})
 		bus.status('online.loginTips', true, user.username, user.ip)
-	} 
+	}
 	addUser(user)
 })
 bus.$event(Socket.USER_LOGOUT, ([user]) => {
@@ -95,4 +91,4 @@ bus.$event(Socket.INTO_FILE_ID, ([cid, fileId]) => processFiles(cid, fileId))
 .magic-online > span{
 	padding-left: 5px;
 }
-</style>
+</style>

+ 2 - 1
src/scripts/constants/socket.js

@@ -12,5 +12,6 @@ export default {
     ONLINE_USERS: 'online_users',
     SET_FILE_ID: 'set_file_id',
     INTO_FILE_ID: 'into_file_id',
-    PING: 'ping'
+    PING: 'ping',
+    PONG: 'pong'
 }

+ 1 - 1
src/scripts/parsing/parser.js

@@ -303,7 +303,7 @@ export class Parser {
 
 	parseReturn() {
 		let returnSpan = this.stream.expect("return").getSpan();
-		if (this.stream.match(";", false)) return new Return(returnSpan, null);
+		if (this.stream.match([';', '}'], false)) return new Return(returnSpan, null);
 		let returnValue = this.parseExpression();
 		return new Return(new Span(returnSpan, returnValue.getSpan()), returnValue);
 	}

+ 8 - 4
src/scripts/websocket.js

@@ -11,16 +11,18 @@ function MagicWebSocket(url) {
 	}
 	this.listeners = {};
 	this.future = new Promise(r => {
+		this.resolve = r
 		this.socket = new ReconnectingWebSocket(url);
 		openedSocket[url] = this
 		this.socket.onmessage = this.messageReceived;
 		this.socket.onconnecting = () => {
+			this.future = new Promise(resolve => this.resolve = resolve)
 			bus.status('message.connectDebugServer')
 		}
 		this.socket.onopen = () => {
 			bus.status('message.connectDebugServerSuccess')
 			bus.$emit('ws_open')
-			r()
+			this.resolve()
 		}
 		this.socket.onclose = () => {
 			bus.status('message.debugServerClose')
@@ -51,11 +53,13 @@ MagicWebSocket.prototype.messageReceived = function (e) {
 	bus.$emit('ws_' + msgType, args)
 }
 MagicWebSocket.prototype.send = function(msg){
-	this.future.then(() => this.socket.send(msg))
-	
+	this.future.then(() => {
+		this.socket.send(msg)
+	})
+
 }
 MagicWebSocket.prototype.close = function () {
 	this.socket.close()
 }
 
-export default MagicWebSocket
+export default MagicWebSocket