Created
September 7, 2013 19:56
-
-
Save reyjexter/6478736 to your computer and use it in GitHub Desktop.
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
/** | |
* Wait for new notification socket | |
*/ | |
def waitForNotification = WebSocket.using[JsValue] { request => | |
val iteratee = Promise[Iteratee[JsValue, Unit]]() | |
val enumerator = Concurrent.unicast[JsValue](onStart = { clientChannel => | |
iteratee.success(Iteratee.foreach[JsValue] { | |
json => { | |
Logger.debug("== Enumerator called ==") | |
Logger.debug("json: " + json.toString) | |
val action = (json \ "action").as[String] | |
val data = (json \ "data").as[JsValue] | |
Logger.debug(">> action: " + action) | |
executeAction(action, data, clientChannel) | |
} | |
}.mapDone { | |
_ => { | |
Logger.debug("disconnected client channel") | |
NotificationActor.disconnect(clientChannel) | |
} | |
}) | |
}) | |
(Iteratee.flatten(iteratee.future), enumerator) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment