Data Sharing Between Apps

Channels

JavaScript

Adding Channels to Your App

To add the channel selector to your window, you need to set allowChannels to true in your application configuration file, under the details top-level key:

{
    "title": "Client List 🔗",
    "type": "window",
    "name": "channelsclientlist",
    "icon": "https://dev-enterprise-demos.tick42.com/resources/icons/clients.ico",
    "details": {
        "url": "https://dev-enterprise-demos.tick42.com/client-list-portfolio-contact/#/clientlist",
        "mode": "tab",
        "allowChannels": true
    }
}

Defining Channels

You can define any number of channels in Glue42 Enterprise for your applications to use - all you need to do is to configure them in the channels.json file in the %LocalAppData%\Tick42\GlueDesktop\config folder. Here is an example of adding a custom purple channel to an already existing list of channels in Glue42 Enterprise:

{
    "name": "Dark Purple",
    "meta": {
        "color": "#6400b0"
    }
}

Custom Channel

See the Configuration section for more detailed info on the configuration properties.

Subscribing for Data

The Channels API can be accessed through the glue.channels object.

See our JavaScript Channels example on GitHub.

To track the data in the current channel, use the glue.channels.subscribe() method:

// Subscribe for updates from the channel your application is currently on.
glue.channels.subscribe((data, channelInfo) => {
    // The callback will be invoked each time the data is updated. 
});

The callback receives :

  • data - the current data from the channel;
  • channelInfo - information about the channel you are currently on;

The callback will be invoked in three cases:

  • the data of the channel you are currently on is updated;
  • the user has switched the channel and you are receiving a snapshot of the new channel data;
  • your app is now not joined to any channel (e.g., the user has deselected the current channel). In this case, both data and channelInfo will be undefined;

To subscribe for updates from a specific channel, use:

glue.channels.subscribeFor("Green", (data, channelInfo) => {
    // The callback will be invoked each time the data is updated. 
});

The subscribeFor() method accepts a channel name as a first parameter and a callback to handle channel data updates.

Publishing Data

To update the context of the channel, use glue.channels.publish(). The publish() method accepts two parameters. The first parameter is the data to publish, which is required. The second parameter is an optional channel ID specifying which channel context to update. If you do not specify a channel ID, the current channel will be updated.

Updating the current channel:

glue.channels.publish({ RIC: "VOD.L" });

Updating a specific channel:

glue.channels.publish({ RIC: "VOD.L" }, "Green");

Note that a channel may contain multiple data structures, e.g. RIC and clientId. When executing the code above, this will update only the RIC field, leaving the other fields of the context unchanged.

The publish() method will throw an exception, if you are not on a channel and try to publish data.

Retrieving Channel Context

To get the context of a channel, use the glue.channels.get() method:

const data = await glue.channels.get("Green");

The get() method accepts a channel name as a required parameter.

Current Channel

To get the name of the channel your application is currently on, use the glue.channels.current() method:

let myChannel = glue.channels.current();

If you want to monitor how your app moves between channels, you can subscribe to updates with the glue.channels.changed() method:

glue.channels.changed((newChannel) => {
    if (!newChannel) {
        // handle the case where your app is not joined to any channel 
        // (e.g., the user has deselected the current channel)
    } else {
        // handle the case where you have switched to another channel 
    }
});

Reference

Reference