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

Unified Diff: dart/samples/dartiverse_search/web/client.dart

Issue 60293003: Version 0.8.10.5 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: dart/samples/dartiverse_search/web/client.dart
===================================================================
--- dart/samples/dartiverse_search/web/client.dart (revision 29908)
+++ dart/samples/dartiverse_search/web/client.dart (working copy)
@@ -2,12 +2,13 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+import 'dart:async';
+import 'dart:convert';
import 'dart:html';
-import 'dart:convert';
class Client {
- static const Duration CONNECT_DELAY = const Duration(milliseconds: 500);
+ static const Duration RECONNECT_DELAY = const Duration(milliseconds: 500);
WebSocket webSocket;
final DivElement log = new DivElement();
@@ -16,25 +17,14 @@
DivElement resultsElement = querySelector('#results');
Client() {
- onDisconnected();
searchElement.onChange.listen((e) {
search(searchElement.value);
searchElement.value = '';
});
+ connect();
}
- void onConnected() {
- setStatus('');
- searchElement.disabled = false;
- searchElement.focus();
- webSocket.onMessage.listen((e) {
- onMessage(e.data);
- });
- }
-
- void onDisconnected() {
- searchElement.disabled = true;
- setStatus('Disconnected');
+ void connect() {
webSocket = new WebSocket('ws://${Uri.base.host}:${Uri.base.port}/ws');
webSocket.onOpen.first.then((_) {
onConnected();
@@ -44,11 +34,27 @@
});
});
webSocket.onError.first.then((_) {
- print("Failed to connect to ${webSocket.url}");
+ print("Failed to connect to ${webSocket.url}. "
+ "Please run bin/server.dart and try again.");
onDisconnected();
});
}
+ void onConnected() {
+ setStatus('');
+ searchElement.disabled = false;
+ searchElement.focus();
+ webSocket.onMessage.listen((e) {
+ onMessage(e.data);
+ });
+ }
+
+ void onDisconnected() {
+ searchElement.disabled = true;
+ setStatus('Disconnected - start \'bin/server.dart\' to continue');
+ new Timer(RECONNECT_DELAY, connect);
+ }
+
void setStatus(String status) {
statusElement.innerHtml = status;
}

Powered by Google App Engine
This is Rietveld 408576698