here's the code:
smartfox.onJoinRoom = function(roomObj:Object){
trace("roomObj="+roomObj);
}
here's the output window:
[Sending]: <msg t='sys'><body action='autoJoin' r='-1'></body></msg>
[Sending]: <msg t='sys'><body action='getRmList' r='-1'></body></msg>
[Received]: <msg t="sys"><body action="joinOK" r="2"><pid id="0" /><vars /><userList r="2"><user id="20" name="test" mod="0"><vars /></user></userList></body></msg>
roomObj=undefined
[Received]: <msg t="sys"><body action="rmList" r="0"><rmList><rm id="2" priv="0" temp="0" game="0" ucnt="1" maxu="50" maxs="0"><n>the main site</n></rm><rm id="3" priv="0" temp="0" game="0" ucnt="0" maxu="50" maxs="0"><n>library</n></rm></rmList></body></msg>
room object undefined w/ onJoinRoom event
Here's what I have figured out after further investigation. There needs to be a slight delay between logging in and joining a room.
I was having autoJoin() triggered by the onLogin() event. This causes the onJoinRoom event to not pass a room object.
To solve this, I used setInterval to delay calling the autojoin by 10 ms, this in turn allows the room object to be passed to the onJoinRoom event.
I was having autoJoin() triggered by the onLogin() event. This causes the onJoinRoom event to not pass a room object.
To solve this, I used setInterval to delay calling the autojoin by 10 ms, this in turn allows the room object to be passed to the onJoinRoom event.
Here's what I have figured out after further investigation. There needs to be a slight delay between logging in and joining a room.
It's not really a delay it's more about the order in which requests are sent and the fact that a frame-change is performed in the client code.
In other words it's not a bug in the server or client API, it is related with the specific code of the examples.
All the examples coming with the latest SmartFoxServer PRO (1.2.5) work properly and eliminate the issue. In case you don't have it, I suggest you to download it and check the source code of the "SimpleChat" which is the simplest example to look for.
This problem was already descripted in another post some time ago talking about an issue with the Linux Flash Player. The player for Linux is way more slow than the other editions and it magnified the problem, which helped us finding it and solving it.
You can read the whole story here >> viewtopic.php?t=74
Let me know if you have any other questions
The examples worked fine, my problem occured with a chat I was developing that did not have a frame change.
Here is the order of events:
connect()
onConnect() -> Login()
onLogin() -> autoJoin()
onJoinRoom() -> Room object is not passed
The Fix
function delay_func(){
clearInterval(delay_func_int)
autoJoin()
}
connect()
onConnect() -> Login()
onLogin() -> delay_func_int=setInterval (delay_func,10)
onJoinRoom() ->Room object passed.
Joe
Here is the order of events:
connect()
onConnect() -> Login()
onLogin() -> autoJoin()
onJoinRoom() -> Room object is not passed
The Fix
function delay_func(){
clearInterval(delay_func_int)
autoJoin()
}
connect()
onConnect() -> Login()
onLogin() -> delay_func_int=setInterval (delay_func,10)
onJoinRoom() ->Room object passed.
Joe
hi Joe,
I am not sure if understand, maybe you've some problems in your code. I think a few lines of code would be the best explanation, here
Here's a code template for connecting and joining a room.
Template:
Just create a brand new fmx2004 document and copy/paste the above code in the first frame.
It works perfectly for me (using SFS PRO 1.2.5), so it should for you too
I am not sure if understand, maybe you've some problems in your code. I think a few lines of code would be the best explanation, here
Here's a code template for connecting and joining a room.
Template:
Code: Select all
import it.gotoandplay.smartfoxserver.*
stop()
// Basic Config
var ip:String = "127.0.0.1"
var port:Number = 9339
var zone:String = "dbZone"
// Server setup
var smartfox:SmartFoxClient = new SmartFoxClient()
smartfox.debug = true
// Handle connection
smartfox.onConnection = function(ok)
{
if (ok)
{
trace("connected")
login()
}
else
trace("Ouch! Can't connect")
}
// Send an empty login
function login()
{
smartfox.login(zone, "", null)
}
// Handle login
smartfox.onLogin = function(resObj:Object)
{
if (resObj.success)
{
// Login OK
trace("Logged as: " + resObj.name)
}
else
{
trace("Could not login")
}
}
// Handle room-list
smartfox.onRoomListUpdate = function(roomObj:Object)
{
this.autoJoin()
}
// Handle Join
smartfox.onJoinRoom = function(roomObj:Object)
{
trace("Joined Room: " + roomObj.getName() + "(" + roomObj.getId() + ")")
}
// Start the connection
smartfox.connect(ip, port)
Just create a brand new fmx2004 document and copy/paste the above code in the first frame.
It works perfectly for me (using SFS PRO 1.2.5), so it should for you too
Your code works fine. The difference was that my code was having autoJoin() triggered by the onLogin event not the onRoomListUpdate event. In this case the room object is not passed.
I would just make it clear in the documentation that you have to wait for onRoomListUpdate event to trigger autoJoin() and that it cannot be called directly from the onLogin event.
Here is an example of the code that does not pass the room object:
import it.gotoandplay.smartfoxserver.*
stop()
// Basic Config
var ip:String = "127.0.0.1"
var port:Number = 9339
var zone:String = "dbZone"
// Server setup
var smartfox:SmartFoxClient = new SmartFoxClient()
smartfox.debug = true
// Handle connection
smartfox.onConnection = function(ok)
{
if (ok)
{
trace("connected")
login()
}
else
trace("Ouch! Can't connect")
}
// Send an empty login
function login()
{
smartfox.login(zone, "", null)
}
// Handle login
smartfox.onLogin = function(resObj:Object)
{
if (resObj.success)
{
// Login OK
trace("Logged as: " + resObj.name)
this.autoJoin()
}
else
{
trace("Could not login")
}
}
//I was not using this because I did not need a room list.
// Handle room-list
//smartfox.onRoomListUpdate = function(roomObj:Object)
//{
// this.autoJoin()
//}
// Handle Join
smartfox.onJoinRoom = function(roomObj:Object)
{
trace("Joined Room: " + roomObj.getName() + "(" + roomObj.getId() + ")")
}
// Start the connection
smartfox.connect(ip, port)
I would just make it clear in the documentation that you have to wait for onRoomListUpdate event to trigger autoJoin() and that it cannot be called directly from the onLogin event.
Here is an example of the code that does not pass the room object:
import it.gotoandplay.smartfoxserver.*
stop()
// Basic Config
var ip:String = "127.0.0.1"
var port:Number = 9339
var zone:String = "dbZone"
// Server setup
var smartfox:SmartFoxClient = new SmartFoxClient()
smartfox.debug = true
// Handle connection
smartfox.onConnection = function(ok)
{
if (ok)
{
trace("connected")
login()
}
else
trace("Ouch! Can't connect")
}
// Send an empty login
function login()
{
smartfox.login(zone, "", null)
}
// Handle login
smartfox.onLogin = function(resObj:Object)
{
if (resObj.success)
{
// Login OK
trace("Logged as: " + resObj.name)
this.autoJoin()
}
else
{
trace("Could not login")
}
}
//I was not using this because I did not need a room list.
// Handle room-list
//smartfox.onRoomListUpdate = function(roomObj:Object)
//{
// this.autoJoin()
//}
// Handle Join
smartfox.onJoinRoom = function(roomObj:Object)
{
trace("Joined Room: " + roomObj.getName() + "(" + roomObj.getId() + ")")
}
// Start the connection
smartfox.connect(ip, port)
I would just make it clear in the documentation that you have to wait for onRoomListUpdate event to trigger autoJoin() and that it cannot be called directly from the onLogin event.
Yeah! I will definately add a new article with the next release that shows the code template for a basic SmartFoxServer application.
Return to “SmartFoxServer 1.x Discussions and Help”
Who is online
Users browsing this forum: Baidu [Spider] and 47 guests