22
22
using System . Net . WebSockets ;
23
23
using System . Threading . Tasks ;
24
24
using System . Threading ;
25
- using System . Text . Json ;
26
25
using System . Text ;
27
26
using OpenQA . Selenium . Internal . Logging ;
28
- using System . Text . Json . Serialization ;
29
27
30
28
#nullable enable
31
29
@@ -45,7 +43,7 @@ public async Task ConnectAsync(CancellationToken cancellationToken)
45
43
await _webSocket . ConnectAsync ( _uri , cancellationToken ) . ConfigureAwait ( false ) ;
46
44
}
47
45
48
- public async Task < T > ReceiveAsJsonAsync < T > ( JsonSerializerContext jsonSerializerContext , CancellationToken cancellationToken )
46
+ public async Task < byte [ ] > ReceiveAsync ( CancellationToken cancellationToken )
49
47
{
50
48
using var ms = new MemoryStream ( ) ;
51
49
@@ -61,31 +59,28 @@ public async Task<T> ReceiveAsJsonAsync<T>(JsonSerializerContext jsonSerializerC
61
59
62
60
ms . Seek ( 0 , SeekOrigin . Begin ) ;
63
61
62
+ byte [ ] data = ms . ToArray ( ) ;
63
+
64
64
if ( _logger . IsEnabled ( LogEventLevel . Trace ) )
65
65
{
66
- _logger . Trace ( $ "BiDi RCV <-- { Encoding . UTF8 . GetString ( ms . ToArray ( ) ) } ") ;
66
+ _logger . Trace ( $ "BiDi RCV <-- { Encoding . UTF8 . GetString ( data ) } ") ;
67
67
}
68
68
69
- var res = await JsonSerializer . DeserializeAsync ( ms , typeof ( T ) , jsonSerializerContext , cancellationToken ) . ConfigureAwait ( false ) ;
70
-
71
- return ( T ) res ! ;
69
+ return data ;
72
70
}
73
71
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 )
76
73
{
77
- var buffer = JsonSerializer . SerializeToUtf8Bytes ( command , typeof ( TCommand ) , jsonSerializerContext ) ;
78
-
79
74
await _socketSendSemaphoreSlim . WaitAsync ( cancellationToken ) ;
80
75
81
76
try
82
77
{
83
78
if ( _logger . IsEnabled ( LogEventLevel . Trace ) )
84
79
{
85
- _logger . Trace ( $ "BiDi SND --> { Encoding . UTF8 . GetString ( buffer ) } ") ;
80
+ _logger . Trace ( $ "BiDi SND --> { Encoding . UTF8 . GetString ( data ) } ") ;
86
81
}
87
82
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 ) ;
89
84
}
90
85
finally
91
86
{
0 commit comments