Click or drag to resize

PlayerToSpectatorRequest Class

Turns the current user from player to spectator in a Game Room.
Inheritance Hierarchy
SystemObject
  BaseRequest
    Sfs2X.RequestsPlayerToSpectatorRequest

Namespace:  Sfs2X.Requests
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public class PlayerToSpectatorRequest : BaseRequest
Constructors
  NameDescription
Public methodPlayerToSpectatorRequest
See PlayerToSpectatorRequest(Room) constructor.
Public methodPlayerToSpectatorRequest(Room)
Creates a new PlayerToSpectatorRequest instance.
Top
Remarks
If the operation is successful, all the users in the target Room are notified with the PLAYER_TO_SPECTATOR event. The operation could fail if no spectator slots are available in the Game Room at the time of the request; in this case the PLAYER_TO_SPECTATOR_ERROR event is dispatched to the requester's client.
Examples
The following example turns the current user from player to spectator in the last joined Game Room:
void SomeMethod() {
    sfs.AddEventListener(SFSEvent.PLAYER_TO_SPECTATOR, OnPlayerToSpectatorSwitch);
    sfs.AddEventListener(SFSEvent.PLAYER_TO_SPECTATOR_ERROR, OnPlayerToSpectatorSwitchError);

    // Switch player to spectator
    sfs.Send( new PlayerToSpectatorRequest() );
}

void OnPlayerToSpectatorSwitch(BaseEvent evt) {
    User user = (User)evt.Params["user"];
    Console.WriteLine("Player " + user.Name + " is now a spectator");                           // .Net / Unity
    System.Diagnostics.Debug.WriteLine("Player " + user.Name + " is now a spectator");          // UWP
}

void OnPlayerToSpectatorSwitchError(BaseEvent evt) {
    Console.WriteLine("Unable to become a spectator due to the following error: " + (string)evt.Params["errorMessage"]);                        // .Net / Unity
    System.Diagnostics.Debug.WriteLine("Unable to become a spectator due to the following error: " + (string)evt.Params["errorMessage"]);       // UWP
}
See Also