esl 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 47

libesl-dart #

FreeSWITCH event socket client library written in Dart

The project is in an early state and contributions/bug reports are very welcome. See the examples directory for usage.

Basic usage #

You need to add the esl library to your pubspec.yaml.

  esl: '<0.1.0'

And import it in your sources.

import 'package:esl/esl.dart' as esl;

Connecting #

esl.Connection conn = new esl.Connection();
conn.connect('', 8021);

Authenticating #

The first thing you will need to do after having connected, is authenticate. Libesl-dart is fully asynchronous and uses streams for the events, responses and requests coming from the FreeSWITCH server.

This means that the way you handle authentication, is that you setup a listener for auth/request requests coming from the server.

Example code

esl.Connection conn = new esl.Connection();
conn.requestStream.listen((esl.Packet packet) {
  switch (packet.contentType) {
    case (esl.ContentType.authRequest):

conn.connect('', 8021);

Log trace #

Every esl connection object has its own logger object that is muted by default. It uses the "logging" package[1] from, so you may need to include this package in your project.

In order to tap into the log trace you need to set an onRecord handler. This can be done at any time, but makes most sense doing at instantiation.

Example code

esl.Connection conn = new esl.Connection()

This makes every log entry go to the root Logger, and inherit its loglevel.


Features and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

0.1.1 #

  • Minor changes to comply with Dart version 2.6
  • Formatting and fixes for warnings.

0.1.0 #

  • Breaking changes: see 0.0.99

0.0.99 #

  • Breaking changes:

    • Made log field in Connection private (breaking)
    • Class field excludedFields in Channel class is no longer public.
    • Connection.connect no longer returns the Socket object.
    • Connection class no longer connects for you. A connected socket must be passed to the constructor.
    • Packets no longer parses the payload, but just stores the bytes.
    • The Event, Response and Reply classes are no longer derived from the Packet class. This means that you must update your listener type, if you use the general Packet type.
    • Notice stream of Connection object now spawns typed Notice objects, rather than Packet objects.
    • Response.rawLength renamed to content
    • Event.contentAsMap renamed to fields . Event.field function removed. Use Event.fields Map instead.
  • Non-breaking

  • Added utility authentication handler function

  • Branched out packet transformer to seperate library.

  • Cleaned up API documentation.

0.0.21 #

  • Made fields headerBuffer and bodyBuffer private. These were, unintentially, left public but were never intended to be exposed.
  • Closed #9 Socket Writes may cause async errors.

0.0.20 #

Breaking change release. Removed the un-dartly named functions and constants that was deprecated in 0.0.19.

0.0.19-1 #

Patch release with documentation generated.

0.0.19 #

  • Addition of notice stream for disconnect notice
  • Deprecated most of the un-dartly named functions and constants
  • Added job-uuid parameter for bgapi
  • Minor bugfixes

0.0.16-beta #

  • Initial beta release


// Copyright (c) 2015, Kim Rostgaard Christensen. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file.

library esl.example;

import 'dart:async';
import 'dart:io';

import 'package:esl/constants.dart' as esl;
import 'package:esl/esl.dart' as esl;
import 'package:logging/logging.dart';

Future<Null> main() async {
  /* Changing the root log level propagates to libesl-dart.*/
  Logger.root.level = Level.ALL;
  final List<String> events = <String>[esl.EventType.all];

  esl.Connection conn = new esl.Connection(
      await Socket.connect('localhost', 8021),
      onDisconnect: () => print('oooof'));

  /* FreeSWITCH will send requests to your connection - for instance
    authentication requests.
    In order to respond to them automatically, you can subscribe to
    them from the requestStream. */
  conn.requestStream.listen((esl.Request request) {
    /* An authentication request should be responded to be an
         authentication. This is an example on how to do it. */
    if (request is esl.AuthRequest) {
      /* As the authentication call is a future, you can use .then
           blocks to schedule subsequent command or API calls when
           the authentication returns properly. */
          .then((_) => conn.event(events, format: esl.EventFormat.json))
          .catchError((dynamic e) => print(e));

  /* Each connection object has an event stream that can be subscribed
     to globally. This means that you have to handle further dispatching
     manually using, for instance, a switch statement. */
  esl.ChannelList channelList = new esl.ChannelList();

  conn.eventStream.listen((esl.Event event) {
    switch (event.eventName) {
      case (esl.EventType.custom):
        esl.Channel channel = new esl.Channel.fromEvent(event);
      case (esl.EventType.channelCreate):

  conn.noticeStream.listen((esl.Notice notice) => print(notice.runtimeType));

  await new Future<Null>.delayed(new Duration(seconds: 1));
  print(await conn.bgapi('status'));

/// Checks authentication reply
void _checkAuthentication(esl.Reply reply) {
  if (reply.status != esl.CommandReply.ok) {
    throw new StateError('Invalid credentials!');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  esl: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:esl/esl.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with runtime flutter-web on web


  • package:esl/esl.dart that imports:
  • dart:io

Package not compatible with runtime js


  • package:esl/esl.dart that imports:
  • dart:io

Health suggestions

Fix lib/src/connection.dart. (-9.08 points)

Analysis of lib/src/connection.dart reported 19 hints, including:

line 10 col 44: Avoid const keyword.

line 20 col 20: Unnecessary new keyword.

line 24 col 23: Unnecessary new keyword.

line 30 col 7: Unnecessary new keyword.

line 32 col 7: Unnecessary new keyword.

Fix lib/packet_transformer.dart. (-4.41 points)

Analysis of lib/packet_transformer.dart reported 9 hints, including:

line 14 col 27: Avoid const keyword.

line 25 col 48: Unnecessary new keyword.

line 64 col 27: Unnecessary new keyword.

line 69 col 34: Unnecessary new keyword.

line 70 col 17: Unnecessary new keyword.

Fix lib/src/channel.dart. (-3.45 points)

Analysis of lib/src/channel.dart reported 7 hints, including:

line 33 col 47: Avoid const keyword.

line 47 col 33: Unnecessary new keyword.

line 48 col 37: Unnecessary new keyword.

line 65 col 37: Unnecessary new keyword.

line 69 col 35: Unnecessary new keyword.

Fix additional 10 files with analysis or formatting issues. (-14.44 points)

Additional issues in the following files:

  • lib/src/event.dart (5 hints)
  • lib/constants.dart (4 hints)
  • lib/src/peer.dart (4 hints)
  • lib/src/authentication_handler.dart (3 hints)
  • lib/src/response.dart (3 hints)
  • lib/src/channel_list.dart (2 hints)
  • lib/src/notice.dart (2 hints)
  • lib/src/packet.dart (2 hints)
  • lib/src/peer_list.dart (2 hints)
  • lib/src/request.dart (2 hints)

Maintenance suggestions

The description is too long. (-10 points)

Search engines display only the first part of the description. Try to keep the value of the description field in your package's pubspec.yaml file between 60 and 180 characters.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.0.0 <3.0.0
logging >=0.11.3 <1.0.0 0.11.4
Dev dependencies
test >=0.12.34 <2.0.0