@github/alive-client
Advanced tools
Comparing version 1.0.2 to 1.1.2
import { AlivePresenceData, PresenceItem, UserPresence } from './presence.js'; | ||
import { MetadataUpdate } from './presence-metadata.js'; | ||
import type { Socket } from '@github/stable-socket'; | ||
import type { Socket, SocketPolicy } from '@github/stable-socket'; | ||
import type { Subscription } from './subscription-set'; | ||
@@ -10,3 +10,3 @@ interface AliveMessageData { | ||
} | ||
export declare type AliveData = AliveMessageData | AlivePresenceData; | ||
export type AliveData = AliveMessageData | AlivePresenceData; | ||
interface MessageEvent { | ||
@@ -20,6 +20,9 @@ type: 'message'; | ||
} | ||
export declare type AliveEvent = { | ||
export type AliveEvent = { | ||
channel: string; | ||
} & (MessageEvent | PresenceEvent); | ||
export declare type Notifier<T> = (subscribers: Iterable<T>, event: AliveEvent) => void; | ||
export type Notifier<T> = (subscribers: Iterable<T>, event: AliveEvent) => void; | ||
interface AliveSessionOptions { | ||
socketPolicy?: SocketPolicy; | ||
} | ||
export declare class AliveSession<T> { | ||
@@ -31,2 +34,3 @@ private url; | ||
private readonly maxReconnectBackoff; | ||
private readonly options; | ||
private socket; | ||
@@ -45,3 +49,3 @@ private subscriptions; | ||
private lastCameOnline; | ||
constructor(url: string, getUrl: () => Promise<string | null>, inSharedWorker: boolean, notify: Notifier<T>, maxReconnectBackoff?: number); | ||
constructor(url: string, getUrl: () => Promise<string | null>, inSharedWorker: boolean, notify: Notifier<T>, maxReconnectBackoff?: number, options?: AliveSessionOptions); | ||
subscribe(subscriptions: Array<Subscription<T>>): void; | ||
@@ -48,0 +52,0 @@ unsubscribe(subscriptions: Array<Subscription<T>>): void; |
@@ -20,3 +20,3 @@ import { AlivePresence, getPresenceKey, isPresenceChannel } from './presence.js'; | ||
export class AliveSession { | ||
constructor(url, getUrl, inSharedWorker, notify, maxReconnectBackoff = 600000) { | ||
constructor(url, getUrl, inSharedWorker, notify, maxReconnectBackoff = 600000, options = {}) { | ||
this.url = url; | ||
@@ -27,2 +27,3 @@ this.getUrl = getUrl; | ||
this.maxReconnectBackoff = maxReconnectBackoff; | ||
this.options = options; | ||
this.subscriptions = new SubscriptionSet(); | ||
@@ -256,3 +257,3 @@ this.state = 'online'; | ||
connect() { | ||
const socket = new StableSocket(this.getUrlWithPresenceId(), this, { timeout: 4000, attempts: 7 }); | ||
const socket = new StableSocket(this.getUrlWithPresenceId(), this, this.options.socketPolicy || { timeout: 4000, attempts: 7 }); | ||
socket.open(); | ||
@@ -259,0 +260,0 @@ return socket; |
export declare const IDLE_METADATA_KEY = "_i"; | ||
export declare type Metadata = Record<string, unknown> & { | ||
export type Metadata = Record<string, unknown> & { | ||
[IDLE_METADATA_KEY]?: 0 | 1; | ||
@@ -4,0 +4,0 @@ }; |
@@ -19,3 +19,3 @@ import { Metadata } from './presence-metadata.js'; | ||
} | ||
export declare type AlivePresenceData = FullPresenceData | AddPresenceData | RemovePresenceData; | ||
export type AlivePresenceData = FullPresenceData | AddPresenceData | RemovePresenceData; | ||
export interface UserPresence { | ||
@@ -22,0 +22,0 @@ userId: number; |
import { Topic } from './topic.js'; | ||
export declare type Subscription<T> = { | ||
export type Subscription<T> = { | ||
subscriber: T; | ||
@@ -4,0 +4,0 @@ topic: Topic; |
export class Topic { | ||
constructor(name, signed) { | ||
this.name = name; | ||
this.signed = signed; | ||
this.offset = ''; | ||
} | ||
static parse(data) { | ||
@@ -16,2 +11,7 @@ const [content, signature] = data.split('--'); | ||
} | ||
constructor(name, signed) { | ||
this.name = name; | ||
this.signed = signed; | ||
this.offset = ''; | ||
} | ||
} |
{ | ||
"name": "@github/alive-client", | ||
"version": "1.0.2", | ||
"version": "1.1.2", | ||
"description": "Template repository making it easier for developers to write frontend functionality that will be integrated into dotcom", | ||
@@ -13,5 +13,5 @@ "main": "dist/index.js", | ||
"lint": "eslint src/ test/", | ||
"test": "npm run lint && npm run karma", | ||
"test:watch": "karma start test/karma.config.cjs", | ||
"karma": "karma start test/karma.config.cjs --singleRun", | ||
"test": "npm run lint && npm run test:browser", | ||
"test:browser": "vitest", | ||
"test:watch": "vitest --watch", | ||
"clean": "rm -rf dist", | ||
@@ -47,21 +47,13 @@ "prebuild": "npm run clean", | ||
"devDependencies": { | ||
"@vitest/browser": "^2.1.8", | ||
"@github/prettier-config": "0.0.4", | ||
"@size-limit/preset-small-lib": "^7.0.3", | ||
"@types/chai": "^4.2.22", | ||
"@types/mocha": "^9.0.0", | ||
"chai": "^4.3.4", | ||
"eslint": "^8.2.0", | ||
"eslint-plugin-github": "^4.3.5", | ||
"karma": "^6.3.9", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-esbuild": "^2.2.0", | ||
"karma-mocha": "^2.0.1", | ||
"karma-mocha-reporter": "^2.2.5", | ||
"mocha": "^9.1.3", | ||
"playwright": "^1.17.1", | ||
"prettier": "^2.4.1", | ||
"playwright": "^1.49.1", | ||
"size-limit": "^7.0.3", | ||
"typescript": "^4.4.4" | ||
"typescript": "^5.7.2", | ||
"vitest": "^2.1.8" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10
731
28503