phoenix_socket 0.2.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

phoenix_socket #

Dart library to interact with Phoenix Channels (Presence coming up next) over WebSockets.

This library uses web_socket_channel for WebSockets, making the API consistent across web and native environments.

Getting Started #

Look at the example project for an example on how to use this library. The API was designed to look like javascript's as much as possible, but leveraging Dart's unique native advantages like Streams and Futures.

The documentation is in a poor state for now, but it will improve soon enough.

[0.2.4] #

  • Fix a couple of bugs around failing states

[0.2.3] #

  • Fix duplicate message sending/completing in some race conditions

[0.2.2] #

  • Make logging more configurable
  • Fix auto-rejoin of channels

[0.2.1] #

  • Add much more logging using the logging library
  • Fix a couple of minor bugs

[0.2.0] #

  • Fix some statement management issues
  • Clean up classes file location
  • Improve API to be more consistent with behavior

[0.1.1] #

  • Add some very incomplete docs

[0.1.0] #

  • First version that feel really stable
  • Presence still largely untested


import 'dart:async';

import 'package:phoenix_socket/phoenix_socket.dart';
import 'package:uuid/uuid.dart';

void main() async {
  final socket1 = PhoenixSocket('ws://localhost:4000/socket/websocket');
  await socket1.connect();
  var channel1 = socket1.addChannel(topic: 'channel3');
  await channel1.join().future;
  var uuid = Uuid().v4();

  channel1.push('ping', {'from': uuid});

  await for (var message in channel1.messages) {
    if (message.event != 'pong' || message.payload['from'] == uuid) continue;
    print("received ${message.event} from ${message.payload['from']}");
    Timer(Duration(seconds: 1), () {
      channel1.push('ping', {'from': uuid});

Use this package as a library

1. Depend on it

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

  phoenix_socket: ^0.2.4

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:phoenix_socket/phoenix_socket.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 Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
equatable ^1.1.0 1.1.1
logging ^0.11.4 0.11.4
meta ^1.1.8 1.1.8
pedantic ^1.8.0 1.9.0
quiver ^2.0.0 2.1.3
rxdart ^0.23.1 0.23.1 0.24.0-dev.1
web_socket_channel ^1.1.0 1.1.0
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
matcher 0.12.6
path 1.6.4
stack_trace 1.9.3
stream_channel 2.0.0
typed_data 1.1.6
Dev dependencies
test ^1.11.1