Now we will need to define our protocol. For this functionality, we will need three Actors. The Actors that we create will be as follows:
ChatRoom: This will have a reference for all users in the chat room
ChatUser: This will have one instance per user (active browser)
ChatBotAdmin: This simple Bot Admin will provide stats about the chat room
ChatUserActor
will need to join JoinChatRoom
object in order to start chatting. ChatUserActor
will also need to send messages to ChatMessage
class to the ChatRoomActor
that will broadcast messages to all users. The ChatBotAdmin
will get a report from GetStats
object from ChatRoomActor
.
Let's start coding this protocol. First, we will need to define the messages that will be exchanged between these Actors, as shown in the following piece of code:
package actors case class ChatMessage(name:String,text: String) case class Stats(users:Set[String]) object JoinChatRoom object Tick object...