Skip to content

Commit

Permalink
fix: revert new Realtime API featuring Broadcast and Presence
Browse files Browse the repository at this point in the history
  • Loading branch information
w3b6x9 committed Aug 3, 2022
1 parent 03072d1 commit e155e65
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 47 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -40,7 +40,7 @@
"@supabase/functions-js": "^1.3.4",
"@supabase/gotrue-js": "^1.22.17",
"@supabase/postgrest-js": "^0.37.4",
"@supabase/realtime-js": "^1.7.2",
"@supabase/realtime-js": "^1.7.4",
"@supabase/storage-js": "^1.7.2"
},
"devDependencies": {
Expand Down
42 changes: 3 additions & 39 deletions src/SupabaseClient.ts
Expand Up @@ -7,12 +7,7 @@ import { SupabaseStorageClient } from '@supabase/storage-js'
import { FunctionsClient } from '@supabase/functions-js'
import { PostgrestClient } from '@supabase/postgrest-js'
import { AuthChangeEvent } from '@supabase/gotrue-js'
import {
RealtimeClient,
RealtimeSubscription,
RealtimeClientOptions,
RealtimeChannel,
} from '@supabase/realtime-js'
import { RealtimeClient, RealtimeSubscription, RealtimeClientOptions } from '@supabase/realtime-js'

const DEFAULT_OPTIONS = {
schema: 'public',
Expand Down Expand Up @@ -160,20 +155,6 @@ export default class SupabaseClient {
return rest.rpc<T>(fn, params, { head, count })
}

/**
* Creates a channel with Broadcast and Presence.
* Activated when vsndate query param is present in the WebSocket URL.
*/
channel(name: string, opts: { selfBroadcast: boolean; [key: string]: any }): RealtimeChannel {
const userToken = this.auth.session()?.access_token ?? this.supabaseKey

if (!this.realtime.isConnected()) {
this.realtime.connect()
}

return this.realtime.channel(name, { ...opts, user_token: userToken }) as RealtimeChannel
}

/**
* Closes and removes all subscriptions and returns a list of removed
* subscriptions and their errors.
Expand All @@ -193,23 +174,6 @@ export default class SupabaseClient {
})
}

/**
* Closes and removes a channel and returns the number of open channels.
*
* @param channel The channel you want to close and remove.
*/
async removeChannel(
channel: RealtimeChannel
): Promise<{ data: { openChannels: number }; error: Error | null }> {
const { error } = await this._closeSubscription(channel)
const allChans: RealtimeSubscription[] = this.getSubscriptions()
const openChanCount = allChans.filter((chan) => chan.isJoined()).length

if (allChans.length === 0) await this.realtime.disconnect()

return { data: { openChannels: openChanCount }, error }
}

/**
* Closes and removes a subscription and returns the number of open subscriptions.
*
Expand All @@ -228,7 +192,7 @@ export default class SupabaseClient {
}

private async _closeSubscription(
subscription: RealtimeSubscription | RealtimeChannel
subscription: RealtimeSubscription
): Promise<{ error: Error | null }> {
let error = null

Expand All @@ -243,7 +207,7 @@ export default class SupabaseClient {
}

private _unsubscribeSubscription(
subscription: RealtimeSubscription | RealtimeChannel
subscription: RealtimeSubscription
): Promise<{ error: Error | null }> {
return new Promise((resolve) => {
subscription
Expand Down

0 comments on commit e155e65

Please sign in to comment.