/// WebSocket plugin for Angel. library angel_websocket; /// A notification from the server that something has occurred. class WebSocketEvent { String eventName; Data data; WebSocketEvent({this.eventName, this.data}); factory WebSocketEvent.fromJson(Map data) => WebSocketEvent( eventName: data['eventName'].toString(), data: data['data'] as Data); WebSocketEvent cast() { if (T == Data) { return this as WebSocketEvent; } else { return WebSocketEvent(eventName: eventName, data: data as T); } } Map toJson() { return {'eventName': eventName, 'data': data}; } } /// A command sent to the server, usually corresponding to a service method. class WebSocketAction { String id; String eventName; var data; Map params; WebSocketAction({this.id, this.eventName, this.data, this.params}); factory WebSocketAction.fromJson(Map data) => WebSocketAction( id: data['id'].toString(), eventName: data['eventName'].toString(), data: data['data'], params: data['params'] as Map); Map toJson() { return {'id': id, 'eventName': eventName, 'data': data, 'params': params}; } }