platform/test/controller/common.dart

29 lines
758 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 {
final String playerOne, playerTwo;
const Game({this.playerOne, this.playerTwo});
2016-12-24 01:45:52 +00:00
factory Game.fromJson(Map data) =>
new Game(playerOne: data['playerOne'], playerTwo: data['playerTwo']);
@override
bool operator ==(other) =>
other is Game &&
other.playerOne == playerOne &&
other.playerTwo == playerTwo;
2016-12-23 20:57:46 +00:00
}
2016-12-24 01:45:52 +00:00
const Game JOHN_VS_BOB = const Game(playerOne: 'John', playerTwo: 'Bob');
2016-12-23 20:57:46 +00:00
@Expose('/game')
class GameController extends WebSocketController {
@ExposeWs('search')
search(WebSocketContext socket) async {
2016-12-24 01:45:52 +00:00
print('User is searching for a game...');
socket.send('searched', JOHN_VS_BOB);
2016-12-23 20:57:46 +00:00
}
2016-12-24 01:45:52 +00:00
}