Packagecom.smartfoxserver.v2.requests
Classpublic class PublicMessageRequest
InheritancePublicMessageRequest Inheritance com.smartfoxserver.v2.requests.GenericMessageRequest

Sends a public chat message.

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 publicMessage 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 publicMessage event is dispatched if the Room is configured to allow public messaging only (see the RoomSettings.permissions parameter).

View the examples

See also

publicMessage event
RoomSettings.permissions


Public Methods
 MethodDefined By
  
PublicMessageRequest(message:String, params:ISFSObject = null, targetRoom:Room = null)
Creates a new PublicMessageRequest instance.
PublicMessageRequest
Constructor Detail
PublicMessageRequest()Constructor
public function PublicMessageRequest(message:String, params:ISFSObject = null, targetRoom:Room = null)

Creates a new PublicMessageRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

Parameters
message:String — The message to be sent to all the users in the target Room.
 
params:ISFSObject (default = null) — An instance of SFSObject containing additional custom parameters to be sent to the message recipients (for example the color of the text, etc).
 
targetRoom:Room (default = null) — The Room object corresponding to the Room where the message should be dispatched; if null, the last Room joined by the user is used.

See also

Examples
The following example sends a public message and handles the respective event:
     
     private function someMethod():void
     {
         sfs.addEventListener(SFSEvent.PUBLIC_MESSAGE, onPublicMessage);
         
         // Send a public message
         sfs.send(new PublicMessageRequest("Hello everyone!"));
     }
     
     private function onPublicMessage(evt:SFSEvent):void
     {
         // As messages are forwarded to the sender too,
         // I have to check if I am the sender
         
         var sender:User = evt.params.sender;
         
         if (sender == sfs.mySelf)
             trace("I said:", evt.params.message);
         else
             trace("User " + sender.name + " said:", evt.params.message);
     }