Closed raarts closed 4 years ago
Hi @raarts,
The _client property is a "private" property used by the node-ari-client library to reference the client object that originally created the channel. In JavaScript, variables names beginning with "_" are private, but only by naming convention because you can actually access them. In node-ari-client you could see this reference in all the resources: channel, bridge, playback, etc.
If you need to access the client, just use the client object you created to connect to Asterisk, it is the same object referenced by _client. The typescript definitions @types/ari-client only expose the "public" properties and methods of the library, and this is intentional. We should not use the internal variables of the library.
For example, look at the originate.ts example, how the client object is used to create a Bridge inside the function that is listening for the StasisStart event.
const client = await Ari.connect(url, username, password);
.
.
.
outgoing.once('StasisStart', async (event, outgoing) => {
const bridge = client.Bridge();
outgoing.once('StasisEnd', async (event, channel) => {
await bridge.destroy();
});
await outgoing.answer();
const mixingBridge = await bridge.create({ type: 'mixing' });
await mixingBridge.addChannel({ channel: [incoming.id, outgoing.id] });
});
Ok, I see, thanks for the explanation.
Hi,
I'm reporting this here, because I detected it in the standard example. The callback on the StasisStart event, receives a channel parameter which contains a _client property, but the typescript complier refuses to compile it. I got around it by explicitly casting it:
(incoming as any)._client
. But I'm rather new to typescript. So my question is: is this intentional?Thanks.