Create room on server side, stop broadcasting of new rooms

1,335 views
Skip to first unread message

Fabian Bernhard

unread,
Oct 15, 2013, 5:55:07 AM10/15/13
to eas...@googlegroups.com
Hi all,

I am using v0.10.1.a and following settings:

easyrtc.setOption("roomAutoCreateEnable", false);
easyrtc.setOption("roomDefaultEnable", false);

I would like to 

1) create rooms from the server and not allow the users to create rooms through the web API. How can I achieve this? In see a method "appObj.createRoom" defined in "easyrtc_server.js" but don't know how to call it from my own server implementation which is based on your "server_example/server.js".

2) Stop the creation of rooms being broadcasted to all connections. Basically I want the rooms to be "private" and only known to those who have access to a certain room. How can I stop the broadcasting of the rooms?

Thanks and regards,

Fabian

Fabian Bernhard

unread,
Oct 15, 2013, 10:28:53 PM10/15/13
to eas...@googlegroups.com
I should have read the documentation, it states that "In the near(ish) future, we will be exposing methods to manage configuration options at the application and room level. " ;-)

I have resolved 1) by exposing the createRoom method in easyrtc_server.js, like this:

exports.createRoom = function(roomName, callback) {
// app name for now hard coded ... should be dynamic of course! 
// TODO: make app name dynamic 
var appname = "easyrtc.instantMessaging"; 

// Call createApp in case the app was not created yet 
// it returns "undefined" for appObj if the app exists already
pub.createApp(appname, null, function(err, appObj) { 
// appObj is undefined if room already exists 
// therefore, get the app object here. 
pub.app(appname, function(err, appObj) { 
appObj.createRoom(roomName, null, callback); 
}); 
}); 
};

2) is not happening anymore, can't tell why though.

Rod Apeldoorn

unread,
Oct 15, 2013, 11:59:38 PM10/15/13
to eas...@googlegroups.com
Hey Fabian,

Yes v0.10 will add lots of power to control things at the application and room level. One feature which is currently possible but not yet documented, is to interrupt the default EasyRTC events with your own code. I'll post more on this later.

As for your issues:

1) There is a configuration setting you should be aware of. Note they may not currently work as expect (but they will soon :)
  • "roomAutoCreateEnable" which defaults to true. Enables the creation of rooms from the API. Occurs when client joins a nonexistent room.
  • "roomDefaultEnable" which defaults to true. Enables connections joining a default room if it is not initially specified. If false, than a connection initially may be in no room.
Both of these are application level options, so they can be difference for each application. "roomDefaultEnable" must be set prior or during the creation of the application or else the default room will be automatically created.

I'll post a separate server.js example which uses these options to create an app.

2) The current alpha version of EasyRTC is much better about how it sends client lists. By default it will only send client lists of other people who have joined the same room as you. Server code can be added to restrict who can join which rooms. In a future version I may add a flag to hide users even in the same room.

Rod Apeldoorn, Priologic Software


Rod Apeldoorn

unread,
Oct 16, 2013, 12:04:34 AM10/16/13
to eas...@googlegroups.com
Below is a server.js example for how to create an application with defined rooms. If you run this, and then try the basic instant messaging demo, you'll find it will block you from joining the default room, thus you won't see anyone. If you run the newer Instant Messaging Rooms demo, you will see that the red blue and green rooms are created and available. I note there is a bug where the default room is still created when it's not supposed to be.

var http    = require("http");              // http server core module
var express = require("express");           // web framework external module
var io      = require("socket.io");         // web socket external module
var easyrtc = require("easyrtc");           // EasyRTC external module

// Setup and configure Express http server. Expect a subfolder called "static" to be the web root.
var httpApp = express();
httpApp.configure(function() {
    httpApp.use(express.static(__dirname + "/static/"));
});

var webServer = http.createServer(httpApp).listen(80);
var socketServer = io.listen(webServer);

// Start EasyRTC server with options to change the log level and add dates to the log.
var easyrtcServer = easyrtc.listen(
        httpApp,
        socketServer,
        {logLevel:"debug", logDateEnable:true},
        function(err, rtc) {
            // Creates a new application called easyrtc.instantMessaging with locked down rooms.
            rtc.createApp(
                "easyrtc.instantMessaging", 
                {
                    "roomAutoCreateEnable":false,
                    "roomDefaultEnable":false
                },
                myEasyrtcApp
            );
        }
);

// Callback listener for the EasyRTC application "easyrtc.instantMessaging"  
var myEasyrtcApp = function(err, appObj) {
    appObj.createRoom("redroom",null,function(err, roomObj){});
    appObj.createRoom("blueroom",null,function(err, roomObj){});
    appObj.createRoom("greenroom",null,function(err, roomObj){});
};


Fabian Bernhard

unread,
Oct 16, 2013, 12:44:53 AM10/16/13
to eas...@googlegroups.com
Hi Rod,

Thanks a lot for your detailed response. This is the feature I was looking for, that way I don't have to hack "your" code, much cleaner!

Cheers,

Fabian
Reply all
Reply to author
Forward
0 new messages