Click or drag to resize

PublicMessageRequest Class

Sends a public chat message.
Inheritance Hierarchy
SystemObject
  BaseRequest
    GenericMessageRequest
      Sfs2X.RequestsPublicMessageRequest

Namespace:  Sfs2X.Requests
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public class PublicMessageRequest : GenericMessageRequest
Constructors
  NameDescription
Public methodPublicMessageRequest(String)
See PublicMessageRequest(string, ISFSObject, Room) constructor.
Public methodPublicMessageRequest(String, ISFSObject)
See PublicMessageRequest(string, ISFSObject, Room) constructor.
Public methodPublicMessageRequest(String, ISFSObject, Room)
Creates a new PublicMessageRequest instance.
Top
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:
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"]);          // UWP
    }
    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"]);          // UWP
    }
}
See Also