Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Clean up libraries

Angelicobe64fcab47f3
diff --git a/libraries/supabase-js/src/Base.js b/libraries/supabase-js/src/Base.js
index 296705ad3dc..1e39de5c798 100644
--- a/libraries/supabase-js/src/Base.js
+++ b/libraries/supabase-js/src/Base.js
@@ -2,10 +2,11 @@ import { Socket } from 'phoenix-channels'
import BaseRequest from './BaseRequest'
class Base {
- constructor(tableName, restUrl, apiSocket, uuid) {
+ constructor(tableName, restUrl, apiSocket, schema, uuid) {
this.tableName = tableName
this.restUrl = restUrl
this.apiSocket = apiSocket
+ this.schema = schema
this.uuid = uuid
this.socket = null
@@ -16,8 +17,15 @@ class Base {
}
createListener() {
- this.socket = new Socket(apiSocket)
- this.channel = this.socket.channel(this.tableName)
+ this.socket = new Socket(this.apiSocket)
+ this.channel = this.socket.channel(`realtime:${this.schema}:${this.tableName}`)
+
+ this.socket.onOpen(() => {
+ console.log('Socket connected')
+ })
+ this.socket.onClose(() => {
+ console.log('Socket disconnected')
+ })
}
on(eventType, callbackFunction) {
@@ -25,6 +33,8 @@ class Base {
var ref = this.channel.on(eventType, callbackFunction)
this.listeners[eventType] = ref
+
+ return this
}
subscribe() {
@@ -39,15 +49,14 @@ class Base {
.receive('error', resp => console.log('Unable to join ', resp))
.receive('timeout', () => console.log('Networking issue. Still waiting...'))
}
+
+ return this
}
unsubscribe() {
- for (var ref in this.listeners) {
- let eventName = this.listeners[ref]
- this.off(eventName, ref)
- }
-
this.socket.disconnect()
+
+ return this
}
request(method) {
diff --git a/libraries/supabase-js/src/index.js b/libraries/supabase-js/src/index.js
index c23e6251ed3..c9d8e1696df 100644
--- a/libraries/supabase-js/src/index.js
+++ b/libraries/supabase-js/src/index.js
@@ -1,5 +1,3 @@
-import BaseRequest from './BaseRequest'
-import Subscription from './Subscription'
import { uuid } from './utils/Helpers'
import Base from './Base'
@@ -10,6 +8,7 @@ class SupabaseClient {
this.restUrl = null
this.apiSocket = null
+ this.schema = null
this.subscriptions = {}
this.authenticate(supabaseUrl, supabaseKey)
@@ -17,19 +16,21 @@ class SupabaseClient {
authenticate(supabaseUrl, supabaseKey){
// do something to utilise parameters and receive
- // the restUrl & apiSocket
+ // the restUrl, apiSocket and schema
- var restUrl = supabaseUrl
+ var restUrl = ''
var apiSocket = ''
+ var schema = ''
- this.restUrl = restUrl
- this.apiSocket = apiSocket
+ this.restUrl = 'http://localhost:3000'
+ this.apiSocket = 'ws://localhost:4000/socket'
+ this.schema = 'public'
}
from(tableName){
let identifier = uuid()
- this.subscriptions[identifier] = new Base(tableName, this.restUrl, this.apiSocket, identifier)
+ this.subscriptions[identifier] = new Base(tableName, this.restUrl, this.apiSocket, this.schema, identifier)
return this.subscriptions[identifier]
}