Keep your users communicating while they are online using Photon Chat. Photon Chat applications need a distinct application and AppId to connect to.
To get updates and messages, your application has to implement several methods that are used as callback.
In C#, they are defined in the
In our demos, we instantiate and use the
ChatClient class to implement the
ChatClient is instantiated you can connect.
Connect() is passed the version, an arbitrary string, and the username, a unique name in best case.
With Photon Chat you use channels to group users or topics. Anyone who subscribes to a channel gets all messages published within. New channels are created upon first subscription.
The subscribe method is passed an array of strings for the channels to be subscribed.
ChatClient.Service() to keep the connection alive and to get incoming messages.
That way you know when to expect new messages.
Prior publishing subscribe the channel you want to publish messages in.
Publish messages to all subscribers of a channel with
Other than plain strings Photon Chat allows you to define complex messages, e.g. for invitations.
Send a private message to any user with
OnGetMessages() on your
IChatClientListener interface to handle incoming public messages.
All public messages are automatically cached in
Dictionary<string, ChatChannel> PublicChannels, so you don't have to keep track of them.
The channel name is the key for
In very long or active conversations, you might want to trim each channels history.
To receive and parse private messages you implement
All private messages are automatically cached in
ChatClient.PrivateChannels, so you don't have to keep track of them.
Again, a channel name is applied as key for
Get a (remote) user's channel name with
Set the online status for your players with
Pass it the actual status and a, optional, status message.
Define your own statuses using integers.
Just send an array of usernames to Photon to get their future status updates.
You'll receive an initial update with the current status per friend to
OnStatusUpdate() on on your