OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library json_rpc_2.client; | 5 library json_rpc_2.client; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 /// | 52 /// |
53 /// If [responses] is a [StreamSink] as well as a [Stream], [requests] may be | 53 /// If [responses] is a [StreamSink] as well as a [Stream], [requests] may be |
54 /// omitted. | 54 /// omitted. |
55 /// | 55 /// |
56 /// Note that the client won't begin listening to [responses] until | 56 /// Note that the client won't begin listening to [responses] until |
57 /// [Client.listen] is called. | 57 /// [Client.listen] is called. |
58 Client.withoutJson(Stream responses, [StreamSink requests]) | 58 Client.withoutJson(Stream responses, [StreamSink requests]) |
59 : _streams = new TwoWayStream.withoutJson( | 59 : _streams = new TwoWayStream.withoutJson( |
60 "Client", responses, "responses", requests, "requests"); | 60 "Client", responses, "responses", requests, "requests"); |
61 | 61 |
62 /// Users of the library should not use this constructor. | |
63 Client.internal(this._streams); | |
64 | |
65 /// Starts listening to the underlying stream. | 62 /// Starts listening to the underlying stream. |
66 /// | 63 /// |
67 /// Returns a [Future] that will complete when the stream is closed or when it | 64 /// Returns a [Future] that will complete when the stream is closed or when it |
68 /// has an error. | 65 /// has an error. |
69 /// | 66 /// |
70 /// [listen] may only be called once. | 67 /// [listen] may only be called once. |
71 Future listen() => _streams.listen(_handleResponse); | 68 Future listen() => _streams.listen(_handleResponse); |
72 | 69 |
73 /// Closes the server's request sink and response subscription. | 70 /// Closes the server's request sink and response subscription. |
74 /// | 71 /// |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 if (response.containsKey("result")) return true; | 186 if (response.containsKey("result")) return true; |
190 | 187 |
191 if (!response.containsKey("error")) return false; | 188 if (!response.containsKey("error")) return false; |
192 var error = response["error"]; | 189 var error = response["error"]; |
193 if (error is! Map) return false; | 190 if (error is! Map) return false; |
194 if (error["code"] is! int) return false; | 191 if (error["code"] is! int) return false; |
195 if (error["message"] is! String) return false; | 192 if (error["message"] is! String) return false; |
196 return true; | 193 return true; |
197 } | 194 } |
198 } | 195 } |
OLD | NEW |