2016-12-23 20:57:46 +00:00
|
|
|
import 'dart:io';
|
2021-05-15 07:19:35 +00:00
|
|
|
import 'package:angel3_container/mirrors.dart';
|
|
|
|
import 'package:angel3_framework/angel3_framework.dart' as srv;
|
|
|
|
import 'package:angel3_framework/http.dart' as srv;
|
|
|
|
import 'package:angel3_websocket/io.dart' as ws;
|
|
|
|
import 'package:angel3_websocket/server.dart' as srv;
|
2017-09-24 04:37:58 +00:00
|
|
|
import 'package:logging/logging.dart';
|
2016-12-23 20:57:46 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
import 'common.dart';
|
|
|
|
|
2021-02-21 02:47:23 +00:00
|
|
|
void main() {
|
2021-09-29 07:40:27 +00:00
|
|
|
srv.Angel app;
|
2021-04-26 00:47:32 +00:00
|
|
|
late srv.AngelHttp http;
|
2024-06-03 03:28:23 +00:00
|
|
|
late ws.WebSockets client;
|
2016-12-23 20:57:46 +00:00
|
|
|
srv.AngelWebSocket websockets;
|
2021-04-26 00:47:32 +00:00
|
|
|
HttpServer? server;
|
|
|
|
String? url;
|
2016-12-23 20:57:46 +00:00
|
|
|
|
|
|
|
setUp(() async {
|
2021-02-21 02:47:23 +00:00
|
|
|
app = srv.Angel(reflector: const MirrorsReflector());
|
2021-09-29 07:40:27 +00:00
|
|
|
http = srv.AngelHttp(app, useZone: false);
|
2016-12-23 20:57:46 +00:00
|
|
|
|
2021-02-21 02:47:23 +00:00
|
|
|
websockets = srv.AngelWebSocket(app)
|
2016-12-23 20:57:46 +00:00
|
|
|
..onData.listen((data) {
|
|
|
|
print('Received by server: $data');
|
|
|
|
});
|
|
|
|
|
2021-09-29 07:40:27 +00:00
|
|
|
await app.configure(websockets.configureServer);
|
|
|
|
app.all('/ws', websockets.handleRequest);
|
|
|
|
await app.configure(GameController(websockets).configureServer);
|
|
|
|
app.logger = Logger('angel_auth')..onRecord.listen(print);
|
2016-12-23 20:57:46 +00:00
|
|
|
|
2018-07-10 16:54:55 +00:00
|
|
|
server = await http.startServer();
|
2021-04-26 00:47:32 +00:00
|
|
|
url = 'ws://${server!.address.address}:${server!.port}/ws';
|
2016-12-23 20:57:46 +00:00
|
|
|
|
2021-02-21 02:47:23 +00:00
|
|
|
client = ws.WebSockets(url);
|
2024-06-03 03:28:23 +00:00
|
|
|
await client.connect(timeout: Duration(seconds: 3));
|
2016-12-23 20:57:46 +00:00
|
|
|
|
2018-08-28 14:17:14 +00:00
|
|
|
print('Connected');
|
|
|
|
|
2016-12-23 20:57:46 +00:00
|
|
|
client
|
2024-06-03 03:28:23 +00:00
|
|
|
..onData.listen((data) {
|
2016-12-23 20:57:46 +00:00
|
|
|
print('Received by client: $data');
|
|
|
|
})
|
|
|
|
..onError.listen((error) {
|
|
|
|
// Auto-fail tests on errors ;)
|
|
|
|
stderr.writeln(error);
|
|
|
|
error.errors.forEach(stderr.writeln);
|
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
2024-06-03 03:28:23 +00:00
|
|
|
await client.close();
|
2018-07-10 16:54:55 +00:00
|
|
|
await http.close();
|
2021-09-29 07:40:27 +00:00
|
|
|
//app = null;
|
2016-12-23 20:57:46 +00:00
|
|
|
server = null;
|
|
|
|
url = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
group('controller.io', () {
|
|
|
|
test('search', () async {
|
2024-06-03 03:28:23 +00:00
|
|
|
client.sendAction(ws.WebSocketAction(eventName: 'search'));
|
|
|
|
var search = await client.on['searched'].first;
|
2016-12-24 01:45:52 +00:00
|
|
|
print('Searched: ${search.data}');
|
2021-02-21 02:47:23 +00:00
|
|
|
expect(Game.fromJson(search.data as Map), equals(johnVsBob));
|
2016-12-23 20:57:46 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|