패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.0.2

phoenix_wings

Dart용 Phoenix Channel 클라이언트

AndroidiOSmacOSWindowsLinux
30일 다운로드
478
좋아요
13
Pub 점수
115

패키지 설치

flutter pub add phoenix_wings

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Phoenix Wings는 Flutter 애플리케이션에서 실시간 통신을 가능하게 하는 Dart 클라이언트입니다. Phoenix 서버에 연결하고 채널을 관리하며 실시간 이벤트를 수신할 수 있는 깔끔하고 반응형 인터페이스를 제공합니다. Flutter의 상태 관리와 원활한 통합을 위해 설계되었으며, 메시지 브로드캐스트, 존재 추적 및 강력한 재연결 로직을 지원합니다. 채팅 앱, 실시간 대시보드 및 낮은 지연 시간 업데이트가 필요한 협업 도구 개발에 적합합니다.

사용 사례

  • 실시간 채팅 애플리케이션
  • 실시간 데이터 대시보드
  • 협업 편집 도구
  • 존재 감지
  • 이벤트 기반 UI 업데이트

주요 기능

  • 반응형 채널 구독
  • 자동 재연결
  • 메시지 브로드캐스트
  • 존재 추적
  • Clean Dart API

적합한 대상

  • 실시간 기능을 구축하는 Flutter 개발자
  • 양방향 통신이 필요한 앱
  • Phoenix Server 백엔드를 사용하는 프로젝트

고려 사항

  • Phoenix Server 인스턴스가 필요합니다
  • WebSocket 기반 통신에 제한됨
  • 예외적인 경우를 처리하기 위해 추가적인 오류 처리가 필요할 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Pub

phoenix_wings.dart

A Phoenix Channel implementation for Dart

Attempts to feature match the Javascript implementation found at phoenix.js

Usage

API Documentation

Much of the library is the same whether your code is running in the VM/Flutter or in a browser. Due to differences between the two platforms, the connection setup differs slightly.

Import & Connection (VM/Flutter)
import 'package:phoenix_wings/phoenix_wings.dart';


final socket = new PhoenixSocket("ws://localhost:4000/socket/websocket");

// equivalent to passing connectionProvider: PhoenixIoConnection.provider

// you can also pass params on connection if you for example want to authenticate using a user token like
final socket = PhoenixSocket("ws://localhost:4000/socket/websocket", socketOptions: PhoenixSocketOptions(params: {"user_token":  'user token here'}, ));

Options that can be passed on connection include :-

  • timeout - How long to wait for a response in miliseconds. Default 10000
  • heartbeatIntervalMs - How many milliseconds between heartbeats. Default 30000
  • reconnectAfterMs - Optional list of milliseconds between reconnect attempts
  • params - Parameters sent to your Phoenix backend on connection.
Import & Connection (HTML)
import 'package:phoenix_wings/html.dart';


final socket = new PhoenixSocket("ws://localhost:4000/socket/websocket", connectionProvider: PhoenixHtmlConnection.provider);

Common Usage
await socket.connect();

final chatChannel = socket.channel("room:chat", {"id": "myId"});

chatChannel.on("user_entered", PhoenixMessageCallback (Map payload, String _ref, String, _joinRef) {
    print(payload);
});

chatChannel.join();
Examples

Mobile - when running the flutter example in your emulator, with the server also running in the same computer host, remember that the emulator is running in a segregated VM, so you need to configure it to point your server that is running on the host machine.


# check your IP configuration
$ ifconfig
enp0s20u5c4i2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 10.0.0.2  netmask 255.255.255.240  broadcast 172.20.10.15
  1. After checking your IP, go to your flutter Settings -> Proxy, and add the proxy host configuration with your IP, and port where your phoenix server with the websockets is listening.

  2. Configure your flutter app to point to your phoenix websocket server.

final socket = PhoenixSocket("ws://10.0.0.2:4000/socket/websocket");

See here for an illustrated example.

Server - phoenix server with a channel that will communicate with the flutter app above.

Console - if you want to debug the websockets direclty, without phoenix_wings, using the phoenix protocol. See here for more info about the json protocol. You will have a lot of fun, connecting, and seeing the loop in this console app sending messages to your flutter app. To run, simply:

dart console.dart

Testing

Most of the tests are run on the VM. However, the PhoenixHtmlConnection tests must run in a browser.

By default tests will run on VM, Chrome and Firefox. This is set in dart_test.yaml

Tests are run via pub run test

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.