Room Modules
Modules are custom code that can be deployed inside Union Server. There are two types of modules: server modules and room modules. Server modules add functionality to the entire server and are not associated with a specific room. Room modules add functionality to a room. Room modules can be written in Java or almost any scripting language that has an invocable syntax (eg. Javascript, Python). For a list of supported script engines see Sun's Scripting Engines and Scripting Applications.
Room Modules
To create a room module you must first write the module code and then deploy the module. The key difference between a server module and a room module is a room module is associated with with a specific instance of a room. The associated room can be retrieved in the ModuleContext. A room module is removed when the associated room is removed from the server.
Room Modules: Write the Module
The following Java class ChatBotRoomModule is an example of a skeleton room module. We are going to fill it in so that it becomes a "chat bot" which sends messages to a chat room.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | package net.user1.union.example.roommodule; import net.user1.union.api.Module; import net.user1.union.core.context.ModuleContext; /** * Joins a chat room (see Your First Union Application at www.unionplatform.com) and welcomes users, says goodbye, * and occasionally adds to the conversation. */ public class ChatBotRoomModule implements Module, Runnable { private ModuleContext m_ctx; public boolean init(ModuleContext ctx) { return true; } public void shutdown() { } } |