99 :license: BSD, see LICENSE for more details.
1010"""
1111import os
12- import json
1312import logging
14- from typing import List , Tuple , Any , Dict
15-
16- from .plugin import ProxyDashboardWebsocketPlugin
17-
18- from ..common .utils import bytes_
13+ from typing import List , Tuple
1914
2015from ..http .responses import permanentRedirectResponse
2116from ..http .parser import HttpParser
22- from ..http .websocket import WebsocketFrame
2317from ..http .server import HttpWebServerPlugin , HttpWebServerBasePlugin , httpProtocolTypes
2418
2519logger = logging .getLogger (__name__ )
@@ -42,24 +36,9 @@ class ProxyDashboard(HttpWebServerBasePlugin):
4236 (httpProtocolTypes .HTTPS , r'/dashboard/$' ),
4337 ]
4438
45- # Handles WebsocketAPI requests for dashboard
46- WS_ROUTES = [
47- (httpProtocolTypes .WEBSOCKET , r'/dashboard$' ),
48- ]
49-
50- def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
51- super ().__init__ (* args , ** kwargs )
52- self .plugins : Dict [str , ProxyDashboardWebsocketPlugin ] = {}
53- if b'ProxyDashboardWebsocketPlugin' in self .flags .plugins :
54- for klass in self .flags .plugins [b'ProxyDashboardWebsocketPlugin' ]:
55- p = klass (self .flags , self .client , self .event_queue )
56- for method in p .methods ():
57- self .plugins [method ] = p
58-
5939 def routes (self ) -> List [Tuple [int , str ]]:
6040 return ProxyDashboard .REDIRECT_ROUTES + \
61- ProxyDashboard .INDEX_ROUTES + \
62- ProxyDashboard .WS_ROUTES
41+ ProxyDashboard .INDEX_ROUTES
6342
6443 def handle_request (self , request : HttpParser ) -> None :
6544 if request .path == b'/dashboard/' :
@@ -76,40 +55,3 @@ def handle_request(self, request: HttpParser) -> None:
7655 b'/dashboard/proxy.html' ,
7756 ):
7857 self .client .queue (permanentRedirectResponse (b'/dashboard/' ))
79-
80- def on_websocket_open (self ) -> None :
81- logger .info ('app ws opened' )
82-
83- def on_websocket_message (self , frame : WebsocketFrame ) -> None :
84- try :
85- assert frame .data
86- message = json .loads (frame .data )
87- except UnicodeDecodeError :
88- logger .error (frame .data )
89- logger .info (frame .opcode )
90- return
91-
92- method = message ['method' ]
93- if method == 'ping' :
94- self .reply ({'id' : message ['id' ], 'response' : 'pong' })
95- elif method in self .plugins :
96- self .plugins [method ].handle_message (message )
97- else :
98- logger .info (frame .data )
99- logger .info (frame .opcode )
100- self .reply ({'id' : message ['id' ], 'response' : 'not_implemented' })
101-
102- def on_client_connection_close (self ) -> None :
103- logger .info ('app ws closed' )
104- # TODO(abhinavsingh): unsubscribe
105-
106- def reply (self , data : Dict [str , Any ]) -> None :
107- self .client .queue (
108- memoryview (
109- WebsocketFrame .text (
110- bytes_ (
111- json .dumps (data ),
112- ),
113- ),
114- ),
115- )
0 commit comments