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

refactor: Realtime V2 #214

Merged
merged 37 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0d7b5f5
feat: add EventType to Realtime Message
grdsdev Dec 23, 2023
4d679ca
refactor: rename Message to RealtimeMessage
grdsdev Dec 23, 2023
05881ef
feat: add callback manager
grdsdev Dec 26, 2023
e55ec98
feat: implement onMessage handler
grdsdev Dec 26, 2023
20f19de
refactor realtime based on Kotlin library
grdsdev Dec 26, 2023
2ee1cea
wip
grdsdev Dec 28, 2023
53ea649
Fix Realtime connection
grdsdev Dec 29, 2023
acf51e5
Add Sendable conformances and make classes thread safe
grdsdev Dec 29, 2023
53990eb
Rename v2 types
grdsdev Dec 29, 2023
1ec731e
Fix Realtime tests
grdsdev Dec 29, 2023
f6e01c7
Fix leaks
grdsdev Dec 29, 2023
3894eb9
add _Presence type
grdsdev Dec 29, 2023
927c08b
block task until subscribed
grdsdev Dec 29, 2023
aa47880
wip
grdsdev Jan 4, 2024
f26b4b2
Make Realtime and Channel Actors
grdsdev Jan 4, 2024
47a64dc
wip slack clone example
grdsdev Jan 4, 2024
e71454c
Fix tests
grdsdev Jan 4, 2024
37b9d7c
Rename Realtime to RealtimeClientV2
grdsdev Jan 4, 2024
074479a
fix: pending heartbeat check
grdsdev Jan 5, 2024
33a484d
Remove AuthTokenProvider
grdsdev Jan 8, 2024
591b4b4
wip
grdsdev Jan 11, 2024
b875aea
Remove Combine
grdsdev Jan 12, 2024
a84be22
Remove OSLog as it doesn't support non-Apple platform
grdsdev Jan 12, 2024
e344c6f
Import FoundationNetworking
grdsdev Jan 12, 2024
48ee07e
Integrate SupabaseLogger
grdsdev Jan 17, 2024
b35f189
Fix Realtime access token and improve slack clone example
grdsdev Jan 18, 2024
5fecab5
wip
grdsdev Jan 18, 2024
f265109
Test
grdsdev Jan 18, 2024
0834b76
test: realtime connect and subscribe
grdsdev Jan 20, 2024
e7d446a
Import Dispatch
grdsdev Jan 20, 2024
5cb7ce4
Remove NSEC_PER_SEC since non-Darwin don't have it
grdsdev Jan 20, 2024
109e862
Trying to fix build on Linux
grdsdev Jan 20, 2024
08c3f18
ci: use Xcode 15.2
grdsdev Jan 20, 2024
c2d1db0
Comment out failing test
grdsdev Jan 21, 2024
3a6bd65
Add local supabase instance for SlackClone
grdsdev Jan 21, 2024
fcf3ed8
Add visionOS support for SlackClone example
grdsdev Jan 21, 2024
2d523f0
Add migration guide
grdsdev Jan 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Use an official Swift runtime as a base image
FROM swift:latest

# Set the working directory to /app
WORKDIR /app

# Copy the entire content of the local directory to the container
COPY . .

# Build the Swift package
RUN swift build

# Run tests
CMD ["swift", "test"]

372 changes: 212 additions & 160 deletions Examples/Examples.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "79D884C62B3C18830009EA4A"
BuildableName = "SlackClone.app"
BlueprintName = "SlackClone"
ReferencedContainer = "container:Examples.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "79D884C62B3C18830009EA4A"
BuildableName = "SlackClone.app"
BlueprintName = "SlackClone"
ReferencedContainer = "container:Examples.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "79D884C62B3C18830009EA4A"
BuildableName = "SlackClone.app"
BlueprintName = "SlackClone"
ReferencedContainer = "container:Examples.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
127 changes: 0 additions & 127 deletions Examples/RealtimeSample/ContentView.swift

This file was deleted.

27 changes: 0 additions & 27 deletions Examples/RealtimeSample/RealtimeSampleApp.swift

This file was deleted.

55 changes: 55 additions & 0 deletions Examples/SlackClone/AppView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// AppView.swift
// SlackClone
//
// Created by Guilherme Souza on 27/12/23.
//

import Supabase
import SwiftUI

@Observable
@MainActor
final class AppViewModel {
var session: Session?
var selectedChannel: Channel?

init() {
Task { [weak self] in
for await (event, session) in await supabase.auth.authStateChanges {
guard [.signedIn, .signedOut, .initialSession].contains(event) else { return }
self?.session = session

if session == nil {
for subscription in await supabase.realtimeV2.subscriptions.values {
await subscription.unsubscribe()
}
}
}
}
}
}

@MainActor
struct AppView: View {
@Bindable var model: AppViewModel

@ViewBuilder
var body: some View {
if model.session != nil {
NavigationSplitView {
ChannelListView(channel: $model.selectedChannel)
} detail: {
if let channel = model.selectedChannel {
MessagesView(channel: channel).id(channel.id)
}
}
} else {
AuthView()
}
}
}

#Preview {
AppView(model: AppViewModel())
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"idiom" : "mac",
"scale" : "1x",
Expand Down
68 changes: 68 additions & 0 deletions Examples/SlackClone/AuthView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// AuthView.swift
// SlackClone
//
// Created by Guilherme Souza on 27/12/23.
//

import SwiftUI

@Observable
@MainActor
final class AuthViewModel {
var email = ""
var toast: ToastState?

func signInButtonTapped() {
Task {
do {
try await supabase.auth.signInWithOTP(
email: email,
redirectTo: URL(string: "slackclone://sign-in")
)
toast = ToastState(status: .success, title: "Check your inbox.")
} catch {
toast = ToastState(status: .error, title: "Error", description: error.localizedDescription)
}
}
}

func handle(_ url: URL) {
Task {
do {
try await supabase.auth.session(from: url)
} catch {
toast = ToastState(status: .error, title: "Error", description: error.localizedDescription)
}
}
}
}

@MainActor
struct AuthView: View {
@Bindable var model = AuthViewModel()

var body: some View {
VStack {
VStack {
TextField("Email", text: $model.email)
#if os(iOS)
.textInputAutocapitalization(.never)
.keyboardType(.emailAddress)
#endif
.textContentType(.emailAddress)
.autocorrectionDisabled()
}
Button("Sign in with Magic Link") {
model.signInButtonTapped()
}
}
.padding()
.toast(state: $model.toast)
.onOpenURL { model.handle($0) }
}
}

#Preview {
AuthView()
}
Loading