Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: lib/src/barback/web_socket_api.dart

Issue 2184303002: Make pub strong-mode clean. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/barback/transformer_isolate.dart ('k') | lib/src/command.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:io'; 6 import 'dart:io';
7 7
8 import 'package:path/path.dart' as path; 8 import 'package:path/path.dart' as path;
9 import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc; 9 import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
10 import 'package:web_socket_channel/web_socket_channel.dart'; 10 import 'package:web_socket_channel/web_socket_channel.dart';
(...skipping 10 matching lines...) Expand all
21 /// This is a [JSON-RPC 2.0](http://www.jsonrpc.org/specification) server. Its 21 /// This is a [JSON-RPC 2.0](http://www.jsonrpc.org/specification) server. Its
22 /// methods are described in the method-level documentation below. 22 /// methods are described in the method-level documentation below.
23 class WebSocketApi { 23 class WebSocketApi {
24 final AssetEnvironment _environment; 24 final AssetEnvironment _environment;
25 final json_rpc.Server _server; 25 final json_rpc.Server _server;
26 26
27 /// Whether the application should exit when this connection closes. 27 /// Whether the application should exit when this connection closes.
28 bool _exitOnClose = false; 28 bool _exitOnClose = false;
29 29
30 WebSocketApi(WebSocketChannel socket, this._environment) 30 WebSocketApi(WebSocketChannel socket, this._environment)
31 : _server = new json_rpc.Server(socket) { 31 : _server = new json_rpc.Server(socket.cast()) {
32 _server.registerMethod("urlToAssetId", _urlToAssetId); 32 _server.registerMethod("urlToAssetId", _urlToAssetId);
33 _server.registerMethod("pathToUrls", _pathToUrls); 33 _server.registerMethod("pathToUrls", _pathToUrls);
34 _server.registerMethod("serveDirectory", _serveDirectory); 34 _server.registerMethod("serveDirectory", _serveDirectory);
35 _server.registerMethod("unserveDirectory", _unserveDirectory); 35 _server.registerMethod("unserveDirectory", _unserveDirectory);
36 36
37 /// Tells the server to exit as soon as this WebSocket connection is closed. 37 /// Tells the server to exit as soon as this WebSocket connection is closed.
38 /// 38 ///
39 /// This takes no arguments and returns no results. It can safely be called 39 /// This takes no arguments and returns no results. It can safely be called
40 /// as a JSON-RPC notification. 40 /// as a JSON-RPC notification.
41 _server.registerMethod("exitOnClose", () { 41 _server.registerMethod("exitOnClose", () {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return _environment.getAssetIdForUrl(url).then((id) { 109 return _environment.getAssetIdForUrl(url).then((id) {
110 if (id == null) { 110 if (id == null) {
111 throw new json_rpc.RpcException(_Error.NOT_SERVED, 111 throw new json_rpc.RpcException(_Error.NOT_SERVED,
112 '"${url.host}:${url.port}" is not being served by pub.'); 112 '"${url.host}:${url.port}" is not being served by pub.');
113 } 113 }
114 114
115 // TODO(rnystrom): When this is hooked up to actually talk to barback to 115 // TODO(rnystrom): When this is hooked up to actually talk to barback to
116 // see if assets exist, consider supporting implicit index.html at that 116 // see if assets exist, consider supporting implicit index.html at that
117 // point. 117 // point.
118 118
119 var result = {"package": id.package, "path": id.path}; 119 var result = <String, Object>{"package": id.package, "path": id.path};
120 120
121 // Map the line. 121 // Map the line.
122 // TODO(rnystrom): Right now, source maps are not supported and it just 122 // TODO(rnystrom): Right now, source maps are not supported and it just
123 // passes through the original line. This lets the editor start using 123 // passes through the original line. This lets the editor start using
124 // this API before we've fully implemented it. See #12339 and #16061. 124 // this API before we've fully implemented it. See #12339 and #16061.
125 if (line != null) result["line"] = line; 125 if (line != null) result["line"] = line;
126 126
127 return result; 127 return result;
128 }); 128 });
129 } 129 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 Future<Map> _pathToUrls(json_rpc.Parameters params) { 181 Future<Map> _pathToUrls(json_rpc.Parameters params) {
182 var assetPath = params["path"].asString; 182 var assetPath = params["path"].asString;
183 var line = params["line"].asIntOr(null); 183 var line = params["line"].asIntOr(null);
184 184
185 return _environment.getUrlsForAssetPath(assetPath).then((urls) { 185 return _environment.getUrlsForAssetPath(assetPath).then((urls) {
186 if (urls.isEmpty) { 186 if (urls.isEmpty) {
187 throw new json_rpc.RpcException(_Error.NOT_SERVED, 187 throw new json_rpc.RpcException(_Error.NOT_SERVED,
188 'Asset path "$assetPath" is not currently being served.'); 188 'Asset path "$assetPath" is not currently being served.');
189 } 189 }
190 190
191 var result = {"urls": urls.map((url) => url.toString()).toList()}; 191 var result = <String, Object>{
192 "urls": urls.map((url) => url.toString()).toList()
193 };
192 194
193 // Map the line. 195 // Map the line.
194 // TODO(rnystrom): Right now, source maps are not supported and it just 196 // TODO(rnystrom): Right now, source maps are not supported and it just
195 // passes through the original line. This lets the editor start using 197 // passes through the original line. This lets the editor start using
196 // this API before we've fully implemented it. See #12339 and #16061. 198 // this API before we've fully implemented it. See #12339 and #16061.
197 if (line != null) result["line"] = line; 199 if (line != null) result["line"] = line;
198 200
199 return result; 201 return result;
200 }); 202 });
201 } 203 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 300 }
299 301
300 /// The pub-specific JSON RPC error codes. 302 /// The pub-specific JSON RPC error codes.
301 class _Error { 303 class _Error {
302 /// The specified directory is not being served. 304 /// The specified directory is not being served.
303 static const NOT_SERVED = 1; 305 static const NOT_SERVED = 1;
304 306
305 /// The specified directory overlaps one or more ones already being served. 307 /// The specified directory overlaps one or more ones already being served.
306 static const OVERLAPPING = 2; 308 static const OVERLAPPING = 2;
307 } 309 }
OLDNEW
« no previous file with comments | « lib/src/barback/transformer_isolate.dart ('k') | lib/src/command.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698