@@ -9,19 +9,22 @@ class WebsocketsJoiner:
99 def __init__ (
1010 self ,
1111 authenticator : auth .IClientAuthenticator = None ,
12- serializer : serializers .Serializer = serializers . JSONSerializer () ,
12+ serializer : serializers .Serializer = None ,
1313 ws_config : types .WebsocketConfig = types .WebsocketConfig (),
1414 ):
1515 self ._authenticator = authenticator
1616 self ._serializer = serializer
1717 self ._ws_config = ws_config
1818
1919 def join (self , uri : str , realm : str ) -> types .BaseSession :
20- transport = WebSocketTransport .connect (
21- uri ,
22- subprotocols = [helpers .get_ws_subprotocol (serializer = self ._serializer )],
23- config = self ._ws_config ,
24- )
20+ if self ._serializer is None :
21+ subprotocols = helpers .WS_SUBPROTOCOLS
22+ else :
23+ subprotocols = [helpers .get_ws_subprotocol (serializer = self ._serializer )]
24+
25+ transport = WebSocketTransport .connect (uri , subprotocols = subprotocols , config = self ._ws_config )
26+ if self ._serializer is None :
27+ self ._serializer = helpers .get_serializer (transport .subprotocol ())
2528
2629 j : Joiner = joiner .Joiner (realm , serializer = self ._serializer , authenticator = self ._authenticator )
2730 transport .write (j .send_hello ())
@@ -39,19 +42,22 @@ class AsyncWebsocketsJoiner:
3942 def __init__ (
4043 self ,
4144 authenticator : auth .IClientAuthenticator = None ,
42- serializer : serializers .Serializer = serializers . JSONSerializer () ,
45+ serializer : serializers .Serializer = None ,
4346 ws_config : types .WebsocketConfig = types .WebsocketConfig (),
4447 ):
4548 self ._ws_config = ws_config
4649 self ._authenticator = authenticator
4750 self ._serializer = serializer
4851
4952 async def join (self , uri : str , realm : str ) -> types .AsyncBaseSession :
50- transport = await AsyncWebSocketTransport .connect (
51- uri ,
52- subprotocols = [helpers .get_ws_subprotocol (serializer = self ._serializer )],
53- config = self ._ws_config ,
54- )
53+ if self ._serializer is None :
54+ subprotocols = helpers .WS_SUBPROTOCOLS
55+ else :
56+ subprotocols = [helpers .get_ws_subprotocol (serializer = self ._serializer )]
57+
58+ transport = await AsyncWebSocketTransport .connect (uri , subprotocols = subprotocols , config = self ._ws_config )
59+ if self ._serializer is None :
60+ self ._serializer = helpers .get_serializer (transport .subprotocol ())
5561
5662 j : Joiner = joiner .Joiner (realm , serializer = self ._serializer , authenticator = self ._authenticator )
5763 await transport .write (j .send_hello ())
0 commit comments