Created
July 13, 2020 11:10
-
-
Save dmaretskyi/94fa8c9f1811cbab36dbcba3271c5d56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @typedef SecretProvider | |
*/ | |
/** | |
* Drives a FeedStore such that messages received on that FeedStore's message stream | |
* correspond to the messages from the open Parties. Provides access to ancillary | |
* services: Identity management, Device management, Party invitation and greeting. | |
* | |
* @event PartyManager#'party' fires when a Party is added to the manager (whether a newly created Party, one joined | |
* on another device, or one loaded from storage) | |
* @type {PublicKey} | |
* | |
* @event PartyManager#'party:update' fires when a Party is updated (eg, a new key or feed added) | |
* @type {PublicKey} | |
* | |
* @event PartyManager#'party:info' fires when PartyInfo is added to the manager (whether a newly created Party, | |
* one joined on another device, or one loaded from storage) | |
* @type {PublicKey} | |
* | |
* @event PartyManager#'party:info:update' fires when PartyInfo is updated | |
* @type {PublicKey} | |
* | |
* @event PartyManager#'@package:device:info' fires when a DeviceInfo message has been processed on the Halo | |
* @type {DeviceInfo} | |
* | |
* @event PartyManager#'@package:identity:info' fires when an IdentityInfo message has been processed on the Halo | |
* @type {IdentityInfo} | |
* | |
* @event PartyManager#'@package:identity:joinedparty' fires when a JoinedParty message has been processed | |
* @type {PublicKey} | |
*/ | |
export class PartyManager { | |
/** | |
* | |
* @param {FeedStore} feedStore configured Feed Store | |
* @param {Keyring} keyRing Keyring | |
* @param {NetworkManager} networkManager | |
*/ | |
constructor(feedStore: any, keyRing: any, networkManager: any); | |
/** @type {Map<string, Party>} */ | |
_parties: Map<string, any>; | |
/** @type {Map<string, PartyState>} */ | |
_partyState: Map<string, Readonly<{ | |
OPEN: string; | |
OPENING: string; | |
CLOSED: string; | |
CLOSING: string; | |
}>>; | |
/** @type {Map<string, PartyInfo>} */ | |
_partyInfoMap: Map<string, PartyInfo>; | |
/** @type {FeedStore} */ | |
_feedStore: any; | |
/** @type {Keyring} */ | |
_keyRing: any; | |
/** @type {NetworkManager} */ | |
_networkManager: any; | |
/** @type {boolean} */ | |
_initialized: boolean; | |
/** @type {boolean} */ | |
_destroyed: boolean; | |
/** @type {PartyProcessor} */ | |
_partyProcessor: PartyProcessor; | |
/** @type {ModelFactory} */ | |
_modelFactory: any; | |
/** @type {Map<string, Model>} */ | |
_partyPropertyModels: Map<string, any>; | |
/** @type {Model} */ | |
_partySettingsModel: any; | |
_identityManager: IdentityManager; | |
_contactManager: ContactManager; | |
/** | |
* @package | |
* @returns {Keyring} | |
*/ | |
get keyRing(): any; | |
/** | |
* @return {IdentityManager} | |
*/ | |
get identityManager(): IdentityManager; | |
/** | |
* Must be called after constructor. | |
* @throws {Error} TODO(dboreham): add details. | |
*/ | |
initialize(): Promise<void>; | |
/** | |
* Cleanup, release resources. | |
*/ | |
destroy(): Promise<void>; | |
/** | |
* Creates a Party. | |
* @return {Party} The newly created Party. | |
*/ | |
createParty(): any; | |
/** | |
* Opens a Party. Party designated by partyKey must have previously been created or joined. | |
* @param {PublicKey} partyKey Party Key | |
* @throws {Error} TODO(dboreham): add details. | |
*/ | |
openParty(partyKey: any): Promise<void>; | |
/** | |
* Close a party. Silently succeeds if not open to prevent caller needing to synchronize. No return value. | |
* @param {PublicKey} partyKey | |
*/ | |
closeParty(partyKey: any): Promise<void>; | |
/** | |
* Issues an invitation to join a Party. | |
* @param {PublicKey} partyKey | |
* @param {InviteDetails} inviteDetails | |
* @param {InviteOptions} [options] | |
* @returns {InvitationDescriptor} | |
*/ | |
inviteToParty(partyKey: any, inviteDetails: any, options?: any): InvitationDescriptor; | |
/** | |
* Join a Party by redeeming an Invitation. | |
* @param {InvitationDescriptor} invitationDescriptor | |
* @param {SecretProvider} secretProvider | |
* @returns {Party} The now open Party. | |
*/ | |
joinParty(invitationDescriptor: InvitationDescriptor, secretProvider: any): any; | |
/** | |
* Set one or more properties on the specified Party as key/value pairs. | |
* Expected properties include: | |
* {String} displayName | |
* @param {PublicKey} partyKey | |
* @param {Object} properties | |
* @returns {Promise<void>} | |
*/ | |
setPartyProperty(partyKey: any, properties: any): Promise<void>; | |
/** | |
* Unsubscribe to a Party (this Party must already exist and have previously been joined/created). | |
* @param partyKey | |
* @returns {Promise<void>} | |
*/ | |
unsubscribe(partyKey: any): Promise<void>; | |
/** | |
* Subscribe to a Party (this Party must already exist and have previously been joined/created). | |
* @param partyKey | |
* @returns {Promise<void>} | |
*/ | |
subscribe(partyKey: any): Promise<void>; | |
/** | |
* Returns an open writable stream through which messages for the designated party can be published. | |
* @param {PublicKey} partyKey | |
* @return {stream.Writable} | |
* @throws {Error} TODO(dboreham): add details. | |
*/ | |
getWritableStream(partyKey: any): any; | |
/** | |
* Return an array of party keys. | |
* When opts.openOnly == true, only return parties that are currently open. | |
* | |
* @typedef {Object} getPartyKeysOpts | |
* @property {boolean} openOnly | |
* | |
* @param {getPartyKeysOpts} opts | |
* @return {PublicKey[]} | |
*/ | |
getPartyKeys(opts: { | |
openOnly: boolean; | |
}): any[]; | |
/** | |
* Return the Party object associated with a given Party Key, or undefined if no such Party is known. | |
* The party must be open. If not open, returns undefined. | |
* @param {PublicKey} partyKey | |
* @return {Party} | |
*/ | |
getParty(partyKey: any): any; | |
/** | |
* Get information about all Parties known to the PartyManager, | |
* primarily for diagnostic/user-facing visualization purposes. | |
* @return {PartyInfo[]} | |
*/ | |
getPartyInfoList(): PartyInfo[]; | |
/** | |
* Get information about the party associated with partyKey, | |
* primarily for diagnostic/user-facing visualization purposes. | |
* @param {PublicKey} partyKey | |
* @return {PartyInfo} | |
*/ | |
getPartyInfo(partyKey: any): PartyInfo; | |
/** | |
* Return whether or not the PartyManager has information about the Party associated with partyKey. | |
* @param {PublicKey} partyKey | |
* @return {boolean} | |
*/ | |
hasPartyInfo(partyKey: any): boolean; | |
/** | |
* Returns true if the specified Party is known, else false. | |
* @param {PublicKey} partyKey | |
* @return {boolean} | |
*/ | |
hasParty(partyKey: any): boolean; | |
/** | |
* Is the specified Party key for the Halo? | |
* Only intended to be used by code in this package, not part of the public interface. | |
* @package | |
* @param {PublicKey} partyKey | |
* @return {boolean} | |
*/ | |
isHalo(partyKey: any): boolean; | |
/** | |
* Returns an Array of all known Contacts across all Parties. | |
* @returns {Contact[]} | |
*/ | |
getContacts(): any[]; | |
/** | |
* Creates a Party and admits the initial member using the specified key pairs. | |
* Waits until this node quiesces: the resulting Party object has been fully constructed. | |
* @param {KeyRecord} partyKeyRecord | |
* @param {KeyRecord} admitKeyRecord | |
* @param {Object} props | |
* TODO(telackey): Implement display name. | |
* @property props.deviceDisplayName {string} When creating an Identity halo party, supplies the Device display name. | |
* @return {Party} | |
*/ | |
_createParty(partyKeyRecord: any, admitKeyRecord: any, props?: any): any; | |
/** | |
* Returns true if a writable feed exists for the Party. | |
* @param {PublicKey} partyKey | |
* @return {boolean} | |
* @throws {Error} TODO(dboreham): add details. | |
* @package | |
*/ | |
hasWritableFeed(partyKey: any): boolean; | |
/** | |
* Returns an open, writable feed for a new Party. | |
* hasParty(partyKey) must be false, or else an error is thrown. | |
* @param {PublicKey} partyKey | |
* @return {Feed} | |
* @throws {Error} TODO(dboreham): add details. | |
* @package | |
*/ | |
initWritableFeed(partyKey: any): any; | |
/** | |
* Returns an open, writable feed for the Party. | |
* hasParty(partyKey) must be true, or else an error is thrown. | |
* @param {PublicKey} partyKey | |
* @return {Feed} | |
* @throws {Error} TODO(dboreham): add details. | |
* @package | |
*/ | |
getWritableFeed(partyKey: any): any; | |
/** | |
* Returns an open, writable feed for the Party. | |
* @param {PublicKey} partyKey | |
* @return {Feed} | |
* @throws {Error} TODO(dboreham): add details. | |
* @package | |
*/ | |
_getWritableFeed(partyKey: any): any; | |
/** | |
* Checks whether the PartyManager is in a valid state. | |
*/ | |
_assertValid(): void; | |
/** | |
* Helper adds syntactic sugar for repeated message create, sign, write calls. | |
* @param {Feed} writeFeed | |
* @return {function(...[*]=)} | |
*/ | |
_messageWriterFactory(writeFeed: any): (arg0: [any][] | undefined) => ; | |
/** | |
* Package private method for loading a party initiated by halo message. | |
* If writeFeedAdmitMessage is true, and the Feed is created, a signed FeedAdmit message will be written | |
* to the Feed. This is needed when 'auto-opening' a Party which was joined on another Device. | |
* @package | |
* @param {PublicKey} partyKey | |
* @param {boolean} [writeFeedAdmitMessage=false] | |
* @return {Promise<Party>} | |
*/ | |
initParty(partyKey: any, writeFeedAdmitMessage?: boolean): Promise<any>; | |
/** | |
* Create and initialize a new PartyInfo object for the indicted partyKey. | |
* @param partyKey | |
* @returns {Promise<PartyInfo>} | |
* @private | |
*/ | |
private _initPartyInfo; | |
/** | |
* Copies the IdentityInfo message (if present) into the target Party. | |
* @param {Party} party | |
* @returns {Promise<void>} | |
* @private | |
*/ | |
private _writeIdentityInfo; | |
/** | |
* Creates a PartyProperty object and writes it to the Party. | |
* @param {Party} party | |
* @param {Object} properties | |
* @returns {Promise<string>} | |
* @private | |
*/ | |
private _createPartyPropertiesItem; | |
/** | |
* Writes the JoinedParty informational message to the Halo. | |
* @param {Party} party | |
* @returns {Promise<void>} | |
* @private | |
*/ | |
private _recordPartyJoining; | |
/** | |
* Load information about already known Parties. | |
* Should only be called once, during initialize(). | |
* @returns {Promise<void>} | |
* @private | |
*/ | |
private _loadKnownPartyInfo; | |
/** | |
* Get the PartyProperties item for the indicated Party. | |
* @param {PublicKey} partyKey | |
* @returns {undefined|{PartyProperties}} | |
* @private | |
*/ | |
private _getPartyPropertiesItem; | |
/** | |
* Get the PartySettings item for the indicated Party. | |
* @param {PublicKey} partyKey | |
* @returns {undefined|{PartySettings}} | |
* @private | |
*/ | |
private _getPartySettingsItem; | |
/** | |
* Retrieve the PartyState of the indicated Party. | |
* @param {Party} party | |
* @returns {PartyState} | |
* @private | |
*/ | |
private _getPartyState; | |
/** | |
* Set the PartyState of the indicated Party. | |
* @param {Party} party | |
* @param {PartyState} state | |
* @returns {{before: PartyState, after: PartyState}} | |
* @private | |
*/ | |
private _setPartyState; | |
} | |
export type SecretProvider = any; | |
import { PartyInfo } from "./party-info"; | |
import { PartyProcessor } from "./party-processor"; | |
import { IdentityManager } from "./identity-manager"; | |
import { ContactManager } from "./contact-manager"; | |
import { InvitationDescriptor } from "./invitation-descriptor"; | |
//# sourceMappingURL=party-manager.d.ts.map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment