I am working on a Chat application using WebSockets(in Play 2.3 with scala). The message has to be broadcasted to all users or specific set of users based on the incoming message. One user can participate in more than one group chat and able to chat with individuals simultaneously.
The Concurrent.broadcast[JsValue] returns the tuple(enumerator, channel). I dont know how to apply filter to this channel, so only specific group of clients will get the message.
We can apply filters on enumerator like (enumerator &> Enumeratee.filter[JsValue] {...} ). but we can not push messages via this enumerator.
I don't want to parse the message on the client side. My code looks like this,
val (public_enumerator, public_channel) = Concurrent.broadcast[JsValue]
def chat = WebSocket.using[JsValue] { request =>
val in = Iteratee.foreach[JsValue]{ msg =>
public_channel.push(msg)
}.map { _ =>
// Quit connection
}
(in ,public_enumerator)
}
Most of the examples I found online are using the deprecated methods, some of them removed in Play 2.3 (like Enumerators.imperative). I dont know how Concurrent.unicast works.
I would like to know if there is another way of doing the same using Actors. I also like to know, that, this design will handle the higher load( more than 1000 users). Thank you.