@yomo/presence
Advanced tools
Comparing version 2.1.0-alpha1 to 2.1.1
declare global { | ||
interface Window { | ||
WebTransport: any; | ||
} | ||
interface Window { | ||
WebTransport: any; | ||
} | ||
} | ||
declare type State = { | ||
id: string; | ||
[key: string]: any; | ||
type State = { | ||
id: string; | ||
[key: string]: any; | ||
}; | ||
declare type PresenceOptions = { | ||
url?: string; | ||
id?: string; | ||
publicKey?: string; | ||
appId?: string; | ||
appSecret?: string; | ||
endpoint?: string; | ||
reliable?: boolean; | ||
debug?: boolean; | ||
type PresenceOptions = { | ||
id?: string; | ||
publicKey?: string; | ||
reliable?: boolean; // default: false | ||
debug?: boolean; // default: false | ||
autoDowngrade?: boolean; // default: false | ||
}; | ||
declare type InternalPresenceOptions = { | ||
url: string; | ||
id: string; | ||
reliable: boolean; | ||
publicKey?: string; | ||
appId?: string; | ||
appSecret?: string; | ||
endpoint?: string; | ||
debug?: boolean; | ||
// internal options, create presence instance with this options | ||
type InternalPresenceOptions = { | ||
id: string; | ||
reliable: boolean; | ||
publicKey?: string; | ||
debug: boolean; | ||
autoDowngrade: boolean; | ||
}; | ||
/** | ||
* @param onReady - callback function when the presence instance is ready | ||
* @param onError - callback function when the presence instance is error | ||
* @param onClosed - callback function when the presence instance is closed | ||
*/ | ||
interface IPresence { | ||
onReady(callbackFn: (presence: IPresence) => void): void; | ||
joinChannel: (channelId: string, metadata?: State) => IChannel; | ||
leaveChannel: (channelId: string) => void; | ||
onReady(callbackFn: (presence: IPresence) => void): void; | ||
/** | ||
* join a channel | ||
* @param channelId a unique channel id | ||
* @param state join channel initial state | ||
* @returns {Channel} | ||
*/ | ||
joinChannel: (channelId: string, metadata?: State) => IChannel; | ||
leaveChannel: (channelId: string) => void; | ||
} | ||
declare type Peers = State[]; | ||
declare type PeersSubscribeCallbackFn = (peers: Peers) => any; | ||
declare type PeersUnsubscribe = Function; | ||
declare type Unsubscribe = Function; | ||
declare type PeersSubscribe = (callbackFn: PeersSubscribeCallbackFn) => PeersUnsubscribe; | ||
declare type ChannelEventSubscribeCallbackFn<T> = (payload: T, state: State) => any; | ||
type Peers = State[]; | ||
type PeersSubscribeCallbackFn = (peers: Peers) => any; | ||
type PeersUnsubscribe = Function; | ||
type Unsubscribe = Function; | ||
type PeersSubscribe = ( | ||
callbackFn: PeersSubscribeCallbackFn | ||
) => PeersUnsubscribe; | ||
type ChannelEventSubscribeCallbackFn<T> = ( | ||
payload: T, | ||
state: State | ||
) => any; | ||
interface IChannel { | ||
id: string; | ||
broadcast<T>(eventName: string, payload: T): void; | ||
subscribe<T>(eventName: string, callbackFn: ChannelEventSubscribeCallbackFn<T>): Unsubscribe; | ||
subscribePeers: PeersSubscribe; | ||
leave(): void; | ||
id: string; | ||
broadcast<T>(eventName: string, payload: T): void; | ||
subscribe<T>( | ||
eventName: string, | ||
callbackFn: ChannelEventSubscribeCallbackFn<T> | ||
): Unsubscribe; | ||
subscribePeers: PeersSubscribe; | ||
leave(): void; | ||
} | ||
@@ -64,11 +86,21 @@ | ||
#private; | ||
constructor(options: InternalPresenceOptions); | ||
constructor(url: string, options: InternalPresenceOptions); | ||
onReady(callbackFn: Function): void; | ||
onError(callbackFn: Function): void; | ||
onClosed(callbackFn: Function): void; | ||
joinChannel(channelId: string, metadata?: State): Channel; | ||
joinChannel(channelId: string, state?: State): Channel; | ||
leaveChannel(channelId: string): void; | ||
} | ||
declare function createPresence(options: PresenceOptions): Promise<IPresence>; | ||
/** | ||
* create a presence instance | ||
* @param url backend url | ||
* @param {string} options.id - the id of the presence instance | ||
* @param {string} options.publicKey - the public key of the presence instance | ||
* @param {boolean} options.reliable - whether to use reliable transport | ||
* @param {boolean} options.debug - whether to enable debug mode | ||
* @param {boolean} options.autoDowngrade - whether to auto downgrade to unreliable transport, when the reliable transport is not available | ||
* @returns {Promise<IPresence>} | ||
*/ | ||
declare function createPresence(url: string, options: PresenceOptions): Promise<IPresence>; | ||
export { IChannel, IPresence, Presence, createPresence }; |
{ | ||
"name": "@yomo/presence", | ||
"version": "2.1.0-alpha1", | ||
"description": "Edge Infra for Realtime Web Applications, geo-distributed architecture ⚡️", | ||
"license": "MIT", | ||
"keywords": [ | ||
"webtransport", | ||
"websocket", | ||
"presence", | ||
"live", | ||
"realtime" | ||
], | ||
"module": "./dist/index.js", | ||
"typings": "./dist/index.d.ts", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts" | ||
}, | ||
"./package.json": "./package.json" | ||
"name": "@yomo/presence", | ||
"version": "2.1.1", | ||
"description": "Edge Infra for Realtime Web Applications, geo-distributed architecture ⚡️", | ||
"license": "MIT", | ||
"keywords": [ | ||
"webtransport", | ||
"websocket", | ||
"presence", | ||
"live", | ||
"realtime" | ||
], | ||
"module": "./dist/index.js", | ||
"typings": "./dist/index.d.ts", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js", | ||
"types": "./dist/index.d.ts" | ||
}, | ||
"devDependencies": { | ||
"@msgpack/msgpack": "^2.8.0", | ||
"@types/node-fetch": "^2.5.12", | ||
"node-fetch": "^2.6.7", | ||
"tsdx": "^0.14.1", | ||
"tsup": "^6.2.2", | ||
"typescript": "^4.5.2", | ||
"web-streams-polyfill": "^3.2.1" | ||
}, | ||
"repository": "github.com:yomorun/presencejs", | ||
"bugs": { | ||
"url": "https://github.com/yomorun/presencejs/issues" | ||
}, | ||
"homepage": "https://presence.js.org", | ||
"dependencies": { | ||
"@yomo/webtransport-polyfill": "^1.0.1" | ||
}, | ||
"scripts": { | ||
"start": "tsup ./src/index.ts --dts --watch", | ||
"build": "tsup ./src/index.ts --dts", | ||
"test": "tsdx test --detectOpenHandles", | ||
"lint": "tsdx lint" | ||
} | ||
"./package.json": "./package.json" | ||
}, | ||
"repository": "github.com:yomorun/presencejs", | ||
"bugs": { | ||
"url": "https://github.com/yomorun/presencejs/issues" | ||
}, | ||
"homepage": "https://presence.js.org", | ||
"devDependencies": { | ||
"@msgpack/msgpack": "^2.8.0", | ||
"@types/node-fetch": "^2.5.12", | ||
"node-fetch": "^2.6.7", | ||
"tsdx": "^0.14.1", | ||
"tsup": "^6.2.2", | ||
"typescript": "^4.5.2", | ||
"web-streams-polyfill": "^3.2.1" | ||
}, | ||
"dependencies": { | ||
"@yomo/webtransport-polyfill": "^1.0.1" | ||
}, | ||
"scripts": { | ||
"start": "tsup ./src/index.ts --dts --watch", | ||
"build": "tsup ./src/index.ts --dts", | ||
"test": "tsdx test --detectOpenHandles", | ||
"lint": "tsdx lint" | ||
} | ||
} |
## 🧬 Introduction | ||
 | ||
`Presencejs` is a JavaScript library that enables the creation of real-time web applications with a secure, low-latency, and high-performance geo-distributed architecture. | ||
@@ -4,0 +6,0 @@ |
Sorry, the diff of this file is too big to display
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
132
0
239263
4200