Skip to content

Instantly share code, notes, and snippets.

@stevef
Created October 16, 2013 16:19
Show Gist options
  • Save stevef/7010599 to your computer and use it in GitHub Desktop.
Save stevef/7010599 to your computer and use it in GitHub Desktop.
class ScoresStream extends Actor with akka.actor.ActorLogging {
//log.info("We've got yet another pigdog on our hands")
var members = Set.empty[String]
val (scoresEnumerator, scoresChannel) = Concurrent.broadcast[JsValue]
case class Message(kind: String, user: String, message: String)
implicit val messageReads = Json.reads[Message]
implicit val messageWrites = Json.writes[Message]
val sub = new Sub(scoresChannel)
val pub = new Pub
def receive = {
case Join(teamId) => {
sub.sub("tsn-test-channel")
sender ! Connected(scoresEnumerator)
}
case Talk(username, text) => {
log.info("getting talk for username: " + username + "and text: " + text)
notifyAll("talk", username, text)
}
case _ => println("wuts going on here?")
}
def notifyAll(kind: String, user: String, text: String) {
val msg = Message(kind, user, text)
//chatChannel.push(msg)
//Pub to Redis
pub.sendChatMsg(Json.stringify(messageWrites.writes(msg)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment