The Ocelloids client.

import { OcelloidsClient, xcm } from "@sodazone/ocelloids-client";

const client = new OcelloidsClient({
httpUrl: "http://127.0.0.1:3000",
wsUrl: "ws://127.0.0.1:3000"
});

const agent = client.agent<xcm.XcmInputs>("xcm");
// create a 'long-lived' subscription
const reply = await agent.createSubscription({
id: "my-subscription",
args: {
origins: ["urn:ocn:polkadot:2004"],
senders: "*",
events: "*",
destinations: [
"urn:ocn:polkadot:0",
"urn:ocn:polkadot:1000",
"urn:ocn:polkadot:2000",
"urn:ocn:polkadot:2034",
"urn:ocn:polkadot:2104"
],
},
channels: [
{
type: "webhook",
url: "https://some.webhook"
},
{
type: "websocket"
}
]
});

// subscribe to the previously created subscription
const ws = agent.subscribe(
"my-subscription",
{
onMessage: msg => {
if(xcm.isXcmReceived(msg)) {
console.log("RECV", msg.subscriptionId);
} else if(xcm.isXcmSent(msg)) {
console.log("SENT", msg.subscriptionId)
}
console.log(msg);
},
onError: error => console.log(error),
onClose: event => console.log(event.reason)
});
// subscribe on-demand
const ws = agent.subscribe({
origins: ["urn:ocn:polkadot:2004"],
senders: "*",
events: "*",
destinations: [
"urn:ocn:polkadot:0",
"urn:ocn:polkadot:1000",
"urn:ocn:polkadot:2000",
"urn:ocn:polkadot:2034",
"urn:ocn:polkadot:2104"
]
}, {
onMessage: msg => {
if(xcm.isXcmReceived(msg)) {
console.log("RECV", msg.subscriptionId);
} else if(xcm.isXcmSent(msg)) {
console.log("SENT", msg.subscriptionId)
}
console.log(msg);
},
onError: error => console.log(error),
onClose: event => console.log(event.reason)
});

Constructors

Methods

Constructors

Methods

  • Checks the health of the service.

    Parameters

    • Optionaloptions: Options

      The ky request options (fetch compatible)

    Returns Promise<{ status: string; statusCode: number; uptime: number }>

    A promise that resolves with the health status.

  • Fetches the list of configured network identifiers (URNs) from the server.

    Parameters

    • Optionaloptions: Options

      The ky request options (fetch compatible)

    Returns Promise<string[]>

    A promise that resolves to an array of network URNs as strings.