platform/lib/client.dart

30 lines
657 B
Dart
Raw Normal View History

2016-04-29 01:19:09 +00:00
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()));
}
}