File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -375,8 +375,11 @@ async def matlab_view(req):
375
375
376
376
# WebSocket
377
377
if (
378
- reqH .get ("connection" ) == "Upgrade"
379
- and reqH .get ("upgrade" ) == "websocket"
378
+ reqH .get ("connection" )
379
+ # Fixes issue #9 on github.
380
+ and reqH .get ("connection" ).lower () == "upgrade"
381
+ and reqH .get ("upgrade" )
382
+ and reqH .get ("upgrade" ).lower () == "websocket"
380
383
and req .method == "GET"
381
384
):
382
385
ws_server = web .WebSocketResponse ()
@@ -394,6 +397,19 @@ async def wsforward(ws_from, ws_to):
394
397
async for msg in ws_from :
395
398
mt = msg .type
396
399
md = msg .data
400
+
401
+ # When a websocket is closed by the MATLAB JSD, it sends out a few http requests to the Embedded Connector about the events
402
+ # that had occured (figureWindowClosed etc.)
403
+ # The Embedded Connector responds by sending a message of type 'Error' with close code as Abnormal closure.
404
+ # When this happens, matlab-proxy can safely exit out of the loop
405
+ # and close the websocket connection it has with the Embedded Connector (ws_client)
406
+ if (
407
+ mt == aiohttp .WSMsgType .ERROR
408
+ and ws_from .close_code
409
+ == aiohttp .WSCloseCode .ABNORMAL_CLOSURE
410
+ ):
411
+ break
412
+
397
413
if mt == aiohttp .WSMsgType .TEXT :
398
414
await ws_to .send_str (md )
399
415
elif mt == aiohttp .WSMsgType .BINARY :
You can’t perform that action at this time.
0 commit comments