OrbiterMicro Quick Start

To create connected content and applications with OrbiterMicro, follow these steps.

Step 1: Add OrbiterMicro to Your Web Page

Add the following code to your .html file's <head> tag. It loads OrbiterMicro from Union's official CDN.

<script type="text/javascript" src="http://cdn.unioncloud.io/OrbiterMicro_latest.js"></script>

When you're ready to push your code live to production replace the preceding line with this one (it links to the smaller, minified version of OrbiterMicro):

<script type="text/javascript" src="http://cdn.unioncloud.io/OrbiterMicro_latest_min.js"></script>

If you prefer to host OrbiterMicro yourself, see Installing Hosted OrbiterMicro.

Step 2: Connect to Union Server

After the <script> tag you added in the preceding section, add the following code to your .html file.

<script type="text/javascript">
// Create Orbiter object
var orbiter = new net.user1.orbiter.Orbiter();

// Register for connection events
orbiter.addEventListener(net.user1.orbiter.OrbiterEvent.READY, readyListener, this);
orbiter.addEventListener(net.user1.orbiter.OrbiterEvent.CLOSE, closeListener, this);

// Connect to Union
orbiter.connect("tryunion.com", 80);

// Connection event listeners
function readyListener (e) {
  alert("OrbiterMicro connected to Union!");

function closeListener (e) {
  alert("OrbiterMicro connection closed.");

Step 3: Communicate with Union Server

OrbiterMicro applications communicate with Union Server using the UPC messages defined by the UPC Protocol specification.

Send a UPC Message

To send a UPC message, use MessageManager's sendUPC() method, as shown in the following generic code:

orbiter.getMessageManager().sendUPC(upcName, upcArg1, upcArg2,...upcArgn);

For upcName, specify the name of the UPC message you want to send (can be a string, such as "u4", or a property of the net.user1.orbiter.UPC object). After upcName, provide a list of message arguments. Each UPC message's parameters are listed in the UPC Protocol specification.

For example, the modified version of the earlier readyListener() function creates and joins a room named "example":

function readyListener (e) {
  var UPC = net.user1.orbiter.UPC;
  orbiter.getMessageManager().sendUPC(UPC.CREATE_ROOM, "example");
  orbiter.getMessageManager().sendUPC(UPC.JOIN_ROOM, "example");

Receive a UPC Message

To receive a UPC message, use MessageManager's addMessageListener() method, as shown in the following generic code:

orbiter.getMessageManager().addMessageListener(upcName, listenerFunction, thisObject);

For upcName, specify the name of UPC message you want to receive. For listenerFunction, specify the function you want to execute when the client receives the specified UPC message. For thisObject, specify the object on which you want to invoke listenerFunction.

For example, the following code registers the function joinedRoomListener() to be executed whenever the current client joins a room.

orbiter.getMessageManager().addMessageListener(UPC.JOINED_ROOM, joinedRoomListener, this);

function joinedRoomListener (roomID) {
  alert("Joined room: " + roomID);

Step 4: Learn By Example

To see the steps in this quick start assembled into a fully functional example, see OrbiterMicro examples.

Step 5: Get Support

If you have questions or need help, visit the Union Platform forums. For priority support, consider a Union Member licence.