By default EasyRTC allows all connections, however it can be locked down to work against a variety of authentication methods. Most commonly this is done by sending a username and credential upon connecting to the server.
Even if authentication is not needed, setting the username can be used to create a visible alternative to the easyrtcid.
easyrtc.setUsername()
easyrtc.connect() or easyrtc.easyApp()easyrtc.setCredential()easyrtc.usernameRegExpusernameRegExpValue is sent to the server "authenticate" event listener
easyrtc.setUsername("handsomeJack");
easyrtc.setCredential()
easyrtc.connect() or easyrtc.easyApp()Value is sent to the server "authenticate" event listener
easyrtc.setCredential({ "password":"345RTC!", "realm":"easyrtc.com", "apikey":"d834kds81vs189s10kkd4" });
Using "authenticate" Event Listener
The "authenticate" event is fired during the initial connection. The listener is provided with full details about the connection, so it may decide whether to authenticate or disconnect them.
In this simplistic example, any clients connecting to the adminSite application will be denied unless they have a username of "handsomeJack". Any clients connecting to any other application will be let through.
var onAuthenticate = function(socket, easyrtcid, appName, username, credential, easyrtcAuthMessage, next){
if (appName == "adminSite" && username != "handsomeJack"){
next(new easyrtc.util.ConnectionError("Failed our private auth."));
}
else {
next(null);
}
};
easyrtc.events.on("authenticate", onAuthenticate);
Listener Parameters:
socket.handshake.address.addresssocket.handshake.headers['x-forwarded-for']socket.handshake.headers.referersocket.disconnect() however it is recommended to call next() with an erroreasyrtc.setCredential()easyrtc.usernameRegExpusernameRegExpnext(null);next(new easyrtc.util.ConnectionError("Failed our private auth.")); For more information about EasyRTC server events, see easyrtcserverevents.md
Please feel free to post on our discussion forum: