-
Notifications
You must be signed in to change notification settings - Fork 5
Chat Client
The chat client interfaces with Beam's chat servers, allowing your app to send and receive chat messages.
To connect to the chat server, first initialize ChatClient
, passing a delegate of ChatClientDelegate
. If there is a user authenticated with BeamSession
, then they will automatically be authenticated with the chat server. Otherwise, a generic connection to the server will be made, in which the user can't participate in chat.
let chatClient = ChatClient(delegate: self)
chatClient.joinChannel(channel.id)
The delegate methods will be passing your app data about the connection you have with the chat server in the meantime, which you should listen to and use to update your app accordingly.
The chatDidConnect:
delegate method will be fired when a connection is made to the chat server. At this point in time, packets and messages are able to be sent through the client.
func chatDidConnect() {
print("connected to chat successfully")
}
The chatReceivedPacket:packet:
delegate method will be fired when a packet has been received from the chat server. This packet has already been parsed and interpreted by the API client, allowing you to use packet data effortlessly.
func chatReceivedPacket(packet: Packet) {
if let packet = packet as? MessagePacket {
print("received a chat message")
}
}
The updateWithViewers:viewers:
delegate method is fired when a new viewer count has been received, regardless of whether it has changed from the last time this method was fired.
func updateWithViewers(viewers: Int) {
print("\(viewers) are watching the stream")
}