September 2018
Intermediate to advanced
398 pages
9h 43m
English
Going back to the Websockets class, and, more specifically, to the cartEventWS method, we can finish the implementation, as follows:
def cartEventWS = WebSocket.accept[String, String] { implicit request =>
ActorFlow.actorRef{out =>
Logger.info(s"Got a new websocket connection from ${request.host}")
managerActor ! BrowserManagerActor.AddBrowser(out)
BrowserActor.props(managerActor)
}
}
After logging, we send the AddBrowser message to the manager by using the ! command (pronounced bang); this is syntactic sugar, and we could also use the .tell() method.
ActorFlow.actorRef needs ActorRef to handle the upstream of the web socket; for that purpose, we create BrowserActor by using the props function of the BrowserActor companion ...
Read now
Unlock full access