asterisk / node-ari-client

Node.js client for ARI. This library is best effort with limited support.
Other
259 stars 102 forks source link

Error: Channel not found on hangup #156

Open uchepercynnoch opened 1 year ago

uchepercynnoch commented 1 year ago

Code Snippet

  private readonly url: string;
  private readonly username: string;
  private readonly password: string;

  constructor(config: ARIConfig) {
    this.url = config.url;
    this.username = config.username;
    this.password = config.password;
  }

  public async run() {
    const client = await this.getClient();

    client.once('StasisStart', (event, channel) => this.handleStasisStart(event, channel, client));
    client.once('StasisEnd', this.handleStasisEnd);

    await client.start('hello-world');
  }

  private async handleStasisStart(event: StasisStart, channel: Channel, client: Client) {
    const playback = client.Playback();

    await channel.ring();
    await appSetTimeout(2000);
    await channel.answer();
    await appSetTimeout(3000);
    await channel.play({ media: 'sound:hello-world' }, playback);
    await appSetTimeout(3000);
    await channel.hangup();
  }

  private async handleStasisEnd(event: StasisEnd, channel: Channel) {}

  private getClient(): Promise<Client> {
    return ari.connect(this.url, this.username, this.password);
  }

This works fine when I dial an extension. However, once I terminate the session, and try to hangup the session on StasisEnd handler, the above exception is thrown and node exists.

I can't seem to point out what is happening. This also happens when I use callbacks not just async/await.

Please help

Asterisk version - 18
Node version - 16
ARI client version - 2.2.0
RizeKishimaro commented 10 months ago

Same Here but The App runs fine if i didn't catch any error on Statsis end i likely think that because of the channel is destory while we are accessing the channel, That's why asterisk server return Channel Not Found.Hope Developer Fix it or we need to make a pull request

cculbreath commented 10 months ago

Anyone have any ideas on this one? I'm having the same issue.

dioris-moreno commented 9 months ago

It's always possible to try hanging up a channel that was already hung up, which will trigger an error. You should handle those and any other errors in your async functions using try-catch blocks.

public async run() {
    try {
        const client = await this.getClient();

        client.once('StasisStart', (event, channel) => this.handleStasisStart(event, channel, client));
        client.once('StasisEnd', this.handleStasisEnd);

        await client.start('hello-world');
    } catch (err) {
        console.log(err);
    }       
}
private async handleStasisStart(event: StasisStart, channel: Channel, client: Client) {
    try {
        const playback = client.Playback();

        await channel.ring();
        await appSetTimeout(2000);
        await channel.answer();
        await appSetTimeout(3000);
        await channel.play({ media: 'sound:hello-world' }, playback);
        await appSetTimeout(3000);
        await channel.hangup();

    } catch (err) {
        console.log(err);
    }
}
dorlanpabon commented 8 months ago

@uchepercynnoch , you have screen or config of dialplan extension, the part of execute Stasis app