phoenix_socket 0.7.4 copy "phoenix_socket: ^0.7.4" to clipboard
phoenix_socket: ^0.7.4 copied to clipboard

PhoenixSocket provides a feature-complete implementation of Phoenix Sockets, using a single API based on StreamChannels compatible with any deployment of Flutter.

example/lib/main.dart

import 'dart:async';

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

void main() async {
  final socket1 = PhoenixSocket('ws://localhost:4001/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 != PhoenixChannelEvent.custom('pong') ||
        message.payload?['from'] == uuid) continue;
    print("received ${message.event} from ${message.payload!['from']}");
    Timer(const Duration(seconds: 1), () {
      channel1.push('ping', {'from': uuid});
    });
  }
}
49
likes
140
pub points
87%
popularity

Publisher

verified publisherbraver.health

PhoenixSocket provides a feature-complete implementation of Phoenix Sockets, using a single API based on StreamChannels compatible with any deployment of Flutter.

Repository

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

logging, rxdart, web_socket_channel

More

Packages that depend on phoenix_socket