Skip to content

Error: Channel not found on hangup #156

@uchepercynnoch

Description

@uchepercynnoch

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions