platform/lib/client.dart
2016-04-28 21:19:09 -04:00

30 lines
No EOL
657 B
Dart

library angel_websocket.client;
import 'dart:convert' show JSON;
import 'dart:html';
import 'shared.dart';
class Angel {
String wsEndPoint;
WebSocket _socket;
Angel(String this.wsEndPoint) {
_socket = new WebSocket(wsEndPoint);
}
AngelService service(String path) {
return new AngelService._base(_socket, path.trim().replaceAll(new RegExp(r'(^\/+)|(\/+$)'), ''));
}
}
class AngelService {
WebSocket _socket;
String path;
AngelService._base(WebSocket this._socket, path) {}
index([Map params]) {
AngelMessage request = new AngelMessage(path, 'index', body: params);
_socket.send(JSON.encode(request.toMap()));
}
}