Connecting To VoiceLayer

Instantiating with your API keys

With the SDK included in your web page you can create an instance of VoiceLayer:

voicelayer = new VoiceLayer(app_key, app_secret);

Replace app_key with your API key and app_secret with your API secret. As previously mentioned, you can change the directory that the workers are located in by passing in an optional 3rd argument:

voicelayer = new VoiceLayer(app_key, app_secret, "scripts/worker_directory");


Connecting will allow you to receive real-time events. In order to connect, you must have a user token. There are two ways you can use a token to connect.

To connect via authentication you can use currentUser.login:

voicelayer.auth.login(email, password, function(err, data) {
  if (err) {
    // The error response from the server will be available in data.error
  } else {
    // The data object represents the user

If the user is successfully connected then connect will be called implicitly. If you wish to explicitly connect and already have a token (perhaps you saved the response from the previous call) then you can use currentUser.setToken and connect:



You can disconnect by using disconnect:


After disconnecting, you will no longer receive real-time events.

disconnect is called implicitly if the user logs out. To log the user out, use the currentUser.logout function. The token will be invalidated after logging out.