Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update from upstream SwiftPhoenixClient #21

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

grdsdev
Copy link
Contributor

@grdsdev grdsdev commented Jul 24, 2023

What kind of change does this PR introduce?

Bug fix, feature, docs update, ...

What is the current behavior?

Please link any relevant issues here.

What is the new behavior?

Feel free to include screenshots if it includes visual changes.

Additional context

Add any other context or screenshots.

@foodisbeast
Copy link

Looks great, could use this now! Any idea on when this will be merged / released?

@foodisbeast
Copy link

foodisbeast commented Aug 1, 2023

I tried using this version in my project, but the latest version of supabase-swift has different initializers for RealtimeClient. I was able to enable usage by editing the initializers ( #22 ).

@grdsdev grdsdev marked this pull request as ready for review August 1, 2023 08:20
…initializers (#22)

* remove endpoint parameter name underscore prefix

* Revert "remove endpoint parameter name underscore prefix"

This reverts commit 478c72e.

* add deprecated initializer to RealtimeClient for compatibility

* Revert "add deprecated initializer to RealtimeClient for compatibility"

This reverts commit 6061152.

* add deprecated initializer to RealtimeClient for compatibility with supabase-swift 0.3.0
…ata (#23)

* fix fatal error passing in non supported types to JSONSerialization.data(withJsonObject:...)

* add assertion for valid JSON object to encode function
@foodisbeast
Copy link

foodisbeast commented Aug 1, 2023

Currently using latest from update-upstream with realtime Presence in my project. However could only get it working when adding custom channel params that matches RealtimeChannelOptions type from supabase-js (See RealtimeChannelOptions in supabase-js master).

export type RealtimeChannelOptions = {
  config: {
    /**
     * self option enables client to receive message it broadcast
     * ack option instructs server to acknowledge that broadcast message was received
     */
    broadcast?: { self?: boolean; ack?: boolean }
    /**
     * key option is used to track presence payload across clients
     */
    presence?: { key?: string }
  }
}

Wondering if there should be some additional config type, automatic payload injection in Presence, or I should just add docs @GRSouza?

let client = supabase.realtime
let params = [
    "config": [
        "presence": [
            "key": profile.id
        ],
        "broadcast": [
//          "ack": true
            "self": true
        ]
    ]
]
// let channel = client.channel(.table(id, schema: "someChannel") - presence.onSync will never call
let channel = client.channel(.table(id, schema: "someChannel"), params: params) // This works fine
let presence = Presence(channel: channel)
presence.onSync {
    // Only calls if params are passed into channel
}
client.connect()
channel.join()

@grdsdev
Copy link
Contributor Author

grdsdev commented Aug 1, 2023

@foodisbeast realtime-js automatically inject params as you can see on https://github.com/supabase/realtime-js/blob/master/src/RealtimeChannel.ts#L136-L142

I think we should use the same approach and also add documentation

@foodisbeast
Copy link

foodisbeast commented Aug 1, 2023

What do you think about adding a string initializer to ChannelEvent @GRSouza? Seems having a finite set of events will prevent listening/sending Presence track and untrack (Presence docs), and broadcast events (Broadcast docs).

@grdsdev
Copy link
Contributor Author

grdsdev commented Aug 2, 2023

If we can't know all the possible events then it's fine to add a string initializer @foodisbeast

foodisbeast and others added 6 commits August 2, 2023 11:56
* add ChannelOptions type and initializer

* add default options to channel creation function

* Add Presence sync docs

* Update initializer parameter spacing in Sources/Realtime/Channel.swift

Co-authored-by: Guilherme Souza <[email protected]>

---------

Co-authored-by: Guilherme Souza <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants