File size: 2,851 Bytes
c212805 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | import { Socket } from '@supabase/phoenix';
import { CONNECTION_STATE } from '../lib/constants';
export default class SocketAdapter {
constructor(endPoint, options) {
this.socket = new Socket(endPoint, options);
}
get timeout() {
return this.socket.timeout;
}
get endPoint() {
return this.socket.endPoint;
}
get transport() {
return this.socket.transport;
}
get heartbeatIntervalMs() {
return this.socket.heartbeatIntervalMs;
}
get heartbeatCallback() {
return this.socket.heartbeatCallback;
}
set heartbeatCallback(callback) {
this.socket.heartbeatCallback = callback;
}
get heartbeatTimer() {
return this.socket.heartbeatTimer;
}
get pendingHeartbeatRef() {
return this.socket.pendingHeartbeatRef;
}
get reconnectTimer() {
return this.socket.reconnectTimer;
}
get vsn() {
return this.socket.vsn;
}
get encode() {
return this.socket.encode;
}
get decode() {
return this.socket.decode;
}
get reconnectAfterMs() {
return this.socket.reconnectAfterMs;
}
get sendBuffer() {
return this.socket.sendBuffer;
}
get stateChangeCallbacks() {
return this.socket.stateChangeCallbacks;
}
connect() {
this.socket.connect();
}
disconnect(callback, code, reason, timeout = 10000) {
return new Promise((resolve) => {
setTimeout(() => resolve('timeout'), timeout);
this.socket.disconnect(() => {
callback();
resolve('ok');
}, code, reason);
});
}
push(data) {
this.socket.push(data);
}
log(kind, msg, data) {
this.socket.log(kind, msg, data);
}
makeRef() {
return this.socket.makeRef();
}
onOpen(callback) {
this.socket.onOpen(callback);
}
onClose(callback) {
this.socket.onClose(callback);
}
onError(callback) {
this.socket.onError(callback);
}
onMessage(callback) {
this.socket.onMessage(callback);
}
isConnected() {
return this.socket.isConnected();
}
isConnecting() {
return this.socket.connectionState() == CONNECTION_STATE.connecting;
}
isDisconnecting() {
return this.socket.connectionState() == CONNECTION_STATE.closing;
}
connectionState() {
// @ts-ignore - requires better typing and exposing type in phoenix
return this.socket.connectionState();
}
endPointURL() {
return this.socket.endPointURL();
}
sendHeartbeat() {
this.socket.sendHeartbeat();
}
/**
* @internal
*/
getSocket() {
return this.socket;
}
}
//# sourceMappingURL=socketAdapter.js.map |