2222using System . Net . WebSockets ;
2323using System . Threading . Tasks ;
2424using System . Threading ;
25- using System . Text . Json ;
2625using System . Text ;
2726using OpenQA . Selenium . Internal . Logging ;
28- using System . Text . Json . Serialization ;
2927
3028#nullable enable
3129
@@ -45,7 +43,7 @@ public async Task ConnectAsync(CancellationToken cancellationToken)
4543 await _webSocket . ConnectAsync ( _uri , cancellationToken ) . ConfigureAwait ( false ) ;
4644 }
4745
48- public async Task < T > ReceiveAsJsonAsync < T > ( JsonSerializerContext jsonSerializerContext , CancellationToken cancellationToken )
46+ public async Task < byte [ ] > ReceiveAsync ( CancellationToken cancellationToken )
4947 {
5048 using var ms = new MemoryStream ( ) ;
5149
@@ -61,31 +59,28 @@ public async Task<T> ReceiveAsJsonAsync<T>(JsonSerializerContext jsonSerializerC
6159
6260 ms . Seek ( 0 , SeekOrigin . Begin ) ;
6361
62+ byte [ ] data = ms . ToArray ( ) ;
63+
6464 if ( _logger . IsEnabled ( LogEventLevel . Trace ) )
6565 {
66- _logger . Trace ( $ "BiDi RCV <-- { Encoding . UTF8 . GetString ( ms . ToArray ( ) ) } ") ;
66+ _logger . Trace ( $ "BiDi RCV <-- { Encoding . UTF8 . GetString ( data ) } ") ;
6767 }
6868
69- var res = await JsonSerializer . DeserializeAsync ( ms , typeof ( T ) , jsonSerializerContext , cancellationToken ) . ConfigureAwait ( false ) ;
70-
71- return ( T ) res ! ;
69+ return data ;
7270 }
7371
74- public async Task SendAsJsonAsync < TCommand > ( TCommand command , JsonSerializerContext jsonSerializerContext , CancellationToken cancellationToken )
75- where TCommand : Command
72+ public async Task SendAsync ( byte [ ] data , CancellationToken cancellationToken )
7673 {
77- var buffer = JsonSerializer . SerializeToUtf8Bytes ( command , typeof ( TCommand ) , jsonSerializerContext ) ;
78-
7974 await _socketSendSemaphoreSlim . WaitAsync ( cancellationToken ) ;
8075
8176 try
8277 {
8378 if ( _logger . IsEnabled ( LogEventLevel . Trace ) )
8479 {
85- _logger . Trace ( $ "BiDi SND --> { Encoding . UTF8 . GetString ( buffer ) } ") ;
80+ _logger . Trace ( $ "BiDi SND --> { Encoding . UTF8 . GetString ( data ) } ") ;
8681 }
8782
88- await _webSocket . SendAsync ( new ArraySegment < byte > ( buffer ) , WebSocketMessageType . Text , true , cancellationToken ) . ConfigureAwait ( false ) ;
83+ await _webSocket . SendAsync ( new ArraySegment < byte > ( data ) , WebSocketMessageType . Text , true , cancellationToken ) . ConfigureAwait ( false ) ;
8984 }
9085 finally
9186 {
0 commit comments