Rooms can be created from code at any time (after the login) on both client and server-side. This is a quick example in ActionScript 3 (for simplicity the required listeners are added just before creating the Room, but this should be made during the application initialization):
smartFox.addEventListener(SFSEvent.ROOM_ADD, onRoomAdded)
smartFox.addEventListener(SFSEvent.ROOM_CREATION_ERROR, onRoomCreationError)
// Create a new Chat Room
var settings:RoomSettings = new RoomSettings("Piggy's Chat Room")
settings.maxUsers = 40
settings.groupId = "ChatGroup"
smartFox.send(new CreateRoomRequest(settings))
These are the event listeners:
function onRoomAdded(evt:SFSEvent):void
{
trace("A new Room was added: " + evt.params.room )
}
function onRoomCreationError(evt:SFSEvent):void
{
trace("attempting to create the Room: " + evt.params.errorMessage)
}
The RoomSetting class allows to specify a large number of parametersto fine tune all major and minor aspects of a Room. If the creation is successful the SFSEvent.ROOM_ADD event will be sent back to the client, otherwise an error message is notified in the SFSEvent.ROOM_CREATION_ERROR event.
0 comments:
Post a Comment