@nodecg/types
Version:
Dynamic broadcast graphics rendered in a browser
162 lines (161 loc) • 7.14 kB
TypeScript
import { i as TypedClientSocket, t as NodeCG } from "../../nodecg.js";
import { n as AbstractReplicant, r as ReplicantValue } from "../../replicants.shared.js";
import "../../logger-interface.js";
import { n as NodeCGAPIBase } from "../../api.base.js";
import { DeepReadonly } from "ts-essentials";
//#region src/client/api/config.d.ts
declare const filteredConfig: NodeCG.FilteredConfig;
//#endregion
//#region src/client/api/replicant.d.ts
declare class ClientReplicant<V, O extends NodeCG.Replicant.Options<V> = NodeCG.Replicant.Options<V>> extends AbstractReplicant<"client", V, O> {
value: ReplicantValue<"client", V, O>;
/**
* When running in the browser, we have to wait until the socket joins the room
* and the replicant is fully declared before running any additional commands.
* After this time, commands do not need to be added to the queue and are simply executed immediately.
*/
private _actionQueue;
private readonly _socket;
constructor(name: string, namespace: string, opts: O, socket?: TypedClientSocket);
/**
* A map of all Replicants declared in this context. Top-level keys are namespaces,
* child keys are Replicant names.
*/
static get declaredReplicants(): Record<string, Record<string, ClientReplicant<unknown>>>;
/**
* Adds an operation to the operation queue, to be flushed at the end of the current tick.
* @param path {string} - The object path to where this operation took place.
* @param method {string} - The name of the operation.
* @param args {array} - The arguments provided to this operation
* @private
*/
_addOperation(operation: NodeCG.Replicant.Operation<ReplicantValue<"client", V, O>>): void;
/**
* Emits all queued operations via Socket.IO & empties this._operationQueue.
* @private
*/
_flushOperations(): void;
/**
* Adds an "action" to the action queue. Actions are method calls on the Replicant object itself.
* @param fn
* @param args
* @private
*/
private _queueAction;
/**
* Emits "declareReplicant" via the socket.
* @private
*/
private _declare;
/**
* Overwrites the value completely, and assigns a new one.
* @param newValue {*} - The value to assign.
* @param revision {number} - The new revision number.
* @private
*/
private _assignValue;
/**
* Handles incoming operations performed on Array and Object Replicants.
* Requests a fullUpdate if it determines that we're not at the latest revision of this Replicant.
* @param data {object} - A record of operations to perform.
* @private
*/
private _handleOperations;
private _handleDisconnect;
/**
* Requests the latest value from the Replicator, discarding the local value.
* @private
*/
private _fullUpdate;
}
//#endregion
//#region src/client/api/api.client.d.ts
type SendMessageCb<T> = (error?: unknown, response?: T) => void;
type ReadReplicantCb<T = unknown> = (value: T | undefined) => void;
interface EventMap {}
declare class NodeCGAPIClient<C extends Record<string, any> = NodeCG.Bundle.UnknownConfig> extends NodeCGAPIBase<"client", C, EventMap> {
static Replicant<V, O extends NodeCG.Replicant.Options<V> = NodeCG.Replicant.Options<V>>(name: string, namespace: string, opts?: O): ClientReplicant<V, O>;
static sendMessageToBundle<T = unknown>(messageName: string, bundleName: string, cb: SendMessageCb<T>): void;
static sendMessageToBundle<T = unknown>(messageName: string, bundleName: string, data?: unknown): Promise<T>;
static sendMessageToBundle<T = unknown>(messageName: string, bundleName: string, data: unknown, cb: SendMessageCb<T>): void;
static readReplicant<T = unknown>(name: string, namespace: string, cb: ReadReplicantCb<T>): void;
get Logger(): new (name: string) => NodeCG.Logger;
get log(): NodeCG.Logger;
/**
* A filtered copy of the NodeCG server config with some sensitive keys removed.
*/
get config(): DeepReadonly<typeof filteredConfig>;
readonly socket: TypedClientSocket;
soundsReady: boolean;
private readonly _soundFiles?;
private readonly _bundleVolume?;
private readonly _masterVolume?;
private _soundCues;
private _memoizedLogger?;
constructor(bundle: NodeCG.Bundle & {
_hasSounds?: boolean;
}, socket: TypedClientSocket);
/**
* _Browser only, except workers_<br/>
* Returns the specified dialog element.
* @param {string} name - The desired dialog's name.
* @param {string} [bundle=CURR_BNDL] - The bundle from which to select the dialog.
* @returns {object}
*/
getDialog(name: string, bundle?: string): (HTMLElement & {
opened: boolean;
close: () => void;
open: () => void;
}) | undefined;
/**
* _Browser only, except workers_<br/>
* Returns the specified dialog's iframe document.
* @param {string} name - The desired dialog's name.
* @param {string} [bundle=CURR_BNDL] - The bundle from which to select the dialog.
* @returns {object}
*/
getDialogDocument(name: string, bundle?: string): Document | undefined;
/**
* Returns the sound cue of the provided `cueName` in the current bundle.
* Returns undefined if a cue by that name cannot be found in this bundle.
*/
findCue(cueName: string): NodeCG.SoundCue | undefined;
/**
* Plays the sound cue of the provided `cueName` in the current bundle.
* Does nothing if the cue doesn't exist or if the cue has no assigned file to play.
* @param cueName {String}
* @param [opts] {Object}
* @param [opts.updateVolume=true] - Whether or not to let NodeCG automatically update this instance's volume
* when the user changes it on the dashboard.
* @returns {Object|undefined} - A SoundJS AbstractAudioInstance.
*/
playSound(cueName: string, {
updateVolume
}?: {
updateVolume: boolean;
}): createjs.AbstractSoundInstance;
/**
* Stops all currently playing instances of the provided `cueName`.
* @param cueName {String}
*/
stopSound(cueName: string): void;
/**
* Stops all currently playing sounds on the page.
*/
stopAllSounds(): void;
sendMessageToBundle<T = unknown>(messageName: string, bundleName: string, cb: SendMessageCb<T>): void;
sendMessageToBundle<T = unknown>(messageName: string, bundleName: string, data?: unknown): Promise<T>;
sendMessageToBundle<T = unknown>(messageName: string, bundleName: string, data: unknown, cb: SendMessageCb<T>): void;
sendMessage<T = unknown>(messageName: string, cb: SendMessageCb<T>): void;
sendMessage<T = unknown>(messageName: string, data?: unknown): Promise<T>;
sendMessage<T = unknown>(messageName: string, data: unknown, cb: SendMessageCb<T>): void;
readReplicant<T = unknown>(name: string, cb: ReadReplicantCb<T>): void;
readReplicant<T = unknown>(name: string, namespace: string, cb: ReadReplicantCb<T>): void;
protected _replicantFactory: <V, O extends NodeCG.Replicant.Options<V> = NodeCG.Replicant.Options<V>>(name: string, namespace: string, opts: O) => ClientReplicant<V, O>;
private _registerSounds;
private _setInstanceVolume;
private _updateInstanceVolumes;
}
//#endregion
export { NodeCGAPIClient };
//# sourceMappingURL=api.client.d.ts.map