This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit val gameEventFormat = Json.format[GameEvent] | |
implicit val gameEventFrameFormatter = FrameFormatter.jsonFrame[GameEvent] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class GameEvent(gameId: String, eventType: String, data: JsValue) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WebsocketEventPublisher(gameId: String, out: ActorRef) | |
extends Actor | |
with ActorLogging | |
with ImplicitFlowMaterializer { | |
import context.dispatcher | |
override def preStart() = { | |
import Global.connection | |
import Config.Events._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.service('commandService', function($http) { | |
return { | |
createGame: function(success, error) { | |
$http.post('/game') | |
.success(success) | |
.error(error); | |
}, | |
startGame: function(gameId, playersCount, error) { | |
$http.post('/game/' + gameId + '/start?playersCount=' + playersCount) | |
.error(error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rootScope.$on('events.TurnCountdownUpdated', function(event, data) { | |
$rootScope.game.turn.secondsLeft = data.secondsLeft; | |
$rootScope.$apply(); | |
}); | |
$rootScope.$on('events.TurnChanged', function(event, data) { | |
$rootScope.game.turn = data.turn; | |
$rootScope.$apply(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.controller('GameController', function($scope, $rootScope, commandService) { | |
$scope.selectedPlayer = $rootScope.game.players[0]; | |
$scope.winners = []; | |
$scope.gameFinished = false; | |
$scope.playAgain = function() { | |
$rootScope.gameId = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SubscriberActor(statsActor: ActorRef) extends ActorSubscriber { | |
override def receive = { | |
case OnNext(message: Message) => | |
for { | |
eventType <- message.headers.get("type") if eventType == "DiceRolled" | |
content <- parseOpt(message.body.decodeString("UTF-8")) | |
JInt(rolledNumber) <- content \ "rolledNumber" | |
} statsActor ! StatsActor.IncRollsCount(rolledNumber.toInt) | |
case OnComplete => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Stats(rollsCounts: Map[Int, Int]) { | |
def incRollsCount(rolledNumber: Int) = { | |
val currentCount = rollsCounts.getOrElse(rolledNumber, 0) | |
copy(rollsCounts = rollsCounts + (rolledNumber -> (currentCount + 1))) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class IncRollsCount(rolledNumber: Int) extends Command | |
case class RollsCountIncreased(rolledNumber: Int) extends Event | |
case object GetState extends Command | |
class StatsActor extends PersistentActor { | |
override val persistenceId = "rolls_stats" | |
var state: Stats = Stats(Map.empty) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit val connection = Connection() | |
val queue = Queue(queueName, durable = false, autoDelete = true) | |
val bindArgs = Map("x-match" -> "all", "type" -> "DiceRolled") | |
val resultFuture = for { | |
_ <- connection.queueDeclare(queue) | |
_ <- connection.queueBind(queueName, exchangeName, "", bindArgs) | |
} yield () | |
resultFuture onComplete { |