A dart client for Supabase Realtime server.

Overview

realtime-dart

Listens to changes in a PostgreSQL Database and via websockets.

A dart client for Supabase Realtime server.

pub package pub test

Usage

Creating a Socket connection

You can set up one connection to be used across the whole app.

import 'package:realtime_client/realtime_client.dart';

var client = RealtimeClient(REALTIME_URL);
client.connect();

Socket Hooks

client.onOpen(() => print('Socket opened.'));
client.onClose((event) => print('Socket closed $event'));
client.onError((error) => print('Socket error: $error'));

Disconnect the socket

Call disconnect() on the socket:

client.disconnect()

Credits

License

This repo is licensed under MIT.

Comments
  • Stream Subscriptions die when auth token expires

    Stream Subscriptions die when auth token expires

    We noticed will testing that after some time that our streams were unexpectedly closed. I tested it with a 60 second expiry time on the JWT and received this exception after 60s :

    [sentry.runZonedGuarded] [error] Uncaught zone error
    [sentry.runZonedGuarded] _CastError (type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String?' in type cast)
    [sentry.runZonedGuarded] #0      RealtimeSubscription.onError.<anonymous closure> 		package:realtime_client/src/realtime_subscription.dart:97
    #1      RealtimeSubscription.trigger													package:realtime_client/src/realtime_subscription.dart:221
    #2      RealtimeClient.onConnMessage.<anonymous closure>.<anonymous closure>			package:realtime_client/src/realtime_client.dart:265
    #3      Iterable.forEach (dart:core/iterable.dart:279:35)
    #4      RealtimeClient.onConnMessage.<anonymous closure>								package:realtime_client/src/realtime_client.dart:264
    #5      new RealtimeClient.<anonymous closure>											package:realtime_client/src/realtime_client.dart:86
    #6      RealtimeClient.onConnMessage													package:realtime_client/src/realtime_client.dart:249
    #7      RealtimeClient.connect.<anonymous closure>										package:realtime_client/src/realtime_client.dart:108
    #8      _rootRunUnary (dart:async/zone.dart:1436:47)
    #9      _CustomZone.runUnary (dart:async/zone.dart:1335:19)
    #10     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
    #11     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
    #12     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
    #13     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
    #14     _HandleErrorStream._handleData (dart:async/stream_pipe.dart:253:10)
    #15     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
    #16     _rootRunUnary (dart:async/zone.dart:1436:47)
    #17     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
    #18     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
    #19     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
    #20     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
    #21     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
    #22     _StreamController._add (dart:async/stream_controller.dart:607:7)
    #23     _rootRunUnary (dart:async/zone.dart:1436:47)
    #24     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
    #25     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
    #26     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
    #27     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
    #28     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
    #29     _StreamController._add (dart:async/stream_controller.dart:607:7)
    #30     _StreamController.add (dart:async/stream_controller.dart:554:5)
    #31     new _WebSocketImpl._fromSocket.<anonymous closure> (dart:_http/websocket_impl.dart:1144:21)
    #32     _rootRunUnary (dart:async/zone.dart:1436:47)
    #33     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
    #34     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
    #35     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
    #36     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
    #37     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:63:11)
    #38     _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11)
    #39     _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:332:23)
    #40     _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:226:46)
    #41     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
    #42     _rootRunUnary (dart:async/zone.dart:1436:47)
    #43     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
    #44     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
    #45     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
    #46     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
    #47     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
    #48     _StreamController._add (dart:async/stream_controller.dart:607:7)
    #49     _StreamController.add (dart:async/stream_controller.dart:554:5)
    #50     _Socket._onData (dart:io-patch/socket_patch.dart:2302:41)
    #51     _rootRunUnary (dart:async/zone.dart:1436:47)
    #52     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
    #53     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
    #54     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
    #55     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
    #56     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
    #57     _StreamController._add (dart:async/stream_controller.dart:607:7)
    #58     _StreamController.add (dart:async/stream_controller.dart:554:5)
    #59     _RawSecureSocket._sendReadEvent (dart:io/secure_socket.dart:1000:19)
    #60     _rootRun (dart:async/zone.dart:1420:47)
    #61     _CustomZone.run (dart:async/zone.dart:1328:19)
    #62     _CustomZone.runGuarded (dart:async/zone.dart:1236:7)
    #63     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1276:23)
    #64     _rootRun (dart:async/zone.dart:1428:13)
    #65     _CustomZone.run (dart:async/zone.dart:1328:19)
    #66     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1260:23)
    #67     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
    #68     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:395:19)
    #69     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:426:5)
    #70     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
    

    It might be related to this issue https://github.com/supabase-community/realtime-dart/issues/28

    opened by KirioXX 14
  • Int columns get converted to String on realtime listening (for one row)

    Int columns get converted to String on realtime listening (for one row)

    Bug report

    Describe the bug

    If I get realtime data from my user profile (which is discriminated with the :id=eq.$userId) every column that is an int gets converted to a String in dart

    To Reproduce

    Pretty much said this, just need a table, and listen two only two one row, and all int columns won't be int in dart but a string

    Expected behaviour

    Not have an error with the type conversion

    Screenshots

    If applicable, add screenshots to help explain your problem.

    Additional context

    N/A

    bug 
    opened by bit-burger 8
  • How to connect to Realtime server

    How to connect to Realtime server

    I am trying to use the following code:

    import 'package:realtime_client/realtime_client.dart';
    
    void main() async {
      final socket = RealtimeClient('ws://SUPABASE_API_ENDPOINT/realtime/v1',
          params: {
            'apikey':
                'My API Key'
          },
          // ignore: avoid_print
          logger: (kind, msg, data) => {print('$kind $msg $data')});
    
      final channel = socket.channel('realtime:public'); //:classTest:chatID.eq.2
      channel.on('DELETE', (payload, {ref}) {
        print('channel delete payload: $payload');
      });
      channel.on('INSERT', (payload, {ref}) {
        print('channel insert payload: $payload');
      });
    
      socket.onMessage((message) => print('MESSAGE $message'));
    
      // on connect and subscribe
      socket.connect();
      channel.subscribe().receive('ok', (_) => print('SUBSCRIBED'));
    }
    
    

    But I get the following:

    flutter: transport connected to ws://supabase_api_endpoint/realtime/v1/websocket?apikey=My API Key&vsn=1.0.0 null
    flutter: push realtime:public ChannelEvents.join () {}
    flutter: transport WebSocketChannelException: WebSocketChannelException: SocketException: Failed host lookup: 'supabase_api_endpoint' (OS Error: No such host is known.
    
    , errno = 11001) null
    flutter: channel error realtime:public null
    flutter: transport close 
    

    What RealtimeClient host can I connect to? how to resolve this problem? thanks

    documentation 
    opened by SamuraiHub 8
  • Chore: complete test coverage

    Chore: complete test coverage

    Chore

    Describe the chore

    We need help with completing test coverage for this library. We need to have all test cases as original realtime-js. There are 2 test files:

    • channel_test.dart
    • socket_test.dart

    Additional context

    This lib is based on web_socket_channel to create WebSocket connections. We only use IOWebSocketChannel which wraps dart:io's WebSocket class

    good first issue 
    opened by phamhieu 8
  • feat: update transformers to accept already transformed walrus changes

    feat: update transformers to accept already transformed walrus changes

    What kind of change does this PR introduce?

    Maintains existing output of realtime changes while making it compatible with walrus changes since walrus will pass through, via realtime, the actual values based on data types. For example, instead of delivering '{1, 2, 3}' for _int4 which has to be transformed by clients, realtime is sending [1, 2, 3] to clients. See this PR comment for more context.

    Related https://github.com/supabase/supabase-dart/issues/56 Related https://github.com/supabase/realtime-js/pull/107

    What is the current behavior?

    Transformers are not compatible with walrus changes.

    What is the new behavior?

    Transformers play nicely with walrus changes as well as existing realtime changes.

    Other context

    Also changed the order of transformer tests to match the order of js library.

    opened by dshukertjr 7
  • make compatible with flutter web

    make compatible with flutter web

    What kind of change does this PR introduce?

    This change introduces an indirection in creating the default websocket to allow for web compatibility

    What is the current behavior?

    Web doesn't work unless you create a realtime client directly with the HtmlWebSocketChannel. Web support is missing on pub.dev in both supabase and realtime_client Example error: Socket error: Unsupported operation: Platform._version

    What is the new behavior?

    No new behavior except for the web

    Additional context

    • Dart has conditional imports to separate implementations of web / non-web behavior https://dart.dev/guides/libraries/create-library-packages#conditionally-importing-and-exporting-library-files
    opened by TimWhiting 7
  • fix: don't apply toString() to json

    fix: don't apply toString() to json

    Currently, each column value is turned to String via .toString(), but when this gets applied to a Map/json the corresponding string isn't a valid string presentation of the map. So decoding it again with json.decode() fails. I removed the .toString() call, because it's either a Map or a String. If it's a bool, it gets recognized as such either way later on in toBoolean called in convertCell()

    I see it got already discussed in #30

    opened by Vinzent03 6
  • fix: correct parsing of boolean values

    fix: correct parsing of boolean values

    fix #29

    What kind of change does this PR introduce?

    Bug fix

    What is the current behavior?

    see #29

    What is the new behavior?

    Correct parsing of boolean values.

    opened by HubTreeTea 6
  • Feedback

    Feedback

    Hey, I think you could add a link for supabase-dart and postgres-dart as they are related and anyone falling into this page might not know they exist.

    Also, I just want to do a Firestore.stream. Is that possible? It could mention how to achieve this (or if it is not possible) for users coming from it to have the right expectations.

    documentation 
    opened by bernaferrari 6
  • chore: Added 9 tests to socket_test.dart

    chore: Added 9 tests to socket_test.dart

    What kind of change does this PR introduce?

    Adds test to socket_test.dart

    Tests added:

    • disconnect

      • calls connection close callback
      • does not throw when no connection
    • channel

      • returns channel with given topic and params
      • adds channel to sockets channels list
    • remove

      • removes given channel from channels
    • push

      • sends data to connection when connected
      • buffers data when not connected
    • makeRef

      • returns next message ref
      • restarts for overflow
    opened by hardiksachan 6
  • fix: rename Callback typedef to BindingCallback

    fix: rename Callback typedef to BindingCallback

    What kind of change does this PR introduce?

    Feature

    What is the current behavior?

    Relates to https://github.com/supabase/supabase-dart/issues/46

    What is the new behavior?

    Renamed Callback to SupabaseEventCallback

    Additional context

    n/a

    opened by chimon2000 4
Owner
Supabase Community
Supabase Community
News App created in Flutter using News API for fetching realtime data and Firebase as the backend and authenticator.

News Buzz News App created in Flutter using News API for fetching realtime data and Firebase as the backend and authenticator. Features Custom news fe

Ankur Kedia 545 Dec 30, 2022
Fully functional Twitter clone built in flutter framework using Firebase realtime database and storage

Fwitter - Twitter clone in flutter A working Twitter clone written in Flutter using Firebase auth,realtime,firestore database and storage. Download Ap

Sonu Sharma 2.4k Jan 8, 2023
:rocket: This application using flutter for develop a realtime chat app

Flutter Chat Socket Description: ?? This application using Flutter for develop a realtime chat app How I can run it? ?? Clone this repository ?? Run b

Dao Hong Vinh 17 Dec 31, 2022
Realtime Chat with Flutter

What is Konnect? Konnect is a messaging app for simple private communication with friends. Say "hello" to a different messaging experience. An unexpec

Yunus Emre Alpu 7 Dec 13, 2022
Realtime Fleet Management

FLEET Realtime Fleet Management Warning These apps were built for demo purposes only. Features Mobile app that sends live location via websockets. Mob

Morteza 3 Nov 30, 2022
Weather-App-Api- - Simple Realtime Weather App With Api

music_app A new Flutter Weather App project. Getting Started // اول حاجه تعمل en

Youssif El Sayed 5 Nov 11, 2022
Flutter SDK for building a realtime broadcaster using the Millicast platform

Flutter SDK for building a realtime broadcaster using the Millicast platform. This Software Development Kit (SDK) for Flutter allows developers to simplify Millicast services integration into their own Android and iOS apps.

Millicast, Inc. 9 Oct 29, 2022
server side dart micro-framework to handle incoming http requests

Queen Palace ???? Introduction server side dart micro-framework to handle incoming http requests

Ahmed Masoud 32 Aug 30, 2022
An expressive, functional, and full-featured server-side framework for Dart.

A framework and collection of packages for writing http servers, built on top of the shelf package. This framework is intended to reduce the technical

Marathon 45 Jun 25, 2022
This project is a implementation of a collection of terminal server samples in Dart

Terminal Server Samples ⭐ Star me on GitHub — it helps! This project is a implementation of a collection of terminal server samples in Dart licensed u

Javier Montenegro 0 Nov 26, 2021
Dart HTTP server framework for building REST APIs. Includes PostgreSQL ORM and OAuth2 provider.

Aqueduct is a modern Dart HTTP server framework. The framework is composed of libraries for handling and routing HTTP requests, object-relational mapp

Stable Kernel 2.4k Jan 5, 2023
Dart API to speak to a moderator server

Interzone is the dart API to talk with moderator, a tiny ephemeral forum basic blocks: world.dart, a world scaffold each world you can think of as one

null 8 Jan 17, 2022
Dart GraphQL server implementation. Utilities, code generator, examples and reference implementation.

Leto - GraphQL Server A complete implementation of the official GraphQL specification in the Dart programming language. Inspired by graphql-js, async-

Juan Manuel Castillo 29 Nov 27, 2022
Simple examples that help you get started with Appwrite + Dart (=❤️) as an Appwrite server-side integration.

Playground for Dart Simple examples that help you get started with Appwrite + Dart (= ❤️ ) This is Appwrite server side integration with Dart. For Flu

Appwrite 31 Nov 22, 2022
Nakama is an open-source server designed to power modern games and apps

Nakama is an open-source server designed to power modern games and apps. Features include user accounts, chat, social, matchmaker, realtime multiplayer, and much more.

Allan Nava 85 Dec 30, 2022
Rokeet UI - A Server Driven UI Framework

Rokeet UI A Server-Driven UI framework. Status Lib Build Coverage Core Configure Mockoon server Install Mockoon: Mac OSX brew install --cask mockoon

osodroid 6 Apr 7, 2022
GetDoctor is a complete app developed in Flutter, Firebase and Blazor,.Net Core API and SQL Server

GetDoctor ?? ?? ?? GetDoctor is a complete app developed in Flutter, Firebase and Blazor,DotNet Core API and SQL Server GetDoctor is a complete packag

Sunil Vijayan 69 Dec 19, 2022
A Flutter server rendering framework

Shark Flutter ?? (Under Construction) A Flutter server rendering framework After i finish the project structure, I would draw a project diagram and de

Vau 62 Dec 29, 2022
A complete grocery store developed with Flutter, .Net Core, Firebase, One Signal and SQL Server as backend

# Grocery-Store developed in Flutter,DotNet Core, Firebase, One-Signal, SQL-Server, Stripe, Razorpay, Paypal A complete grocery store developed with F

Sunil Vijayan 31 Jan 1, 2023