platform/packages/websocket/test/controller/common.dart
thomashii@dukefirehawk.com 41188b3df8 Migrated websocket
2021-04-26 08:47:32 +08:00

35 lines
932 B
Dart

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});
factory Game.fromJson(Map data) => Game(
playerOne: data['playerOne'].toString(),
playerTwo: data['playerTwo'].toString());
Map<String, dynamic> toJson() {
return {'playerOne': playerOne, 'playerTwo': playerTwo};
}
@override
bool operator ==(other) =>
other is Game &&
other.playerOne == playerOne &&
other.playerTwo == playerTwo;
}
const Game johnVsBob = Game(playerOne: 'John', playerTwo: 'Bob');
@Expose('/game')
class GameController extends WebSocketController {
GameController(AngelWebSocket ws) : super(ws);
@ExposeWs('search')
dynamic search(WebSocketContext socket) async {
print('User is searching for a game...');
socket.send('searched', johnVsBob);
}
}