Listens to changes in a PostgreSQL Database and via websockets.

Overview

realtime-swift

Listens to changes in a PostgreSQL Database and via websockets.

A Swift client for Supabase Realtime server.

Usage

Creating a Socket connection

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

import Realtime

var client = RealtimeClient(endPoint: "https://yourcompany.supabase.co/realtime/v1", params: ["apikey": "public-anon-key"])
client.connect()

Socket Hooks

socket.onOpen { 
    print("Socket opened.")
}

socket.onError { error in
    print("Socket error: ", error.localizedDescription)
}

socket.onClose {
    print("Socket closed")
}

Disconnect the socket

Call disconnect() on the socket:

client.disconnect()

Credits

License

This repo is licensed under MIT.

Comments
  • Remove Starscream Dependency and bump minimum support platform

    Remove Starscream Dependency and bump minimum support platform

    This PR bumps the minimum supported platforms to:

      platforms: [
        .macOS(.v10_15),
        .iOS(.v13),
        .watchOS(.v6),
        .tvOS(.v13),
      ],
    

    That make's it possible to remove the Starscream dependency.

    opened by grsouza 3
  • StarScream Dependency prevents importing into Swift Playgrounds 4

    StarScream Dependency prevents importing into Swift Playgrounds 4

    This is definitely an edge case, but something I think that is important.

    The realtime-swift package cannot be imported into Swift Playgrounds 4 because of the dependency on StarScream. realtime-swift can already run with StarScream removed since an implementation of the Transport protocol using standard iOS libraries exists. Please see my fork for a working repo that can import into Swift Playgrounds 4: https://github.com/YeomansIII/realtime-swift

    Through my research, these Supabase Swift libraries (postgrest-swift, storage-swift, gotrue-swift) are some of the only 100% Swift packages that can actually be imported into Swift Playgrounds 4, which allows developers to create iOS apps directly on iPadOS without a Mac computer. This was important for me, because I was looking for a no-code backend like Firebase to use for my iOS app I am developing in Swift Playgrounds 4. Firebase and numerous other similar platforms were not able to be imported into Swift Playgrounds 4 because the packages contain Objective-C or other incompatible code/settings.

    While I know that removing the StarScream dependency allows importing into Swift Playgrounds 4, I do not know if this is an actual solution or what the potential solution might be to get the main realtime-swift repo working with Swift Playgrounds.

    So I would like to open up that discussion here.

    opened by YeomansIII 2
  • Issue With Channel + Schema

    Issue With Channel + Schema

    I love the project

    Im running into a when setting up a channel listener on a table with public schema.

    Currently, I can only receive data from my supabase DB if I'm using realtime:*, but whenever set a specific table with the schema set public:

    channel(.table("Media", schema: "public"))

    the listener returns no data and after the socket opens, it emits a Close Event shortly after. I made sure all of my tables were public and also replicated as per the requirements for real-time setup.

    Screen Shot 2022-01-14 at 2 24 17 PM

    Thanks you for the help!

    opened by lmick002 2
  • realtime doesn't seem to work with with xcframeworks.

    realtime doesn't seem to work with with xcframeworks.

    not sure if it's a side effect of CLib change from swift-nio

    sample app here https://github.com/wweevv-johndpope/DemoBazel/tree/gotrue-swift

    table is simple structure

        struct TestClass: Codable {
            var id: Int?
        }
    
    
    Screen Shot 2022-09-06 at 6 54 51 am

    I'm definitely on the right instance. pqxcxltwoifmxcmhghzf

    client connects successfully - I attempt to move subscription into the onOpen block - but no joy.

    
    
       let rt = RealtimeClient(endPoint: "https://pqxcxltwoifmxcmhghzf.supabase.co/realtime/v1", params: ["apikey": supabaseKey])
            rt.connect()
            rt.onOpen {
               
                let allUsersUpdateChanges =  rt.channel(.all)//rt.channel(.table("test", schema: "public"))
                allUsersUpdateChanges.on(.all) { message in
                    print(message)
                }
                allUsersUpdateChanges.subscribe()
            }
            self.realtimeClient = rt
    
    
    opened by wweevv-johndpope 1
  • Starscream dependency on zlib

    Starscream dependency on zlib

    https://github.com/daltoniam/Starscream/pull/844

    this prevents xcframeworks being spat out https://github.com/supabase-community/supabase-swift/issues/38

    opened by johndpope 1
  • Connection Issue

    Connection Issue

    Hello,

    I might be doing something totally off but having a hard time connecting to the server. I am getting an error of "Could not connect to the server."

    Heres what I am trying:

    var client = RealtimeClient(endPoint: "https://pkx....supabase.co/realtime/v1", params: ["apikey": "eyJhb..."])
    

    A few questions.

    1. Should use https and not wss in the url?
    2. Should the url end in supabase.io or supabase.co?
    opened by drewg233 1
  • Swiftification of the API

    Swiftification of the API

    Apply the usual Swift pattern to the API: Event and Topic are now proper Swift Enum. Limit the current implementation to the effectively supported features. Extend the tests to ensure the patterns are right. Add the subscription part to the README for ease of introduction to the framework.

    opened by mbarnach 1
  • Import FoundationNetworking if needed.

    Import FoundationNetworking if needed.

    Add FoundationNetworking if available. This is allowing Linux platforms to compile the framework, since the migration of URL-related function to the FoundationNetworking framework.

    opened by mbarnach 0
  • Fix ChannelTopic init from string and add unit tests

    Fix ChannelTopic init from string and add unit tests

    I created this PR in favor of #4 . Thanks @lmick002 for addressing it, I've just added a few minor things on top of it, such as:

    1. Refactoring ChannelTopic type for using RawRepresentable.
    2. Add unit tests for testing the ChannelTopic init from the rawValue string.

    Fixes #3

    opened by grsouza 0
  • Fix availability check

    Fix availability check

    What kind of change does this PR introduce?

    Fix availability check for URLSessionTransport.

    What is the current behavior?

    The current availability check consider only macOS versions.

    What is the new behavior?

    Availability check now consider macOS, iOS, tvOS and watchOS versions.

    opened by grsouza 0
Releases(0.0.2)
  • 0.0.2(Oct 6, 2022)

    What's Changed

    • Import FoundationNetworking if needed. by @mbarnach in https://github.com/supabase-community/realtime-swift/pull/7
    • Remove Starscream Dependency and bump minimum support platform by @grsouza in https://github.com/supabase-community/realtime-swift/pull/11

    Full Changelog: https://github.com/supabase-community/realtime-swift/compare/0.0.1...0.0.2

    Source code(tar.gz)
    Source code(zip)
  • 0.0.1(Feb 22, 2022)

    What's Changed

    • Fix availability check by @grsouza in https://github.com/supabase-community/realtime-swift/pull/1
    • Swiftification of the API by @mbarnach in https://github.com/supabase-community/realtime-swift/pull/2
    • Fix ChannelTopic init from string and add unit tests by @grsouza in https://github.com/supabase-community/realtime-swift/pull/5

    New Contributors

    • @grsouza made their first contribution in https://github.com/supabase-community/realtime-swift/pull/1
    • @mbarnach made their first contribution in https://github.com/supabase-community/realtime-swift/pull/2

    Full Changelog: https://github.com/supabase-community/realtime-swift/commits/0.0.1

    Source code(tar.gz)
    Source code(zip)
Owner
Supabase
Supabase
A stand-alone Swift wrapper around the libpq client library, enabling access to PostgreSQL servers.

Perfect - PostgreSQL Connector This project provides a Swift wrapper around the libpq client library, enabling access to PostgreSQL servers. This pack

PerfectlySoft Inc. 51 Nov 19, 2022
A PostgreSQL client library for Swift. Does not require libpq.

PostgresClientKit PostgresClientKit provides a friendly Swift API for operating against a PostgreSQL database. Features Doesn't require libpq. Postgre

codewins.com 107 Dec 1, 2022
This Project domonstrate the latest Swift on Server to create RESTFul API's connected via Database: MongoDB NoSql

Swift is a general-purpose programming language built using a modern approach to safety & performance that make it specifically suitable for Server applications. Vapor is a web framework for Swift, allowing you to write backends, web apps APIs and HTTP servers in Swift

Furqan 3 Aug 23, 2022
Which contacts changed outside your iOS app? Better CNContactStoreDidChange notification: get real changes, without the noise.

ContactsChangeNotifier Which contacts changed outside your iOS app? Better CNContactStoreDidChange notification: Get real changes, without the noise.

Yonat Sharon 5 Oct 31, 2022
Safe and easy wrappers for common Firebase Realtime Database functions.

FirebaseHelper FirebaseHelper is a small wrapper over Firebase's realtime database, providing streamlined methods for get, set, delete, and increment

Quan Vo 15 Apr 9, 2022
CodableCloudKit allows you to easily save and retrieve Codable objects to iCloud Database (CloudKit)

CodableCloudKit CodableCloudKit allows you to easily save and retrieve Codable objects to iCloud Database (CloudKit) Features ℹ️ Add CodableCloudKit f

Laurent Grondin 65 Oct 23, 2022
Realm is a mobile database: a replacement for Core Data & SQLite

Realm is a mobile database that runs directly inside phones, tablets or wearables. This repository holds the source code for the iOS, macOS, tvOS & wa

Realm 15.7k Jan 1, 2023
WCDB is a cross-platform database framework developed by WeChat.

WCDB 中文版本请参看这里 WCDB is an efficient, complete, easy-to-use mobile database framework used in the WeChat application. It's currently available on iOS,

Tencent 9.6k Jan 8, 2023
Sync Realm Database with CloudKit

IceCream helps you sync Realm Database with CloudKit. It works like magic! Features Realm Database Off-line First Thread Safety Reactive Programming O

Soledad 1.8k Jan 6, 2023
Movies Information DataBase (Add - Delete - Edit - Search)

MoviesInformation Movies Information DataBase (Add - Delete - Edit - Search) This Code Provide Simple Program About Movies Information This Program Ca

Mohammad Jaha 2 Sep 15, 2021
Easy direct access to your database 🎯

OHMySQL ★★ Every star is appreciated! ★★ The library supports Objective-C and Swift, iOS and macOS. You can connect to your remote MySQL database usin

Oleg 210 Dec 28, 2022
A Generic CoreData Manager to accept any type of objects. Fastest way for adding a Database to your project.

QuickDB FileManager + CoreData ❗️ Save and Retrieve any thing in JUST ONE line of code ❗️ Fast usage dataBase to avoid struggling with dataBase comple

Behrad Kazemi 17 Sep 24, 2022
A simple order manager, created in order to try Realm database

Overview A simple order manager, created in order to get acquainted with the features and limitations of the local Realm database. The project is writ

Kirill Sidorov 0 Oct 14, 2021
A sample application showcasing Vapor 4 connecting to an Oracle database using SwiftOracle package.

vapor-oracle A sample application showcasing Vapor 4 connecting to an Oracle database using SwiftOracle package. In this Vapor application, we create

Ilia Sazonov 3 Sep 22, 2022
A property wrapper for displaying up-to-date database content in SwiftUI views

@Query Latest release: November 25, 2021 • version 0.1.0 • CHANGELOG Requirements: iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+ • Swift 5.5+ /

Gwendal Roué 102 Dec 29, 2022
A food delivery app using firebase as the database.

FDA-ONE Food Delivery Application is a mobile application that users can use to find the best restaurant around their location and order the meals the

Naseem Oyebola 0 Nov 28, 2021
BucketServer - Small API with SQLite database that saves notes for an iOS appliction called Bucket list

BucketList Server-Side Small API with SQLite database that saves notes for an iO

null 0 Dec 30, 2021
Innova CatchKennyGame - The Image Tap Fun Game with keep your scores using Core Database

Innova_CatchKennyGame The Image Tap Fun Game with keep your scores using Core Da

Alican Kurt 0 Dec 31, 2021
Synco - Synco uses Firebase's Realtime Database to synchronize data across multiple devices, in real time

Synco Synco uses Firebase's Realtime Database to synchronize a color across mult

Alessio 0 Feb 7, 2022