1212 ```
1313"""
1414
15- from asyncio import new_event_loop , run
15+ from asyncio import new_event_loop
1616from collections .abc import Callable , Coroutine
1717from json import JSONDecodeError , dumps , loads
1818from typing import Any , TypeVar , final
19- from uuid import uuid4
2019
2120from aiohttp .web import Application , run_app
2221from pydantic import ValidationError
23- from socketio import AsyncClient , AsyncServer # pyright: ignore [reportMissingTypeStubs]
22+ from socketio import AsyncServer # pyright: ignore [reportMissingTypeStubs]
2423from vbl_aquarium .models .ephys_link import (
2524 EphysLinkOptions ,
2625 SetDepthRequest ,
2726 SetInsideBrainRequest ,
2827 SetPositionRequest ,
2928)
30- from vbl_aquarium .models .proxy import PinpointIdResponse
3129from vbl_aquarium .utils .vbl_base_model import VBLBaseModel
3230
3331from ephys_link .__about__ import __version__
3634from ephys_link .utils .constants import (
3735 MALFORMED_REQUEST_ERROR ,
3836 PORT ,
39- PROXY_CLIENT_NOT_INITIALIZED_ERROR ,
40- SERVER_NOT_INITIALIZED_ERROR ,
4137 UNKNOWN_EVENT_ERROR ,
4238 cannot_connect_as_client_is_already_connected_error ,
4339 client_disconnected_without_being_connected_error ,
@@ -64,35 +60,24 @@ def __init__(self, options: EphysLinkOptions, platform_handler: PlatformHandler,
6460 self ._platform_handler = platform_handler
6561 self ._console = console
6662
67- # Initialize based on proxy usage.
68- self ._sio : AsyncServer | AsyncClient = AsyncClient () if self ._options .use_proxy else AsyncServer ()
69- if not self ._options .use_proxy :
70- # Exit if _sio is not a Server.
71- if not isinstance (self ._sio , AsyncServer ):
72- self ._console .critical_print (SERVER_NOT_INITIALIZED_ERROR )
73- raise TypeError (SERVER_NOT_INITIALIZED_ERROR )
63+ # Initialize server.
64+ self ._sio : AsyncServer = AsyncServer ()
7465
75- self ._app = Application ()
76- self ._sio .attach (self ._app ) # pyright: ignore [reportUnknownMemberType]
66+ self ._app = Application ()
67+ self ._sio .attach (self ._app ) # pyright: ignore [reportUnknownMemberType]
7768
78- # Bind connection events.
79- _ = self ._sio .on ("connect" , self .connect ) # pyright: ignore [reportUnknownMemberType, reportUnknownVariableType]
80- _ = self ._sio .on ("disconnect" , self .disconnect ) # pyright: ignore [reportUnknownMemberType, reportUnknownVariableType]
69+ # Bind connection events.
70+ _ = self ._sio .on ("connect" , self .connect ) # pyright: ignore [reportUnknownMemberType, reportUnknownVariableType]
71+ _ = self ._sio .on ("disconnect" , self .disconnect ) # pyright: ignore [reportUnknownMemberType, reportUnknownVariableType]
8172
8273 # Store connected client.
8374 self ._client_sid : str = ""
8475
85- # Generate Pinpoint ID for proxy usage.
86- self ._pinpoint_id = str (uuid4 ())[:8 ]
87-
8876 # Bind events.
8977 _ = self ._sio .on ("*" , self .platform_event_handler ) # pyright: ignore [reportUnknownMemberType, reportUnknownVariableType]
9078
9179 def launch (self ) -> None :
92- """Launch the server.
93-
94- Based on the options, either connect to a proxy or launch the server locally.
95- """
80+ """Launch the server."""
9681
9782 # List platform and available manipulators.
9883 self ._console .info_print ("PLATFORM" , self ._platform_handler .get_display_name ())
@@ -108,22 +93,7 @@ def launch(self) -> None:
10893 loop .close ()
10994
11095 # Launch server
111- if self ._options .use_proxy :
112- self ._console .info_print ("PINPOINT ID" , self ._pinpoint_id )
113-
114- async def connect_proxy () -> None :
115- # Exit if _sio is not a proxy client.
116- if not isinstance (self ._sio , AsyncClient ):
117- self ._console .critical_print (PROXY_CLIENT_NOT_INITIALIZED_ERROR )
118- raise TypeError (PROXY_CLIENT_NOT_INITIALIZED_ERROR )
119-
120- # noinspection HttpUrlsUsage
121- await self ._sio .connect (f"http://{ self ._options .proxy_address } :{ PORT } " ) # pyright: ignore [reportUnknownMemberType]
122- await self ._sio .wait ()
123-
124- run (connect_proxy ())
125- else :
126- run_app (self ._app , port = PORT )
96+ run_app (self ._app , port = PORT )
12797
12898 # Helper functions.
12999 def _malformed_request_response (self , request : str , data : tuple [tuple [Any ], ...]) -> str : # pyright: ignore [reportExplicitAny]
@@ -250,8 +220,6 @@ async def platform_event_handler(self, event: str, _: str, data: Any) -> str: #
250220 # Server metadata.
251221 case "get_version" :
252222 return __version__
253- case "get_pinpoint_id" :
254- return PinpointIdResponse (pinpoint_id = self ._pinpoint_id , is_requester = False ).to_json_string ()
255223 case "get_platform_info" :
256224 return (await self ._platform_handler .get_platform_info ()).to_json_string ()
257225
0 commit comments