Ver Fonte

feat(frontend): check session active on send message to server

wangweimin há 5 anos atrás
pai
commit
7fc49c3b87

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
pywebio/html/js/pywebio.min.js


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
pywebio/html/js/pywebio.min.js.map


+ 0 - 1
webiojs/src/handlers/popup.ts

@@ -29,7 +29,6 @@ export class PopupHandler implements CommandHandler{
             // @ts-ignore
             $('.modal').modal('hide');
         }
-
     }
 
     static get_element(spec: { title: string, content: any[], closable: boolean, implicit_close: boolean, size: string }) {

+ 0 - 3
webiojs/src/models/output.ts

@@ -65,9 +65,6 @@ export function DisplayAreaButtonOnClick(this_ele: HTMLElement, callback_id: str
     if (state.CurrentSession === null)
         return console.error("can't invoke DisplayAreaButtonOnClick when WebIOController is not instantiated");
 
-    if (state.CurrentSession.closed())
-        return alert("与服务器连接已断开,请刷新页面重新操作");
-
     let val = $(this_ele).val();
     state.CurrentSession.send_message({
         event: "callback",

+ 7 - 1
webiojs/src/session.ts

@@ -79,6 +79,9 @@ export class WebSocketSession implements Session {
     }
 
     send_message(msg: ClientEvent): void {
+        if (this.closed())
+            return alert("与服务器连接已断开,请刷新页面重新操作");
+
         if (this.ws === null)
             return console.error('WebSocketWebIOSession.ws is null when invoke WebSocketWebIOSession.send_message. ' +
                 'Please call WebSocketWebIOSession.start_session first');
@@ -96,7 +99,7 @@ export class WebSocketSession implements Session {
     }
 
     closed(): boolean {
-        return this._closed || this.ws.readyState===WebSocket.CLOSED || this.ws.readyState===WebSocket.CLOSING;
+        return this._closed || this.ws.readyState === WebSocket.CLOSED || this.ws.readyState === WebSocket.CLOSING;
     }
 }
 
@@ -163,6 +166,9 @@ export class HttpSession implements Session {
     };
 
     send_message(msg: ClientEvent): void {
+        if (this.closed())
+            return alert("与服务器连接已断开,请刷新页面重新操作");
+
         if (this.debug) console.info('<<<', msg);
         $.ajax({
             type: "POST",

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff