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).
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.
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.
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.
The wheneverDiscovered method installs a callback that is executed whenever a remote object with the given typetag has been discovered.
The createMessage method creates a message that can be sent asynchronously to a reference that points to a local or remote 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.
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.
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.
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.
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.
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.
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.
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.