-
Notifications
You must be signed in to change notification settings - Fork 5
How to write a Module
Davide Casali edited this page Mar 3, 2014
·
5 revisions
Modules are a core element of how Roomverse is conceived. Writing one is quite easy, you just need to create a new JavaScript file that listens to the desired events.
A module is structured as a single JS file contained in a folder with the same name. It uses the following structure:
module.Test = function() {
action.on('ready', function() {
console.log('[TestModule] Ready.');
});
}
-
ready
, triggered when the chat UI is loaded -
rooms-add
, triggered when a room is added. Gets the room name as parameter. -
rooms-remove
, triggered when a room is closed. Gets the room name as paraemetr. -
room-echo-*
, triggered when a specific room gets a message (i.e.room-echo-wordpress
). Gets the text as a parameter.
You can create sidebar widgets by hand just adding them to the correct sidebar (.rv-widgets.roomname
), however a better and more future-proof way is to use the provided Widget class.
The widget class is initialized with new Widget(room-name, widget-css-class, title, content)
.
An example module:
module.Alpha = function() {
action.on('rooms-add', function(room) {
var w = new Widget(room, 'alpha', 'Alpha Release',
'<p>This version is an alpha release, it\'s missing critical features. Please refer to GitHub for the current status.</p>' +
'<p>This widget is loaded for: <br/><strong>' + room + '</strong></p>'
);
});
}