Sends a public chat message.

Namespace: Sfs2X.Requests
Assembly: SmartFox2X (in SmartFox2X.dll) Version: 1.7.0.0 (1.7.0)

Syntax

C#
public class PublicMessageRequest : GenericMessageRequest

Remarks

A public message is dispatched to all the users in the specified Room, including the message sender (this allows showing messages in the correct order in the application interface); the corresponding event is the PUBLIC_MESSAGE event. It is also possible to send an optional object together with the message: it can contain custom parameters useful to transmit, for example, additional informations related to the message, like the text font or color, or other formatting details.

In case the target Room is not specified, the message is sent in the last Room joined by the sender.

NOTE: the PUBLIC_MESSAGE event is dispatched if the Room is configured to allow public messaging only (see the RoomSettings.Permissions parameter).

Examples

The following example sends a public message and handles the respective event:
 Copy imageCopy
void SomeMethod() {
    sfs.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
    // Send a public message
    sfs.Send( new PublicMessageRequest("Hello everyone!") );
}
void OnPublicMessage(BaseEvent evt) {
    // As messages are forwarded to the sender too, I have to check if I am the sender
    User sender = (User)evt.Params["sender"];
    if (sender == sfs.MySelf)
    {
        Console.WriteLine("I said " + (string)evt.Params["message"]);                           // .Net / Unity
        System.Diagnostics.Debug.WriteLine("I said " + (string)evt.Params["message"]);          // Windows Universal
}
    else
    {
        Console.WriteLine("User " + sender.Name + " said: " + (string)evt.Params["message"]);                           // .Net / Unity
        System.Diagnostics.Debug.WriteLine("User " + sender.Name + " said: " + (string)evt.Params["message"]);          // Windows Universal
    }
}

Inheritance Hierarchy

System..::..Object
  BaseRequest
    GenericMessageRequest
      Sfs2X.Requests..::..PublicMessageRequest

See Also