@supabase/realtime-js
Advanced tools
Comparing version 1.4.5 to 1.4.6
@@ -1,2 +0,2 @@ | ||
export declare const version = "1.4.5"; | ||
export declare const version = "1.4.6"; | ||
//# sourceMappingURL=version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = '1.4.5'; | ||
exports.version = '1.4.6'; | ||
//# sourceMappingURL=version.js.map |
import Timer from './lib/timer'; | ||
import Serializer from './lib/serializer'; | ||
import RealtimeSubscription from './RealtimeSubscription'; | ||
import Serializer from './lib/serializer'; | ||
import RealtimeChannel from './RealtimeChannel'; | ||
export declare type Options = { | ||
@@ -137,3 +138,5 @@ transport?: WebSocket; | ||
remove(channel: RealtimeSubscription): void; | ||
channel(topic: string, chanParams?: {}): RealtimeSubscription; | ||
channel(topic: string, chanParams?: { | ||
[key: string]: any; | ||
}): RealtimeSubscription | RealtimeChannel; | ||
push(data: Message): void; | ||
@@ -140,0 +143,0 @@ onConnMessage(rawMessage: any): void; |
@@ -11,2 +11,13 @@ "use strict"; | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -19,4 +30,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const timer_1 = __importDefault(require("./lib/timer")); | ||
const serializer_1 = __importDefault(require("./lib/serializer")); | ||
const RealtimeSubscription_1 = __importDefault(require("./RealtimeSubscription")); | ||
const serializer_1 = __importDefault(require("./lib/serializer")); | ||
const RealtimeChannel_1 = __importDefault(require("./RealtimeChannel")); | ||
const noop = () => { }; | ||
@@ -213,4 +225,28 @@ class RealtimeClient { | ||
} | ||
channel(topic, chanParams = {}) { | ||
let chan = new RealtimeSubscription_1.default(topic, chanParams, this); | ||
channel(topic, chanParams = { isNewVersion: false }) { | ||
const { isNewVersion } = chanParams, params = __rest(chanParams, ["isNewVersion"]); | ||
const chan = isNewVersion | ||
? new RealtimeChannel_1.default(topic, Object.assign({}, params), this) | ||
: new RealtimeSubscription_1.default(topic, Object.assign({}, params), this); | ||
if (chan instanceof RealtimeChannel_1.default) { | ||
chan.presence.onJoin((key, currentPresences, newPresences) => { | ||
chan.trigger('presence', { | ||
event: 'JOIN', | ||
key, | ||
currentPresences, | ||
newPresences, | ||
}); | ||
}); | ||
chan.presence.onLeave((key, currentPresences, leftPresences) => { | ||
chan.trigger('presence', { | ||
event: 'LEAVE', | ||
key, | ||
currentPresences, | ||
leftPresences, | ||
}); | ||
}); | ||
chan.presence.onSync(() => { | ||
chan.trigger('presence', { event: 'SYNC' }); | ||
}); | ||
} | ||
this.channels.push(chan); | ||
@@ -217,0 +253,0 @@ return chan; |
import { PresenceOpts, PresenceOnJoinCallback, PresenceOnLeaveCallback } from 'phoenix'; | ||
import RealtimeSubscription from './RealtimeSubscription'; | ||
import RealtimeChannel from './RealtimeChannel'; | ||
declare type Presence = { | ||
@@ -27,3 +27,3 @@ presence_id: string; | ||
export default class RealtimePresence { | ||
channel: RealtimeSubscription; | ||
channel: RealtimeChannel; | ||
state: PresenceState; | ||
@@ -43,3 +43,3 @@ pendingDiffs: RawPresenceDiff[]; | ||
*/ | ||
constructor(channel: RealtimeSubscription, opts?: PresenceOpts); | ||
constructor(channel: RealtimeChannel, opts?: PresenceOpts); | ||
/** | ||
@@ -46,0 +46,0 @@ * Used to sync the list of presences on the server |
@@ -32,3 +32,3 @@ "use strict"; | ||
}; | ||
this.channel.on(events.state, (newState) => { | ||
this.channel.on(events.state, {}, (newState) => { | ||
const { onJoin, onLeave, onSync } = this.caller; | ||
@@ -43,3 +43,3 @@ this.joinRef = this.channel.joinRef(); | ||
}); | ||
this.channel.on(events.diff, (diff) => { | ||
this.channel.on(events.diff, {}, (diff) => { | ||
const { onJoin, onLeave, onSync } = this.caller; | ||
@@ -46,0 +46,0 @@ if (this.inPendingSyncState()) { |
@@ -1,2 +0,2 @@ | ||
export declare const version = "1.4.5"; | ||
export declare const version = "1.4.6"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export const version = '1.4.5'; | ||
export const version = '1.4.6'; | ||
//# sourceMappingURL=version.js.map |
import Timer from './lib/timer'; | ||
import Serializer from './lib/serializer'; | ||
import RealtimeSubscription from './RealtimeSubscription'; | ||
import Serializer from './lib/serializer'; | ||
import RealtimeChannel from './RealtimeChannel'; | ||
export declare type Options = { | ||
@@ -137,3 +138,5 @@ transport?: WebSocket; | ||
remove(channel: RealtimeSubscription): void; | ||
channel(topic: string, chanParams?: {}): RealtimeSubscription; | ||
channel(topic: string, chanParams?: { | ||
[key: string]: any; | ||
}): RealtimeSubscription | RealtimeChannel; | ||
push(data: Message): void; | ||
@@ -140,0 +143,0 @@ onConnMessage(rawMessage: any): void; |
@@ -10,7 +10,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
import { w3cwebsocket } from 'websocket'; | ||
import { VSN, CHANNEL_EVENTS, TRANSPORTS, SOCKET_STATES, DEFAULT_TIMEOUT, WS_CLOSE_NORMAL, DEFAULT_HEADERS, } from './lib/constants'; | ||
import Timer from './lib/timer'; | ||
import Serializer from './lib/serializer'; | ||
import RealtimeSubscription from './RealtimeSubscription'; | ||
import Serializer from './lib/serializer'; | ||
import RealtimeChannel from './RealtimeChannel'; | ||
const noop = () => { }; | ||
@@ -207,4 +219,28 @@ export default class RealtimeClient { | ||
} | ||
channel(topic, chanParams = {}) { | ||
let chan = new RealtimeSubscription(topic, chanParams, this); | ||
channel(topic, chanParams = { isNewVersion: false }) { | ||
const { isNewVersion } = chanParams, params = __rest(chanParams, ["isNewVersion"]); | ||
const chan = isNewVersion | ||
? new RealtimeChannel(topic, Object.assign({}, params), this) | ||
: new RealtimeSubscription(topic, Object.assign({}, params), this); | ||
if (chan instanceof RealtimeChannel) { | ||
chan.presence.onJoin((key, currentPresences, newPresences) => { | ||
chan.trigger('presence', { | ||
event: 'JOIN', | ||
key, | ||
currentPresences, | ||
newPresences, | ||
}); | ||
}); | ||
chan.presence.onLeave((key, currentPresences, leftPresences) => { | ||
chan.trigger('presence', { | ||
event: 'LEAVE', | ||
key, | ||
currentPresences, | ||
leftPresences, | ||
}); | ||
}); | ||
chan.presence.onSync(() => { | ||
chan.trigger('presence', { event: 'SYNC' }); | ||
}); | ||
} | ||
this.channels.push(chan); | ||
@@ -211,0 +247,0 @@ return chan; |
import { PresenceOpts, PresenceOnJoinCallback, PresenceOnLeaveCallback } from 'phoenix'; | ||
import RealtimeSubscription from './RealtimeSubscription'; | ||
import RealtimeChannel from './RealtimeChannel'; | ||
declare type Presence = { | ||
@@ -27,3 +27,3 @@ presence_id: string; | ||
export default class RealtimePresence { | ||
channel: RealtimeSubscription; | ||
channel: RealtimeChannel; | ||
state: PresenceState; | ||
@@ -43,3 +43,3 @@ pendingDiffs: RawPresenceDiff[]; | ||
*/ | ||
constructor(channel: RealtimeSubscription, opts?: PresenceOpts); | ||
constructor(channel: RealtimeChannel, opts?: PresenceOpts); | ||
/** | ||
@@ -46,0 +46,0 @@ * Used to sync the list of presences on the server |
@@ -27,3 +27,3 @@ /* | ||
}; | ||
this.channel.on(events.state, (newState) => { | ||
this.channel.on(events.state, {}, (newState) => { | ||
const { onJoin, onLeave, onSync } = this.caller; | ||
@@ -38,3 +38,3 @@ this.joinRef = this.channel.joinRef(); | ||
}); | ||
this.channel.on(events.diff, (diff) => { | ||
this.channel.on(events.diff, {}, (diff) => { | ||
const { onJoin, onLeave, onSync } = this.caller; | ||
@@ -41,0 +41,0 @@ if (this.inPendingSyncState()) { |
{ | ||
"name": "@supabase/realtime-js", | ||
"version": "1.4.5", | ||
"version": "1.4.6", | ||
"description": "Listen to realtime updates to your PostgreSQL database", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,1 +0,1 @@ | ||
export const version = '1.4.5' | ||
export const version = '1.4.6' |
@@ -12,4 +12,5 @@ import { w3cwebsocket } from 'websocket' | ||
import Timer from './lib/timer' | ||
import Serializer from './lib/serializer' | ||
import RealtimeSubscription from './RealtimeSubscription' | ||
import Serializer from './lib/serializer' | ||
import RealtimeChannel from './RealtimeChannel' | ||
@@ -252,4 +253,36 @@ export type Options = { | ||
channel(topic: string, chanParams = {}) { | ||
let chan = new RealtimeSubscription(topic, chanParams, this) | ||
channel( | ||
topic: string, | ||
chanParams: { [key: string]: any } = { isNewVersion: false } | ||
) { | ||
const { isNewVersion, ...params } = chanParams | ||
const chan = isNewVersion | ||
? new RealtimeChannel(topic, { ...params }, this) | ||
: new RealtimeSubscription(topic, { ...params }, this) | ||
if (chan instanceof RealtimeChannel) { | ||
chan.presence.onJoin((key, currentPresences, newPresences) => { | ||
chan.trigger('presence', { | ||
event: 'JOIN', | ||
key, | ||
currentPresences, | ||
newPresences, | ||
}) | ||
}) | ||
chan.presence.onLeave((key, currentPresences, leftPresences) => { | ||
chan.trigger('presence', { | ||
event: 'LEAVE', | ||
key, | ||
currentPresences, | ||
leftPresences, | ||
}) | ||
}) | ||
chan.presence.onSync(() => { | ||
chan.trigger('presence', { event: 'SYNC' }) | ||
}) | ||
} | ||
this.channels.push(chan) | ||
@@ -256,0 +289,0 @@ return chan |
@@ -12,3 +12,3 @@ /* | ||
} from 'phoenix' | ||
import RealtimeSubscription from './RealtimeSubscription' | ||
import RealtimeChannel from './RealtimeChannel' | ||
@@ -65,3 +65,3 @@ type Presence = { | ||
*/ | ||
constructor(public channel: RealtimeSubscription, opts?: PresenceOpts) { | ||
constructor(public channel: RealtimeChannel, opts?: PresenceOpts) { | ||
const events = opts?.events || { | ||
@@ -72,3 +72,3 @@ state: 'presence_state', | ||
this.channel.on(events.state, (newState: RawPresenceState) => { | ||
this.channel.on(events.state, {}, (newState: RawPresenceState) => { | ||
const { onJoin, onLeave, onSync } = this.caller | ||
@@ -99,3 +99,3 @@ | ||
this.channel.on(events.diff, (diff: RawPresenceDiff) => { | ||
this.channel.on(events.diff, {}, (diff: RawPresenceDiff) => { | ||
const { onJoin, onLeave, onSync } = this.caller | ||
@@ -102,0 +102,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
309702
102
5521