platform/packages/websocket/test/controller/common.dart

36 lines
932 B
Dart
Raw Normal View History

2016-12-23 20:57:46 +00:00
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_websocket/server.dart';
class Game {
2021-04-26 00:47:32 +00:00
final String? playerOne, playerTwo;
2016-12-23 20:57:46 +00:00
const Game({this.playerOne, this.playerTwo});
2016-12-24 01:45:52 +00:00
2021-02-21 02:47:23 +00:00
factory Game.fromJson(Map data) => Game(
2018-07-10 16:54:55 +00:00
playerOne: data['playerOne'].toString(),
playerTwo: data['playerTwo'].toString());
2016-12-24 01:45:52 +00:00
2018-11-04 02:17:33 +00:00
Map<String, dynamic> toJson() {
return {'playerOne': playerOne, 'playerTwo': playerTwo};
}
2016-12-24 01:45:52 +00:00
@override
bool operator ==(other) =>
other is Game &&
other.playerOne == playerOne &&
other.playerTwo == playerTwo;
2016-12-23 20:57:46 +00:00
}
2021-02-21 02:47:23 +00:00
const Game johnVsBob = Game(playerOne: 'John', playerTwo: 'Bob');
2016-12-24 01:45:52 +00:00
2016-12-23 20:57:46 +00:00
@Expose('/game')
class GameController extends WebSocketController {
2017-10-19 22:26:59 +00:00
GameController(AngelWebSocket ws) : super(ws);
2016-12-23 20:57:46 +00:00
@ExposeWs('search')
2021-04-10 15:12:43 +00:00
dynamic search(WebSocketContext socket) async {
2016-12-24 01:45:52 +00:00
print('User is searching for a game...');
2018-07-10 16:54:55 +00:00
socket.send('searched', johnVsBob);
2016-12-23 20:57:46 +00:00
}
2016-12-24 01:45:52 +00:00
}