2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- part of dds;
5
+ import 'dart:async' ;
6
+
7
+ import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
8
+ import 'package:meta/meta.dart' ;
9
+ import 'package:sse/server/sse_handler.dart' ;
10
+ import 'package:stream_channel/stream_channel.dart' ;
11
+ import 'package:web_socket_channel/web_socket_channel.dart' ;
12
+
13
+ import '../dds.dart' ;
14
+ import 'constants.dart' ;
15
+ import 'dds_impl.dart' ;
16
+ import 'rpc_error_codes.dart' ;
17
+ import 'stream_manager.dart' ;
6
18
7
19
/// Representation of a single DDS client which manages the connection and
8
20
/// DDS request intercepting / forwarding.
9
- class _DartDevelopmentServiceClient {
10
- factory _DartDevelopmentServiceClient .fromWebSocket (
21
+ class DartDevelopmentServiceClient {
22
+ factory DartDevelopmentServiceClient .fromWebSocket (
11
23
DartDevelopmentService dds,
12
24
WebSocketChannel ws,
13
25
json_rpc.Peer vmServicePeer,
14
26
) =>
15
- _DartDevelopmentServiceClient ._(
27
+ DartDevelopmentServiceClient ._(
16
28
dds,
17
29
ws,
18
30
vmServicePeer,
19
31
);
20
32
21
- factory _DartDevelopmentServiceClient .fromSSEConnection (
33
+ factory DartDevelopmentServiceClient .fromSSEConnection (
22
34
DartDevelopmentService dds,
23
35
SseConnection sse,
24
36
json_rpc.Peer vmServicePeer,
25
37
) =>
26
- _DartDevelopmentServiceClient ._(
38
+ DartDevelopmentServiceClient ._(
27
39
dds,
28
40
sse,
29
41
vmServicePeer,
30
42
);
31
43
32
- _DartDevelopmentServiceClient ._(
44
+ DartDevelopmentServiceClient ._(
33
45
this .dds,
34
46
this .connection,
35
47
json_rpc.Peer vmServicePeer,
@@ -39,7 +51,7 @@ class _DartDevelopmentServiceClient {
39
51
// .cast<String>() as cast() results in addStream() being called,
40
52
// binding the underlying sink. This results in a StateError being thrown
41
53
// if we try and add directly to the sink, which we do for binary events
42
- // in _StreamManager 's streamNotify().
54
+ // in StreamManager 's streamNotify().
43
55
StreamChannel <String >(
44
56
connection.stream.cast (),
45
57
StreamController (sync : true )
@@ -88,21 +100,21 @@ class _DartDevelopmentServiceClient {
88
100
_clientPeer.registerMethod ('streamListen' , (parameters) async {
89
101
final streamId = parameters['streamId' ].asString;
90
102
await dds.streamManager.streamListen (this , streamId);
91
- return _RPCResponses .success;
103
+ return RPCResponses .success;
92
104
});
93
105
94
106
_clientPeer.registerMethod ('streamCancel' , (parameters) async {
95
107
final streamId = parameters['streamId' ].asString;
96
108
await dds.streamManager.streamCancel (this , streamId);
97
- return _RPCResponses .success;
109
+ return RPCResponses .success;
98
110
});
99
111
100
112
_clientPeer.registerMethod ('registerService' , (parameters) async {
101
113
final serviceId = parameters['service' ].asString;
102
114
final alias = parameters['alias' ].asString;
103
115
if (services.containsKey (serviceId)) {
104
- throw _RpcErrorCodes .buildRpcException (
105
- _RpcErrorCodes .kServiceAlreadyRegistered,
116
+ throw RpcErrorCodes .buildRpcException (
117
+ RpcErrorCodes .kServiceAlreadyRegistered,
106
118
);
107
119
}
108
120
services[serviceId] = alias;
@@ -112,7 +124,7 @@ class _DartDevelopmentServiceClient {
112
124
serviceId,
113
125
alias,
114
126
);
115
- return _RPCResponses .success;
127
+ return RPCResponses .success;
116
128
});
117
129
118
130
_clientPeer.registerMethod (
@@ -140,9 +152,8 @@ class _DartDevelopmentServiceClient {
140
152
'getLogHistorySize' ,
141
153
(parameters) => {
142
154
'type' : 'Size' ,
143
- 'size' : _StreamManager
144
- .loggingRepositories[_StreamManager .kLoggingStream]
145
- .bufferSize,
155
+ 'size' : StreamManager
156
+ .loggingRepositories[StreamManager .kLoggingStream].bufferSize,
146
157
});
147
158
148
159
_clientPeer.registerMethod ('setLogHistorySize' , (parameters) {
@@ -152,9 +163,9 @@ class _DartDevelopmentServiceClient {
152
163
"'size' must be greater or equal to zero" ,
153
164
);
154
165
}
155
- _StreamManager .loggingRepositories[_StreamManager .kLoggingStream]
166
+ StreamManager .loggingRepositories[StreamManager .kLoggingStream]
156
167
.resize (size);
157
- return _RPCResponses .success;
168
+ return RPCResponses .success;
158
169
});
159
170
160
171
_clientPeer.registerMethod ('getDartDevelopmentServiceVersion' ,
@@ -219,21 +230,21 @@ class _DartDevelopmentServiceClient {
219
230
[
220
231
// Forward the request to the service client or...
221
232
serviceClient.sendRequest (method, parameters.asMap).catchError ((_) {
222
- throw _RpcErrorCodes .buildRpcException (
223
- _RpcErrorCodes .kServiceDisappeared,
233
+ throw RpcErrorCodes .buildRpcException (
234
+ RpcErrorCodes .kServiceDisappeared,
224
235
);
225
236
}, test: (error) => error is StateError ),
226
237
// if the service client closes, return an error response.
227
238
serviceClient._clientPeer.done.then (
228
- (_) => throw _RpcErrorCodes .buildRpcException (
229
- _RpcErrorCodes .kServiceDisappeared,
239
+ (_) => throw RpcErrorCodes .buildRpcException (
240
+ RpcErrorCodes .kServiceDisappeared,
230
241
),
231
242
),
232
243
],
233
244
);
234
245
}
235
246
throw json_rpc.RpcException (
236
- _RpcErrorCodes .kMethodNotFound,
247
+ RpcErrorCodes .kMethodNotFound,
237
248
'Unknown service: ${parameters .method }' ,
238
249
);
239
250
});
@@ -260,12 +271,12 @@ class _DartDevelopmentServiceClient {
260
271
String get name => _name;
261
272
262
273
// NOTE: this should not be called directly except from:
263
- // - `_ClientManager ._clearClientName`
264
- // - `_ClientManager ._setClientNameHelper`
274
+ // - `ClientManager ._clearClientName`
275
+ // - `ClientManager ._setClientNameHelper`
265
276
set name (String n) => _name = n ?? defaultClientName;
266
277
String _name;
267
278
268
- final _DartDevelopmentService dds;
279
+ final DartDevelopmentServiceImpl dds;
269
280
final StreamChannel connection;
270
281
final Map <String , String > services = {};
271
282
final json_rpc.Peer _vmServicePeer;
0 commit comments