Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit e862328

Browse files
committed
Add extracted typings from nodecg v1.8.1
These are the typings as of nodecg/nodecg@e3dbf8d which is the commit tagged as `v1.8.1`.
1 parent b6c0bc7 commit e862328

File tree

17 files changed

+518
-0
lines changed

17 files changed

+518
-0
lines changed

types/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Alex Van Camp, Matthew McNamara, and contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

types/browser.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {NodeCGStaticBrowser} from './lib/nodecg-static';
2+
import {NodeCGBrowser} from './lib/nodecg-instance';
3+
4+
declare global {
5+
export const nodecg: NodeCGBrowser;
6+
export const NodeCG: NodeCGStaticBrowser;
7+
export interface Window { nodecg: NodeCGBrowser, NodeCG: NodeCGStaticBrowser }
8+
}
9+
10+
export {NodeCGStaticBrowser, NodeCGBrowser};
11+
export * from './lib/config';
12+
export * from './lib/logger';
13+
export * from './lib/replicant';

types/lib/config.d.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {LoggerOptions} from './logger';
2+
3+
/**
4+
* NodeCG config exposed in extensions and browser
5+
*/
6+
export interface NodeCGConfig {
7+
host: string;
8+
port: number;
9+
developer: boolean;
10+
baseURL: string;
11+
logging: LoggerOptions;
12+
sentry: {
13+
enabled?: boolean;
14+
publicDsn?: string;
15+
};
16+
login: {
17+
enabled?: boolean;
18+
local?: {
19+
enabled: boolean;
20+
};
21+
steam?: {
22+
enabled: boolean;
23+
};
24+
twitch?: {
25+
enabled: boolean;
26+
clientID: string;
27+
scope: string;
28+
};
29+
};
30+
ssl?: {
31+
enabled: boolean;
32+
};
33+
}

types/lib/logger.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export class Logger {
2+
constructor(name: string);
3+
trace(...args: any[]): void;
4+
debug(...args: any[]): void;
5+
info(...args: any[]): void;
6+
warn(...args: any[]): void;
7+
error(...args: any[]): void;
8+
replicants(...args: any[]): void;
9+
static globalReconfigure(
10+
opts: LoggerOptions & {file: {path: string}}
11+
): void;
12+
}
13+
14+
/**
15+
* Options used for Logger constructor
16+
*/
17+
export interface LoggerOptions {
18+
replicants?: boolean;
19+
console?: {
20+
enabled: boolean;
21+
timestamps: boolean;
22+
level: LoggerLevel;
23+
};
24+
file?: {
25+
enabled: boolean;
26+
timestamps: boolean;
27+
level: LoggerLevel;
28+
};
29+
}
30+
31+
/**
32+
* NodeCG logger level enum
33+
*/
34+
export type LoggerLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error';

types/lib/nodecg-instance.d.ts

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/// <reference lib="dom" />
2+
/// <reference types="node" />
3+
/// <reference types="socket.io" />
4+
/// <reference types="socket.io-client" />
5+
/// <reference types="soundjs" />
6+
7+
import {RequestHandler, Router, RouterOptions} from 'express';
8+
9+
import {Logger} from './logger';
10+
import {ReplicantOptions, Replicant} from './replicant';
11+
import {NodeCGConfig} from './config';
12+
import {SendMessageToBundle, SendMessageReturnType} from './nodecg-static';
13+
import {Platform} from './platform';
14+
15+
interface NodeCGCommon<P extends Platform, M = SendMessageReturnType<P>> {
16+
bundleName: string;
17+
bundleConfig: any;
18+
bundleVersion: string;
19+
readonly bundleGit: {
20+
branch: string;
21+
hash: string;
22+
shortHash: string;
23+
date?: Date;
24+
message?: string;
25+
};
26+
Logger: typeof Logger;
27+
log: Logger;
28+
readonly config: NodeCGConfig;
29+
sendMessage(
30+
messageName: string,
31+
cb?: (error: any, ...args: any[]) => void
32+
): M;
33+
sendMessage(
34+
messageName: string,
35+
data: any,
36+
cb?: (error: any, ...args: any[]) => void
37+
): M;
38+
sendMessageToBundle: SendMessageToBundle<P, M>;
39+
listenFor(messageName: string, handlerFunc: (message: any) => void): void;
40+
listenFor(
41+
messageName: string,
42+
bundleName: string,
43+
handlerFunc: (message: any) => void
44+
): void;
45+
unlisten(messageName: string, handlerFunc: (message: any) => void): void;
46+
unlisten(
47+
messageName: string,
48+
bundleName: string,
49+
handlerFunc: (message: any) => void
50+
): void;
51+
Replicant<V>(name: string, opts?: ReplicantOptions<V>): Replicant<V, P>;
52+
Replicant<V>(
53+
name: string,
54+
namespace: string,
55+
opts?: ReplicantOptions<V>
56+
): Replicant<V, P>;
57+
}
58+
59+
/**
60+
* NodeCG instance in extensions
61+
*/
62+
export interface NodeCGServer extends NodeCGCommon<'server'> {
63+
getSocketIOServer(): SocketIO.Server;
64+
Router(options?: RouterOptions): Router;
65+
mount: Router['use'];
66+
util: {
67+
authCheck: RequestHandler;
68+
};
69+
extensions: {
70+
[bundleName: string]: (nodecg: NodeCGServer) => void;
71+
};
72+
listenFor(
73+
messageName: string,
74+
handlerFunc: (message: any, cb?: ListenForCb) => void
75+
): void;
76+
listenFor(
77+
messageName: string,
78+
bundleName: string,
79+
handlerFunc: (message: any, cb?: ListenForCb) => void
80+
): void;
81+
}
82+
83+
/**
84+
* NodeCG instance in browser
85+
*/
86+
export interface NodeCGBrowser extends NodeCGCommon<'browser'> {
87+
socket: SocketIOClient.Socket;
88+
soundReady?: boolean;
89+
getDialog(
90+
name: string,
91+
bundle?: string
92+
): ReturnType<ParentNode['querySelector']>;
93+
getDialogDocument(name: string, bundle?: string): Document;
94+
findCue(cueName: string): Cue | undefined;
95+
playSound(
96+
cueName: string,
97+
opts?: {updateVolume?: boolean}
98+
): createjs.AbstractSoundInstance;
99+
stopSound(cueName: string): void;
100+
stopAllSounds(): void;
101+
readReplicant<V>(name: string, cb: (value: V) => void): void;
102+
readReplicant<V>(
103+
name: string,
104+
namespace: string,
105+
cb: (value: V) => void
106+
): void;
107+
}
108+
109+
/**
110+
* NodeCG instance combined
111+
*/
112+
export type NodeCG<P extends Platform> = P extends 'server'
113+
? NodeCGServer
114+
: NodeCGBrowser;
115+
116+
/**
117+
* Sound cue object
118+
*/
119+
interface Cue {
120+
name: string;
121+
assignable: boolean;
122+
defaultFile: string;
123+
}
124+
125+
export type ListenForCb = HandledListenForCb | UnhandledListenForCb;
126+
127+
interface HandledListenForCb {
128+
handled: true;
129+
}
130+
131+
interface UnhandledListenForCb {
132+
(...args: any[]): void;
133+
handled: false;
134+
}

types/lib/nodecg-static.d.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import {
2+
Replicant,
3+
ReplicantOptions,
4+
DeclaredReplicants,
5+
ReplicantBrowser,
6+
} from './replicant';
7+
import {NodeCG} from './nodecg-instance';
8+
import {Platform} from './platform';
9+
10+
/**
11+
* NodeCG constructor
12+
*/
13+
interface NodeCGStaticCommon<P extends Platform, R = Replicant<any, P>> {
14+
new (bundle: any, socket: SocketIOClient.Socket): NodeCG<P>;
15+
version: string;
16+
sendMessageToBundle: SendMessageToBundle<P>;
17+
declaredReplicants: DeclaredReplicants<P>;
18+
Replicant<V>(name: string, opts?: ReplicantOptions<V>): Replicant<V, P>;
19+
Replicant<V>(
20+
name: string,
21+
namespace?: string,
22+
opts?: ReplicantOptions<V>
23+
): Replicant<V, P>;
24+
}
25+
26+
/**
27+
* NodeCG constructor in extensions
28+
*/
29+
export interface NodeCGStaticServer extends NodeCGStaticCommon<'server'> {
30+
readReplicant<V>(name: string, namespace?: string): void;
31+
}
32+
33+
/**
34+
* NodeCG constructor in browser
35+
*/
36+
export interface NodeCGStaticBrowser extends NodeCGStaticCommon<'browser'> {
37+
readReplicant<V>(name: string, cb: (value: V) => void): void;
38+
readReplicant<V>(
39+
name: string,
40+
namespace: string,
41+
cb: (value: V) => void
42+
): void;
43+
waitForReplicants(...replicants: ReplicantBrowser<any>[]): Promise<void>;
44+
}
45+
46+
/**
47+
* NodeCG constructor combined
48+
*/
49+
export type NodeCGStatic<P extends Platform> = P extends 'server'
50+
? NodeCGStaticServer
51+
: NodeCGStaticBrowser;
52+
53+
/**
54+
* sendMessage returns Promise in browser, void in extensions
55+
*/
56+
type SendMessageReturnType<P extends Platform> = P extends 'server'
57+
? void
58+
: Promise<any>;
59+
60+
/**
61+
* Combined 'sendMessageToBundle' method for browser and extensions
62+
*/
63+
interface SendMessageToBundle<
64+
P extends Platform,
65+
M = SendMessageReturnType<P>
66+
> {
67+
(
68+
messageName: string,
69+
bundleName: string,
70+
cb?: (error: any, ...args: any[]) => void
71+
): M;
72+
(
73+
messageName: string,
74+
bundleName: string,
75+
data: any,
76+
cb?: (error: any, ...args: any[]) => void
77+
): M;
78+
}

types/lib/platform.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Used to select types for browser API or extensions API
3+
*/
4+
export type Platform = 'server' | 'browser';

0 commit comments

Comments
 (0)