mikeanth
03/08/2022, 5:13 PMCreating a Socket connection
section from the docs here: https://github.com/supabase/realtime-js
My code looks like this:
import { RealtimeClient } from '@supabase/realtime-js'
var client = new RealtimeClient("wss://<project_ref>.supabase.co/realtime/v1")
client.connect()
client.onOpen(() => console.log('Socket opened.'))
client.onClose(() => console.log('Socket closed.'))
client.onError((e) => console.log('Socket error', e))
mikeanth
03/08/2022, 5:14 PMmikeanth
03/08/2022, 5:14 PMmike@workstation:~/workspace/scheduler$ node src/index.js
Socket error _Event {
type: 'error',
isTrusted: false,
_yaeti: true,
target: W3CWebSocket {
_listeners: {},
addEventListener: [Function: _addEventListener],
removeEventListener: [Function: _removeEventListener],
dispatchEvent: [Function: _dispatchEvent],
_url: 'wss://<project_ref_here>.supabase.co/realtime/v1/websocket?vsn=1.0.0',
_readyState: 3,
_protocol: undefined,
_extensions: '',
_bufferedAmount: 0,
_binaryType: 'arraybuffer',
_connection: undefined,
_client: WebSocketClient {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
config: [Object],
_req: null,
protocols: [],
origin: null,
url: [Url],
secure: true,
base64nonce: 'jOMp0ZkpTIVvP0M37rUqCw==',
[Symbol(kCapture)]: false
},
onopen: [Function (anonymous)],
onerror: [Function (anonymous)],
onmessage: [Function (anonymous)],
onclose: [Function (anonymous)]
},
cancelable: true,
stopImmediatePropagation: [Function (anonymous)]
}
Socket closed.
mikeanth
03/08/2022, 5:15 PM<project_ref>
with my actual project idmikeanth
03/08/2022, 5:15 PMmikeanth
03/08/2022, 5:16 PMsupabase-js
, but in this particular microservice i only need access to the realtime api, so it feels wasteful to import the entire client library only to get access to the realtime-js
wrappergaryaustin
03/08/2022, 5:30 PMmikeanth
03/08/2022, 5:31 PMmikeanth
03/08/2022, 5:31 PMmikeanth
03/08/2022, 5:34 PMmikeanth
03/08/2022, 5:34 PMmike@workstation:~/workspace/scheduler$ node src/index.js
Socket error _Event {
type: 'error',
isTrusted: false,
_yaeti: true,
target: W3CWebSocket {
_listeners: {},
addEventListener: [Function: _addEventListener],
removeEventListener: [Function: _removeEventListener],
dispatchEvent: [Function: _dispatchEvent],
_url: 'wss://<project_ref>.supabase.co/websocket?apikey=<anon_key>&vsn=1.0.0',
_readyState: 3,
_protocol: undefined,
_extensions: '',
_bufferedAmount: 0,
_binaryType: 'arraybuffer',
_connection: undefined,
_client: WebSocketClient {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
config: [Object],
_req: null,
protocols: [],
origin: null,
url: [Url],
secure: true,
base64nonce: 'qMVi2jFMfYO4FxIzX4RDYw==',
[Symbol(kCapture)]: false
},
onopen: [Function (anonymous)],
onerror: [Function (anonymous)],
onmessage: [Function (anonymous)],
onclose: [Function (anonymous)]
},
cancelable: true,
stopImmediatePropagation: [Function (anonymous)]
}
Socket closed.
mikeanth
03/08/2022, 5:35 PMvar supabase_url = "wss://<project_ref>.supabase.co"
var supabase_anon_key = "<anon_key>"
var client = new RealtimeClient(supabase_url, {
params: {
apikey: supabase_anon_key
}
})
client.connect()
mikeanth
03/08/2022, 5:43 PMservice_role
key and it didn't change anything 😦garyaustin
03/08/2022, 5:46 PMmikeanth
03/08/2022, 5:47 PMgaryaustin
03/08/2022, 5:47 PMmikeanth
03/08/2022, 5:47 PMgaryaustin
03/08/2022, 5:48 PMmikeanth
03/08/2022, 5:49 PMmikeanth
03/08/2022, 5:49 PMgaryaustin
03/08/2022, 5:57 PMmikeanth
03/08/2022, 5:57 PMsupabase-js
now eithermikeanth
03/08/2022, 5:57 PMmikeanth
03/08/2022, 5:59 PMsupabase-js
instead of httpsmikeanth
03/08/2022, 5:59 PMmikeanth
03/08/2022, 6:00 PMmikeanth
03/08/2022, 6:00 PMgaryaustin
03/08/2022, 6:03 PMmikeanth
03/08/2022, 6:05 PMmikeanth
03/08/2022, 6:05 PMmikeanth
03/08/2022, 6:05 PMmikeanth
03/08/2022, 6:05 PMmikeanth
03/08/2022, 6:05 PMgaryaustin
03/08/2022, 7:56 PMgaryaustin
03/08/2022, 9:21 PMmikeanth
03/08/2022, 9:23 PMmikeanth
03/08/2022, 9:23 PMmikeanth
03/08/2022, 9:24 PMmikeanth
03/08/2022, 9:24 PMgaryaustin
03/08/2022, 9:26 PMmikeanth
03/08/2022, 9:27 PMmikeanth
03/08/2022, 9:41 PM