[SOLVED] Errors when using Orbiter/JS-RoomModule

All Union Platform questions, comments, feature requests, and bug reports.

Errors when using Orbiter/JS-RoomModule  

Postby jjMedina » Sat 07 Sep 2013 17:36

My Setup:
I'm using Orbiter (full, not micro) with a Javascript room module that is currently sending CHAT_MESSAGE's from a module GreeterBot.js (found in the Union example) and I'm coming across a problem that several people have seemed to run into. I've read through a few forum posts already:

http://www.unionplatform.com/?page_id=3151:
(OrbiterMicro tutorial)
http://www.unionplatform.com/forums/viewtopic.php?f=3&t=146&p=491&hilit=message+listener+error#p491
(Sent a raw UPC through the messageManager)
http://www.unionplatform.com/forums/viewtopic.php?f=3&t=194&p=634&hilit=client.sendMessage#p634
(I think this developer is using [orbiter.getClientManager().sendMessage("CHAT_MESSAGE", [ e.getClientID() ], null, "Private hi to you!");] as a solution)

These tutorials pretty much nailed it, but I'm still looking for a solution to evt.getClient().getClientID(); not validating the getClientID.
It seems that either the message listener in unionchat.js isn't written correctly, or the onRoomAddClient(evt) function in GreeterBot.js isn't written right (getting the right arguments, or performing the sendMessage() with the right arguments)

Also, the union admin puts out a curious warning, that the "ScriptWrapperModule can't find the field [_script_file] for autoset"- is this something set in union.xml?

If you'd like to visit the site on which I'm developing (not sure that's gonna help), its 94ism.com/drawr. Below is the error reporting from Union Admin, the browser console, and my function in GreeterBot.js

In Union Admin-
Module [net.user1.union.script.ScriptWrapperModule] could not find field [_script_file] for autoset. Assuming it will be handled manually in module code.
Script [GreeterBot.js] was loaded by ScriptEngine [null]

In my console:
Uncaught Error: A message listener for incoming message [CHAT_MESSAGE] encountered an error:
TypeError: Cannot call method 'getClientID' of null

Ensure that all [CHAT_MESSAGE] listeners supply a first parameter whose datatype is Client (or a compatible type). Listeners ... parameters match the following actual message arguments:
Goodbye Guest1.

In GreeterBot.js:

function onRoomAddClient(evt) {
var args = ["Welcome Guest" + evt.getClient().getClientID()];
moduleContext.getRoom().sendMessage("CHAT_MESSAGE", null, args);
}


In the Orbiter API:
addMessageListener(message, listener, thisArg, forRoomIDs)
---Indicates the arguments that can (optionally) be input into the addMessageListener;
The tutorial only inputs "CHAT_MESSAGE" and chatMessageListener, which are [message] and [listener], but not [thisArg] or [forRoomIDs].
So I think this may be part of the issue?


@Colin, any ideas???
jjMedina
 
Posts: 5
Joined: Fri 06 Sep 2013 17:21

Re: Errors when using Orbiter/JS-RoomModule

Postby colin » Fri 24 Jan 2014 22:13

hi jj,
i just updated our GreeterBot example to demonstrate receiving a message from the server in a JavaScript client. we previously showed the code in actionscript (reactor), but there was no javascript (orbiter) example. the following page should give you the information you're looking for:

http://www.unionplatform.com/?page_id=2615

i believe your only problem was failing to handle a null value for the message listener's "fromClient" parameter. when the server sends a message, the fromClient is null, and you have to, therefore, avoid invoking methods on the null fromClient. here's the working chat message listener:

Code: Select all
function chatMessageListener (fromClient, message) {
  // Treat any message whose fromClient is null as a message from GreeterBot.
  if (fromClient === null) {
    displayChatMessage("Union Server: " + message);
  } else {
    displayChatMessage("User" + fromClient.getClientID() + ": " + message);
  }
}


colin
colin
 
Posts: 232
Joined: Mon 17 Oct 2011 18:47


Return to Union Platform

Online

Users browsing this forum: No registered users and 3 guests