asterisk 0.2.1 copy "asterisk: ^0.2.1" to clipboard
asterisk: ^0.2.1 copied to clipboard

Idiomatic bindings to Asterisk's REST interface, allowing calls to be managed in Dart.

example/main.dart

import 'package:asterisk/asterisk.dart';

import '_credentials.dart';

/// Accepts incoming calls, announces the caller id on the channel and then
/// hangs up.
void main() async {
  final asterisk = createAsteriskClient();
  print('Starting up - dial number 1 to reach whoami');

  await for (final incoming in asterisk.stasisStart) {
    _announceId(incoming.channel);
  }
}

Future<void> _announceId(LiveChannel channel) async {
  print('Has incoming call from ${channel.channel.caller}');

  await channel.answer();
  await Future.delayed(const Duration(seconds: 1));

  // This could be simplified by just supplying an array of sources in a single
  // play() call, but doing this manually shows some of the event-handling
  // capabilities.
  var playback =
      await channel.play(sources: [MediaSource.sound('hello-world')]);
  await playback.events.where((e) => e is PlaybackFinished).first;

  playback = await channel
      .play(sources: [MediaSource.digits(channel.channel.caller.number)]);
  await playback.events.where((e) => e is PlaybackFinished).first;

  if (!channel.isClosed) {
    await channel.hangUp();
  }
}
0
likes
150
pub points
53%
popularity

Publisher

verified publishersimonbinder.eu

Idiomatic bindings to Asterisk's REST interface, allowing calls to be managed in Dart.

Repository (GitHub)
View/report issues

Topics

#asterisk #voip #sip #telephony

Documentation

API reference

License

MIT (LICENSE)

Dependencies

http, json_annotation, logging, meta, pool, weak_cache, web_socket_channel

More

Packages that depend on asterisk