Orbiter / Javascript Server Module example needed

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

Orbiter / Javascript Server Module example needed

Postby toby » Sat 28 Jul 2012 23:50

I have searched high, low, sideways, and every way I can think of,
but I have not found a complete example of a Server Module that receives messages.

I would like to use Orbiter (not Orbiter Micro) on the Client side,
and Javascript on the Server Side.

Lots of Room Module examples:
http://www.unionplatform.com/?page_id=3151 (Javascript)
http://www.unionplatform.com/?page_id=1072 (Java)
http://www.unionplatform.com/?page_id=3127 (Orbiter Micro and Javascript)
http://www.unionplatform.com/?page_id=3073 (Fragments of code for Room and Server Modules)
http://www.unionplatform.com/?page_id=2615 (Creating Room Modules with Javascript)
http://www.unionplatform.com/?page_id=1159 (Fridge magnets, Java example)
... etc.

Here's a server module example in Java
http://www.unionplatform.com/?page_id=11


Also, what is a "moduleContext" ? and what is a "wrapper" ?
Does only Javascript need the "wrapper"?
And does it apply to Server as well as Room Modules?

ADDED:
In this example: http://www.unionplatform.com/?page_id=2615
It does these two:
wrapper.addRoomEventListener(RoomEvent.REMOVE_CLIENT, "onRoomRemoveClient");
moduleContext.getRoom().sendMessage("CHAT_MESSAGE", args);

When do you use the wrapper, and when do you use the moduleContext?

And, for a Server Module, what can I call from those two?
I'm trying to do a custom "Create Account" module, and getting nowhere,
since every function I try to call (createAccount, getAccountManager)
is undefined, on both of those.
-- end ADDED --

If you could direct me to an example of the type I'm seeking that would
be most helpful, or if there isn't one, maybe one could be created.
Last edited by toby on Sun 29 Jul 2012 21:45, edited 1 time in total.
toby
 
Posts: 162
Joined: Sun 24 Jun 2012 14:18

Re: Orbiter / Javascript Server Module example needed

Postby toby » Sun 29 Jul 2012 14:39

In general, the documentation for modules seems rather hit-and-miss.

In "Creating Server Modules with Java"
http://www.unionplatform.com/?page_id=11
it explains how you have to modify union.xml in Step 7.

But not for Javascript.
... [ EDIT: I did find one such example.
... http://www.unionplatform.com/?page_id=677
... The subject of that page is "Rooms" ]


In "Creating Room Modules with Javascript"
http://www.unionplatform.com/?page_id=2615
it explains how to deploy the module using run-time code in Reactor.

What about the other 6 cases?
(Java | Javascript ) × (Server | Room ) × (union.xml | run-time ) = 2 * 2 * 2 = 8 cases.
Or at least enough of them to be able to generalize the others.

For the client side, there is Orbiter vs OrbiterMicro vs Reactor,
and similarly there, the cases are a patchwork.
Last edited by toby on Sun 29 Jul 2012 20:22, edited 1 time in total.
toby
 
Posts: 162
Joined: Sun 24 Jun 2012 14:18

Re: Orbiter / Javascript Server Module example needed

Postby toby » Sun 29 Jul 2012 17:02

Well ... I managed to wade through all the examples
and put together something that is starting to work ...

On the client side, I do this:
Code: Select all
server = orbiter.getServer();
msgManager = orbiter.getMessageManager();
...
var args = new Object();
args.att1 = "value1";
args.att2 = "value2";
... etc.
server.sendModuleMessage("MyModuleName", "onModuleMessage", args);


In union.xml I added:
Code: Select all
<module>
    <id>MyModuleName</id>
    <source type="script">MyModuleName.js</source>
</module>

And in the module.js file I have:
Code: Select all
function init(ctx, wrap)
{
  moduleContext = ctx;
  wrapper = wrap;
  wrapper.addRoomEventListener(RoomEvent.MODULE_MESSAGE, "onModuleMessage");
}

// which seems to work, even though there is no room involved

function onModuleMessage(e)
{
log.debug("Module message received.");

// Print a list of all module message arguments in the log
log.debug("    All message arguments:");

var args = e.getArgs();
var argIterator = args.entrySet().iterator();
var arg;
while (argIterator.hasNext())
   {
    arg = argIterator.next();
    log.debug("        " + arg.getKey() + " = " + arg.getValue());
   }
log.debug("    From client: " + e.getClient().getClientID());
log.debug("    Message name: " + e.getMessage().getMessageName());
}


The latter part works ok ... up to the e.getClient() part,
where Java complains about
Cannot find function getClient().
(and similarly for e.getMessage() )

Which brings me to my next question:
How do I send a reply to (only) the client who initiated this message?
(especially one who hasn't logged in, just connected,
since, in fact, what I'm doing here is a "Create Account" function,
and if you don't have an account, you can't really "log in".)

I'll continue to try to figure that out on my own ... but I still
would like to see a reply to the issues raised in this thread.
toby
 
Posts: 162
Joined: Sun 24 Jun 2012 14:18

Re: Orbiter / Javascript Server Module example needed

Postby toby » Mon 30 Jul 2012 15:19

Finally, I figured out that I can call moduleContext.getServer().

From there I guess I can do whatever I want ...
I wish it had been easier to find that out ...
toby
 
Posts: 162
Joined: Sun 24 Jun 2012 14:18

Re: Orbiter / Javascript Server Module example needed

Postby toby » Mon 30 Jul 2012 16:08

Similar issues about lack of clarity in documentation for Server Modules
were raised here: http://factory.user1.net/boards/15/topics/show/414
and those messages are dated about 1 1/2 years ago.

That's a good indication the documentation could be improved.
toby
 
Posts: 162
Joined: Sun 24 Jun 2012 14:18

Re: Orbiter / Javascript Server Module example needed

Postby jjMedina » Sat 07 Sep 2013 04:12

Haha hey Toby! Funny that you just replied to your own post several times; I just read through the story of your troubles like a blog; it's too bad nobody helped you out.

I'm having the exact same issues using Orbiter (not Micro), creating the Room and Module in the union.xml, and having problems with .getClient

It seems that it doesn't recognize "wrapper" and "moduleContext" as it should: the script should be registering for events through the rooms wrapper, which is the parent, and somewhere in the mix it's getting botched...

Interesting... Colin?
jjMedina
 
Posts: 5
Joined: Fri 06 Sep 2013 17:21


Return to Union Platform

Online

Users browsing this forum: No registered users and 9 guests