The online method initializes the AmbientJS middleware. The middleware will connect to an available local are network and automatically open TCP socket connections to all clients connected to the same network. To discover the other clients, the middleware allows for Zero Configuration Networking. For this the middleware internally uses technologies like Bonjour (on iOS) and Network Service Discovery (on Android).

Parameters

Returns

  • void
  • The createObject method creates a new object that can be shared over a network. This object will be shared by reference; whenever the object is discovered by another client, a reference pointing to that object is provided to that client. To interact with the remote object, the client has to send messages to the reference pointing to that remote object.

    Parameters

  • object - The javascript object (a key-value dictionary) that has to be made distributable.
  • proxy - A proxy object that redefines the behaviour of the references that point to the object. (optional)
  • Returns

  • localReference - A local reference pointing to the (internally stored) object.
  • The createIsolate method creates a new object that can be shared over a network. This object will be shared by copy; whenever the isolate is discovered by another client, a reference pointing to that isolate is provided to that client. This reference holds a local copy of the remote isolate. When accessing one of the properties or executing a non-mutating operation on the remote isolate, the local copy will be used. When executing a mutating operation on the remote isolate, the original remote isolate will be used.

    Parameters

  • object - The javascript object (a key-value dictionary) that has to be made distributable.
  • Returns

  • localReference - A local reference pointing to the (internally stored) isolate.
  • The exportAs method takes a local reference, pointing to an object or isolate, and distributes it over the network with a specific typetag. Whenever a local reference has been exported, other clients can discover the remote object or isolate.

    Parameters

  • localReference - A local reference pointing to an object that needs to be exported.
  • typetag - A typetag (a JavaScript string) with which the object has to be exported.

    Returns

  • void
  • The wheneverDiscovered method installs a callback that is executed whenever a remote object with the given typetag has been discovered.

    Parameters

  • typetag - A typetag (a JavaScript string) with which objects need to be discovered.
  • callback - A callback function that needs to be called whenever a remote object has been discovered. To this callback, a reference pointing to the remote object will be provided.

    Returns

  • void
  • The createMessage method creates a message that can be sent asynchronously to a reference that points to a local or remote object.

    Parameters

  • method - The name of the method that needs to be invoked.
  • arguments - A list of actual parameters, used to invoke the method.

    Returns

  • Message - A message object that can be sent asynchronously via a reference to an object.
  • The createReferenceProxy method creates a proxy for the references of an object. The method takes a behaviour object that redefines the onReceive and onPassReference methods of the references pointing to an object.

    Parameters

  • behaviour - A JavaScript function that produces an object defining the behaviour of the onReceive and/or onPassReference methods of a reference. This behaviour function needs to take one argument: a delegate that provides the default implemenation of a reference.

    Returns

  • ReferenceProxy - A proxy used when creating a new distributable object.
  • Example

    var referenceProxy = AmbientJS.createReferenceProxy(function(delegate) {
      this.onReceive = function(message) {
        console.log("receiving a method call: " + message.method + " at local object");
        delegate.onReceive(message);
      };
      this.onPassReference = function(reference) {
        console.log("passing a reference: " + reference);
        delegate.onPassReference(reference);
      };
    });

    The asyncSend method is used to send a message to a reference pointing to a local object, in order to invoke a method of that object. This message is sent asynchronously via the reference to the object. When no return value is expected the message has to be sent with the oneway-option. When a return value is expected, the message has to be sent with the twoway-option. When sending a message with the due-option, a timeout can be provided, stating that the remote invocation should have returned a value before the timeout. Otherwise, the communication is considered to have failed.

    Parameters

  • message - A message object that includes the method to be invoked and a list of actual parameters.
  • option - The option with which the message has to be sent (oneway, twoway or due).
  • timeout - The timeout for the lease when sending the message with the due-option (optional).
  • Returns

  • void
  • or
  • Future - A future that will be resolved with the return value or ruined whenever the leases expires.
  • The setProxy method installs a reference proxy on a reference pointing to a local object. Note: due to security reasons, a reference proxy can only be installed on a reference pointing to a locally stored object.

    Parameters

  • ReferenceProxy - A proxy used when creating a new distributable object.
  • Returns

  • void
  • The setMutableOperation method indicates which methods of an isolate are mutating methods. When another client, that has a copy of the isolate, executes this mutating method, the original version of the isolate is used. Note: the setMutableOperation method is only available for local references pointing to an isolate.

    Parameters

  • method - The name of the mutating method of an isolate (a JavaScript string).
  • Returns

  • void
  • The setProperty method updates the value of a property of an isolate. After updating the value of this property, all copies of the isolate held by other clients will be automatically updated. Note: the setProperty method is only available for local references pointing to an isolate.

    Parameters

  • property - The name of property of the isolate that needs to be changed (a JavaScript string).
  • value - The new value of the property of the isolate.

    Returns

  • void
  • The asyncSend method is used to send a message to a reference pointing to a remote object, in order to remotely invoke a method of that object. This message is sent asynchronously via the reference to the object. When no return value is expected the message has to be sent with the oneway-option. When a return value is expected, the message has to be sent with the twoway-option. When sending a message with the due-option, a timeout can be provided, stating that the remote invocation should have returned a value before the timeout. Otherwise, the communication is considered to have failed.

    Parameters

  • message - A message object that includes the method to be invoked and a list of actual parameters.
  • option - The option with which the message has to be sent (oneway, twoway or due).
  • timeout - The timeout for the lease when sending the message with the due-option (optional).
  • Returns

  • void
  • or
  • Future - A future that will be resolved with the return value or ruined whenever the leases expires.
  • The whenBecomes method of a future installs a callback on that future that will be executed whenever the future is resolved. The callback should be a function that receives one value, i.e. the value with which the future has been resolved.

    Parameters

  • callback - A function that will be executed when the future is resolved.
  • Returns

  • void
  • The whenExpires method of a future installs a callback on that future that will be executed whenever the future expires. The callback should be a function that receives one value, i.e. the expire exception.

    Parameters

  • callback - A function that will be executed when the future is expired.
  • Returns

  • void