Package sfs2x.client.requests
Class ObjectMessageRequest
- java.lang.Object
-
- sfs2x.client.requests.BaseRequest
-
- sfs2x.client.requests.GenericMessageRequest
-
- sfs2x.client.requests.ObjectMessageRequest
-
- All Implemented Interfaces:
sfs2x.client.requests.IRequest
public class ObjectMessageRequest extends sfs2x.client.requests.GenericMessageRequest
Sends an object containing custom data to all users in a Room, or a subset of them.The data object is delivered to the selected users (or all users excluding the sender) inside the target Room by means of the objectMessage event. It can be useful to send game data, like for example the target coordinates of the user's avatar in a virtual world.
Example
The following example sends the player's character movement coordinates and handles the respective event (note: the myCharacter instance is supposed to be the user sprite on the stage, while the getUserCharacter method retrieves the sprite of other users' characters):private void someMethod() { sfs.addEventListener(SFSEvent.OBJECT_MESSAGE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { ISFSObject dataObj = (SFSObject)evt.getArguments().get("message"); User sender = evt.getArguments().get("sender"); UserCharacter character = getUserCharacter(sender.getId()); character.x = dataObj.getInt("x"); character.y = dataObj.getInt("y"); } }); // Send my movement to all players ISFSObject dataObj = new SFSObject(); dataObj.putInt("x", myCharacter.x); dataObj.putInt("y", myCharacter.y); sfs.send(new ObjectMessageRequest(dataObj)); }
- See Also:
SFSEvent.OBJECT_MESSAGE
-
-
Field Summary
-
Fields inherited from class sfs2x.client.requests.GenericMessageRequest
KEY_MESSAGE, KEY_MESSAGE_TYPE, KEY_RECIPIENT, KEY_RECIPIENT_MODE, KEY_ROOM_ID, KEY_SENDER_DATA, KEY_USER_ID, KEY_XTRA_PARAMS
-
Fields inherited from class sfs2x.client.requests.BaseRequest
AddBuddy, AdminMessage, AutoJoin, BanUser, BlockBuddy, CallExtension, ChangeRoomCapacity, ChangeRoomName, ChangeRoomPassword, ClusterInviteUsers, ClusterJoinOrCreate, CreateRoom, CreateSFSGame, FindRooms, FindUsers, GameServerConnectionRequired, GenericMessage, GetRoomList, GoOnline, Handshake, InitBuddyList, InvitationReply, InviteUser, JoinRoom, JoinRoomInvite, KEY_ERROR_CODE, KEY_ERROR_PARAMS, KickUser, LeaveRoom, Login, Logout, ManualDisconnection, ModeratorMessage, ObjectMessage, PingPong, PlayerToSpectator, PrivateMessage, PublicMessage, QuickJoinGame, QuickJoinOrCreateRoom, RemoveBuddy, SetBuddyVariables, SetRoomVariables, SetUserPosition, SetUserVariables, SpectatorToPlayer, SubscribeRoomGroup, UnsubscribeRoomGroup
-
-
Constructor Summary
Constructors Constructor Description ObjectMessageRequest(com.smartfoxserver.v2.entities.data.ISFSObject obj)
ObjectMessageRequest(com.smartfoxserver.v2.entities.data.ISFSObject obj, Room targetRoom)
ObjectMessageRequest(com.smartfoxserver.v2.entities.data.ISFSObject obj, Room targetRoom, java.util.List<User> recipients)
Creates a new ObjectMessageRequest instance.
-
Method Summary
-
Methods inherited from class sfs2x.client.requests.BaseRequest
getId, getMessage, getTargetController, isEncrypted, setEncrypted, setId, setTargetController
-
-
-
-
Constructor Detail
-
ObjectMessageRequest
public ObjectMessageRequest(com.smartfoxserver.v2.entities.data.ISFSObject obj, Room targetRoom, java.util.List<User> recipients)
Creates a new ObjectMessageRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.- Parameters:
obj
- An instance of SFSObject containing custom parameters to be sent to the message recipients.targetRoom
- The Room object corresponding to the Room where the message should be dispatched; ifnull
, the last Room joined by the user is used.recipients
- A list of User objects corresponding to the message recipients; ifnull
, the message is sent to all users in the target Room (except the sender himself).- See Also:
SmartFox.send(sfs2x.client.requests.IRequest)
,SFSObject
,User
-
ObjectMessageRequest
public ObjectMessageRequest(com.smartfoxserver.v2.entities.data.ISFSObject obj, Room targetRoom)
-
ObjectMessageRequest
public ObjectMessageRequest(com.smartfoxserver.v2.entities.data.ISFSObject obj)
-
-