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
|
|
|
|
2018-07-10 16:54:55 +00:00
|
|
|
factory Game.fromJson(Map data) => new Game(
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-07-10 16:54:55 +00:00
|
|
|
const Game johnVsBob = const 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')
|
|
|
|
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
|
|
|
}
|