2017-06-30 23:09:03 +00:00
|
|
|
/// Flutter-compatible WebSocket client library for the Angel framework.
|
|
|
|
library angel_websocket.flutter;
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:http/http.dart' as http;
|
2018-11-08 21:53:52 +00:00
|
|
|
import 'package:http/io_client.dart' as http;
|
2017-06-30 23:09:03 +00:00
|
|
|
import 'package:web_socket_channel/web_socket_channel.dart';
|
|
|
|
import 'package:web_socket_channel/io.dart';
|
|
|
|
import 'base_websocket_client.dart';
|
|
|
|
export 'package:angel_client/angel_client.dart';
|
|
|
|
export 'angel_websocket.dart';
|
|
|
|
|
2018-07-10 16:54:55 +00:00
|
|
|
// final RegExp _straySlashes = new RegExp(r"(^/)|(/+$)");
|
2017-06-30 23:09:03 +00:00
|
|
|
|
|
|
|
/// Queries an Angel server via WebSockets.
|
|
|
|
class WebSockets extends BaseWebSocketClient {
|
|
|
|
final List<WebSocketsService> _services = [];
|
|
|
|
|
2018-07-10 16:54:55 +00:00
|
|
|
WebSockets(String path) : super(new http.IOClient(), path);
|
2017-06-30 23:09:03 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Stream<String> authenticateViaPopup(String url, {String eventName: 'token'}) {
|
|
|
|
throw new UnimplementedError(
|
|
|
|
'Opening popup windows is not supported in the `dart:io` client.');
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future close() {
|
|
|
|
for (var service in _services) {
|
|
|
|
service.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<WebSocketChannel> getConnectedWebSocket() async {
|
|
|
|
var socket = await WebSocket.connect(basePath,
|
|
|
|
headers: authToken?.isNotEmpty == true
|
|
|
|
? {'Authorization': 'Bearer $authToken'}
|
|
|
|
: {});
|
|
|
|
return new IOWebSocketChannel(socket);
|
|
|
|
}
|
2018-10-02 15:32:06 +00:00
|
|
|
}
|