VivochaBus

The Vivocha Bus implements a transparent message bus that enables Vivocha and third party components to communicate seamlessly across iframe and browser windows. The Bus is a singleton and it's automatically instantiated when the Vivocha libraries are setup.

Through the Bus, applications running in iframes or browser popups can access all services offered by Vivocha via proxy object. Proxied objects present an interface almost to the original ones, with two exceptions:

  • the return values of all methods are converted to Promise objects and therefore any synchrounous method, when accessed through a proxy, behaves asynchounously
  • member variables are not proxied: it's therefore required to access member variables via accessor methods

The Bus lets applications and libraries expose and access services: a service is simply a collection of functions. Services are "global", in the sense that are not linked to a specific contact. Applications running in the context of a single contact, wanting to limit the exposure of a service to other applications of the same contact, can make the service appending the contact id to id (for instance custom-crm-20160509ca6c0cb25bb2a77d51cc12d14facf3c7).

The Bus is accessed through the property bus of the vivocha global object: vivocha.bus.

See the documentation of the registerService method for usage examples.

Table of Contents

Constructor

new VivochaBus()

Internal constructor, not to be used directly.

Extends

  • EventEmitter

Members

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

Methods

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

Events

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

The Vivocha Bus implements a transparent message bus that enables Vivocha and third party components to communicate seamlessly across iframe and browser windows. The Bus is a singleton and it's automatically instantiated when the Vivocha libraries are setup.

Through the Bus, applications running in iframes or browser popups can access all services offered by Vivocha via proxy object. Proxied objects present an interface almost to the original ones, with two exceptions:

  • the return values of all methods are converted to Promise objects and therefore any synchrounous method, when accessed through a proxy, behaves asynchounously
  • member variables are not proxied: it's therefore required to access member variables via accessor methods

The Bus lets applications and libraries expose and access services: a service is simply a collection of functions. Services are "global", in the sense that are not linked to a specific contact. Applications running in the context of a single contact, wanting to limit the exposure of a service to other applications of the same contact, can make the service appending the contact id to id (for instance custom-crm-20160509ca6c0cb25bb2a77d51cc12d14facf3c7).

The Bus is accessed through the property bus of the vivocha global object: vivocha.bus.

See the documentation of the registerService method for usage examples.

Table of Contents

Constructor

new VivochaBus()

Internal constructor, not to be used directly.

Extends

  • EventEmitter

Members

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

Methods

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

Events

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

The Vivocha Bus implements a transparent message bus that enables Vivocha and third party components to communicate seamlessly across iframe and browser windows. The Bus is a singleton and it's automatically instantiated when the Vivocha libraries are setup.

Through the Bus, applications running in iframes or browser popups can access all services offered by Vivocha via proxy object. Proxied objects present an interface almost to the original ones, with two exceptions:

  • the return values of all methods are converted to Promise objects and therefore any synchrounous method, when accessed through a proxy, behaves asynchounously
  • member variables are not proxied: it's therefore required to access member variables via accessor methods

The Bus lets applications and libraries expose and access services: a service is simply a collection of functions. Services are "global", in the sense that are not linked to a specific contact. Applications running in the context of a single contact, wanting to limit the exposure of a service to other applications of the same contact, can make the service appending the contact id to id (for instance custom-crm-20160509ca6c0cb25bb2a77d51cc12d14facf3c7).

The Bus is accessed through the property bus of the vivocha global object: vivocha.bus.

See the documentation of the registerService method for usage examples.

Table of Contents

Constructor

new VivochaBus()

Internal constructor, not to be used directly.

Extends

  • EventEmitter

Members

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

Methods

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

Events

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

The Vivocha Bus implements a transparent message bus that enables Vivocha and third party components to communicate seamlessly across iframe and browser windows. The Bus is a singleton and it's automatically instantiated when the Vivocha libraries are setup.

Through the Bus, applications running in iframes or browser popups can access all services offered by Vivocha via proxy object. Proxied objects present an interface almost to the original ones, with two exceptions:

  • the return values of all methods are converted to Promise objects and therefore any synchrounous method, when accessed through a proxy, behaves asynchounously
  • member variables are not proxied: it's therefore required to access member variables via accessor methods

The Bus lets applications and libraries expose and access services: a service is simply a collection of functions. Services are "global", in the sense that are not linked to a specific contact. Applications running in the context of a single contact, wanting to limit the exposure of a service to other applications of the same contact, can make the service appending the contact id to id (for instance custom-crm-20160509ca6c0cb25bb2a77d51cc12d14facf3c7).

The Bus is accessed through the property bus of the vivocha global object: vivocha.bus.

See the documentation of the registerService method for usage examples.

Table of Contents

Constructor

new VivochaBus()

Internal constructor, not to be used directly.

Extends

  • EventEmitter

Members

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

Methods

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

Events

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

The Vivocha Bus implements a transparent message bus that enables Vivocha and third party components to communicate seamlessly across iframe and browser windows. The Bus is a singleton and it's automatically instantiated when the Vivocha libraries are setup.

Through the Bus, applications running in iframes or browser popups can access all services offered by Vivocha via proxy object. Proxied objects present an interface almost to the original ones, with two exceptions:

  • the return values of all methods are converted to Promise objects and therefore any synchrounous method, when accessed through a proxy, behaves asynchounously
  • member variables are not proxied: it's therefore required to access member variables via accessor methods

The Bus lets applications and libraries expose and access services: a service is simply a collection of functions. Services are "global", in the sense that are not linked to a specific contact. Applications running in the context of a single contact, wanting to limit the exposure of a service to other applications of the same contact, can make the service appending the contact id to id (for instance custom-crm-20160509ca6c0cb25bb2a77d51cc12d14facf3c7).

The Bus is accessed through the property bus of the vivocha global object: vivocha.bus.

See the documentation of the registerService method for usage examples.

Table of Contents

Constructor

new VivochaBus()

Internal constructor, not to be used directly.

Extends

  • EventEmitter

Members

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

Methods

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

Events

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

The Vivocha Bus implements a transparent message bus that enables Vivocha and third party components to communicate seamlessly across iframe and browser windows. The Bus is a singleton and it's automatically instantiated when the Vivocha libraries are setup.

Through the Bus, applications running in iframes or browser popups can access all services offered by Vivocha via proxy object. Proxied objects present an interface almost to the original ones, with two exceptions:

  • the return values of all methods are converted to Promise objects and therefore any synchrounous method, when accessed through a proxy, behaves asynchounously
  • member variables are not proxied: it's therefore required to access member variables via accessor methods

The Bus lets applications and libraries expose and access services: a service is simply a collection of functions. Services are "global", in the sense that are not linked to a specific contact. Applications running in the context of a single contact, wanting to limit the exposure of a service to other applications of the same contact, can make the service appending the contact id to id (for instance custom-crm-20160509ca6c0cb25bb2a77d51cc12d14facf3c7).

The Bus is accessed through the property bus of the vivocha global object: vivocha.bus.

See the documentation of the registerService method for usage examples.

Table of Contents

Constructor

new VivochaBus()

Internal constructor, not to be used directly.

Extends

  • EventEmitter

Members

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

services

Dictionary of the currently available services. Each key is a service id and the corresponding value is the service provider.

Methods

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

registerService(id, provider)

Register a service provider on the bus: all users of the bus will be able to access the service. Registered services are available through the property services or the method request.

Examples

Registering a service on the Bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.registerService("HelloWorld", {
      greet: function(name) {
        // Note that even if this function is synchronous
        // it'll return a Promise when accessed throught the Bus
        return "Hello, " + (name || "World") + "!";
      }
    });
  });

Being notified of any new service becoming available

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added", function(id, provider) {
      console.log('service ' + id + ' is now available');
      // provider can be used directly
    });
  });

Being notified of a particular service becoming available and using it

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.on("added.HelloWorld", function(provider) {
      provider.greet().then(function(greeting) {
        console.log(greeting); // Prints "Hello, World!"
      });
    });
  });

Using a service directly via the bus

  // Wait for the library to be ready
  vivocha.ready().then(function() {
    vivocha.bus.services.HelloWorld.greet().then(function(greeting) {
      console.log(greeting); // Prints "Hello, World!"
    });
  });
Parameters:
Name Type Description
id string

Unique identifier of the service being added.

provider object

Objected implementing the service being offered through the bus.

unregisterService(id)

Deregister a previously registered service. Only the bus user that registered the service can deregister it.

Parameters:
Name Type Description
id string

Identifier of the service to deregister.

request(id, method, …argsopt) → {Promise}

Invoke a method on a registered service. Similar to calling vivocha.bus.id.method(...args), but checks that service and method are available.

Example
vivocha.bus.request('HelloWorld', 'greet', 'John').then(function(greeting) {
    console.log(greeting); // Prints "Hello, John!"
  });
Parameters:
Name Type Attributes Description
id string

Identifier of the service to invoke a method upon.

method string

Name of the method to invoke.

args * <optional>
<repeatable>

Method arguments

Returns:
Type
Promise

Events

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.

added

A new service is available.

Parameters:
Name Type Description
id string

The id of the new service.

provider object

A reference to the service provider object.

added∙SERVICE_ID

A new service called SERVICE_ID is available.

Parameters:
Name Type Description
provider object

A reference to the service provider object.

removed

A service is no longer available.

Parameters:
Name Type Description
id string

The id of the service.

removed∙SERVICE_ID

The service SERVICE_ID is no longer available.