Page 1 of 1

Can't create a room in JS Server API

Posted: 30 Nov 2017, 09:50
by trueicecold
Hey there,

I'm trying to do something very simple: open a room in the zone extension:

Server code:

Code: Select all

function init() {
	addRequestHandler("FindRoom", onFindRoom);
}

function onFindRoom(event, sender) {
	var cfg = new CreateRoomSettings();
 
	cfg.setName("232323s");
	cfg.setGame(true);
	cfg.setMaxUsers(10);
	cfg.setMaxSpectators(5);
	cfg.setDynamic(true);
	 
	var myNewRoom = getApi().createRoom(getParentZone(), cfg, null);
}
Client code:

Code: Select all

//Server.connection is the SmartFox instance
Server.connection.send(new SFS2X.ExtensionRequest("FindRoom", null));
I get an exception:

Code: Select all

java.lang.ClassCastException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.ClassCastException
Message: Cannot cast jdk.nashorn.internal.runtime.Undefined to com.smartfoxserver.v2.entities.Room
Description: Java Error invoking Javascript function: $$handleClientRequest
I thought this was pretty straight-forward, am I missing something?

Thanks!

Re: Can't create a room in JS Server API

Posted: 01 Dec 2017, 08:28
by Lapo
Hi,
I was able to reproduce the issue. It seems that one of the missing optional parameters is causing the exception, even though the Room is actually created. I don't know if you've noticed that.

In any case if you call createRoom(...) with the complete list of parameters it will go away.
For example:

Code: Select all

var room = getApi().createRoom(getParentZone(), cfg, null, false, null, true, false);
This should fix the problem you've encountered.
The parameters (in order) are:
zone -> the zone where to create the Room
cfg -> the room config
owner -> the creator of the Room (null == server)
autoJoin -> auto-join the owner upon creation
roomToLeave -> if auto-join is true you can pass another Room that the owner will leave upon auto-joining the new one
fireClientEvent-> notify the clients about the new Room
fireServerEvent-> notify other Extensions about the new Room

For more, check the documentation here:
http://docs2x.smartfoxserver.com/api-do ... FSApi.html

We'll investigate this further and release a patch as soon as possible.

Thanks