-
Notifications
You must be signed in to change notification settings - Fork 0
/
electron.env.d.ts
612 lines (535 loc) · 18.3 KB
/
electron.env.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
// noinspection JSUnusedGlobalSymbols
export {} // Make this a module
// This allows TypeScript to pick our custom API
declare global {
namespace versions {
/**
* The version of Node.js
*/
function node(): string
/**
* The version of Chrome
*/
function chrome(): string
/**
* The version of Electron
*/
function electron(): string
}
namespace electron {
/**
* Display information structure
*/
interface Display {
/**
* The unique identifier of the display (for internal use)
*/
id: string
/**
* The name of the display (use this for identification and user-facing purposes)
*/
label: string
/**
* The bounds of the display (in pixels)
*/
bounds: {
x: number
y: number
width: number
height: number
},
/**
* The work area of the display in DIP points.
*/
workArea: {
x: number
y: number
width: number
height: number
},
/**
* The size of the display.
*/
size: {
width: number
height: number
}
/**
* The work area size of the display (in pixels)
*/
workAreaSize: {
width: number
height: number
}
/**
* The scale factor of the display
*/
scaleFactor: number
/**
* The rotation of the display (in degrees)
*/
rotation: number
}
/**
* Oauth2 token structure (mostly via Authorization Code Grant with PKCE)
*/
interface Oauth2Token {
token_type: string
expires_in: number
access_token: string
refresh_token: string | null
expires_at: string
}
/**
* The user object from the id.stream.tv API
*/
interface Own3dUser {
id: string
name: string
avatar_url: string
[key: string]: unknown
}
/**
* Oauth2 credential structure including user information
*/
interface Own3dCredentials extends Oauth2Token {
user: Own3dUser
}
/**
* JSON schema for the `desktop.json` (settings) file
*/
interface Settings {
/**
* The version of the settings schema (diff will force a reset)
*/
version?: string
/**
* The user credentials for the application
*/
credentials?: Own3dCredentials | null
/**
* Whether the application should launch with OBS
*/
launch_with_obs?: boolean
/**
* Whether the developer mode is enabled
*/
developer_mode?: boolean
/**
* Whether the overlay is disabled
*/
overlay_disabled?: boolean
/**
* Whether the overlay is muted
*/
overlay_muted?: boolean
/**
* Global hotkeys for the application
*/
hotkeys?: {
exit: string
}
/**
* The display to use for the overlay
*/
display?: Display | null
/**
* The room identifier for the overlay
*/
room?: string | null
}
/**
* Verified game structure (from the own3d.pro API)
*/
interface VerifiedGame {
/**
* The unique identifier of the game
*/
id: number
/**
* The name of the game
*/
name: string
/**
* The publisher of the game (if available)
*/
publisher: string | null
/**
* Additional setup notes for the game (if available)
*/
notes: string | null
/**
* Whether the game is supported by the overlay
*/
supported: boolean
/**
* Whether the game requires optimization (setting changes)
*/
requires_optimization: boolean
/**
* List of executable names for the game
*/
executables: Array<string>
/**
* The URL to the game's logo (if available)
*/
image_url: string | null
}
/**
* Returns the preload script path which can be used in the webview
*
* @example
* ```typescript
* webview.setAttribute('preload', `file://${await window.electron.preload()}`)
* ```
*/
function preload(): Promise<void>
/**
* Check if the application needs to open the dev tools
*/
function needsDevTools(): Promise<void>
/**
* Get the hostname of the own3d.pro dashboard (for the webview)
*
* @example
* ```typescript
* const hostname = await window.electron.getHostname()
* webview.setAttribute('src', `${hostname}/`)
* ```
*/
function getHostname(): Promise<void>
/**
* Get the current settings of the application
*/
function getSettings(): Promise<Settings>
/**
* Commit the settings to the file
*
* @param settings - The settings to commit
*
* @example
* ```typescript
* // get the current settings
* const settings = await getSettings();
*
* // partial update
* await commitSettings({launch_with_obs: !settings.launch_with_obs});
*
* // full update
* settings.launch_with_obs = !settings.launch_with_obs;
* await commitSettings(settings);
* ```
*/
function commitSettings(settings: Settings): Promise<void>
/**
* Listen for changes to the settings
*
* @param callback - The callback to call when the settings change
*/
function onSettingsChanged(callback: (settings: Settings) => void): void
/**
* Clear the cache of the application.
*/
function clearCache(): Promise<void>
/**
* Toggle the overlay visibility state
*/
function toggleOverlay(): Promise<void>
/**
* Toggle the overlay audio state
*/
function toggleOverlayAudio(): Promise<void>
/**
* Get the list of verified games
*/
function getGames(): Promise<Array<VerifiedGame>>
/**
* Listen for changes to the list of currently played games
*
* @param callback - The callback to call when the list of games change
*/
function onGamesChanged(callback: (games: Array<VerifiedGame>) => void): void
/**
* Get the list of connected displays
*/
function getDisplays(): Promise<Array<Display>>
/**
* Updates the display bounds for the overlay window based on user settings or default display settings
*/
function requestDisplayUpdate(): Promise<void>
/**
* API to interact with the desktop client (window management, authentication, etc.)
*/
namespace desktop {
/**
* Authorization data structure (from the own3d.pro dashboard)
*
* @deprecated This will be replaced by the `magicLogin` flow
*/
interface Authorization {
data: unknown
locale: string
token: string
}
/**
* Close the main window
*/
function closeWindow(): void
/**
* Minimize the main window
*/
function minimizeWindow(): void
/**
* Maximize the main window
*/
function maximizeWindow(): void
/**
* Check if the main window is maximized
*/
function isMaximized(): Promise<boolean>
/**
* Quit the entire application
*/
function quit(): void
/**
* Authenticate the user with the given authorization data
*
* @param authorization - The authorization data to use
*
* @deprecated Use `magicLogin` instead
*/
function authenticate(authorization: Authorization): void
/**
* Get the unique device identifier
*/
function getDeviceId(): Promise<string>
/**
* Tries to authenticate the user using the magic link flow
*
* Our desktop client will open the default browser with the magic link
* and wait for the user to authenticate. Once the user is authenticated,
* the browser will redirect to the desktop client with the access token.
*
* In case of a Timeout, the user shall be informed that they may need
* to try again. Avoid re-calling this function automatically.
*
* @returns The access token from the magic link flow
*
* @throws Error If the URL is not authorized within 2 minutes (timeout)
*
* @example
* ```
* const {access_token} = await window.electron.desktop.magicLogin();
* ```
*/
function magicLogin(): Promise<{ access_token: string }>
/**
* Log the user out of the application
*
* This function behaves like `clearCache()` but also logs the user out
*/
function logout(): void
}
/**
* Beta API to interact with software packages
*/
namespace software {
/**
* Name of the software package
*/
type SoftwareName = 'obs-studio' | 'obs-own3d-desktop-connector';
/**
* Software package information
*/
interface Software {
installed: boolean;
name: SoftwareName;
paths?: {
binary: string;
plugins?: string;
};
}
/**
* Installation progress information
*/
interface InstallProgress {
status: 'downloading' | 'installing';
progress: number;
status_code?: number;
}
/**
* Get the status of a software package
*/
function get(name: SoftwareName): Promise<Software>
/**
* Install a software package (requires admin privileges)
* Throws an error if the software is not installable
*/
function install(
name: SoftwareName,
progressCallback: (progress: InstallProgress) => void,
): Promise<Software>
}
/**
* API (proxy) to interact with obs-websocket
*/
namespace obs {
/**
* obs-websocket request batch options
*/
type RequestBatchOptions = {
/**
* The mode of execution obs-websocket will run the batch in
*/
executionType?: RequestBatchExecutionType;
/**
* Whether obs-websocket should stop executing the batch if one request fails
*/
haltOnFailure?: boolean;
};
/**
* obs-websocket request batch execution type
*/
enum RequestBatchExecutionType {
None = -1,
SerialRealtime = 0,
SerialFrame = 1,
Parallel = 2
}
/**
* obs-websocket request batch request
*/
type RequestBatchRequest<T = keyof unknown> = T extends keyof unknown ? unknown[T] extends never ? {
requestType: T;
requestId?: string;
} : {
requestType: T;
requestId?: string;
requestData: unknown[T];
} : never;
/**
* obs-websocket response message
*/
type ResponseMessage<T = keyof unknown> = T extends keyof unknown ? {
requestType: T;
requestId: string;
requestStatus: {
result: true;
code: number;
} | {
result: false;
code: number;
comment: string;
};
responseData: unknown[T];
} : never;
/**
* Check if the client is connected to obs-websocket
*/
function connected(): Promise<boolean>
/**
* Connects to obs-websocket server.
*
* @param url - The URL to connect to. Defaults to ws://localhost:4444
* @param password - The password to use when connecting
* @param identificationParams - Additional parameters to send when connecting
*
* @example
* ```typescript
* // connect to obs-websocket running on localhost with same port
* await obs.connect();
*
* // Connect to obs-ws running on 192.168.0.4
* await obs.connect('ws://192.168.0.4:4455');
*
* // Connect to localhost with password
* await obs.connect('ws://127.0.0.1:4455', 'super-sekret');
* ```
*/
function connect(url?: string, password?: string, identificationParams?: {}): Promise<any>
/**
* Disconnects from obs-websocket server. This keeps any registered event listeners.
*/
function disconnect(): Promise<void>
/**
* Sending requests to obs-websocket is done via call method.
*
* @param requestType - The request type to send to obs-websocket
* @param requestData - The data to send with the request
*
* @example
* ```typescript
* await obs.call('CreateSceneCollection', {
* sceneCollectionName: 'My Scene Collection',
* });
* ```
*/
function call(requestType: string, requestData?: object): Promise<any>
/**
* Multiple requests can be batched together using the callBatch method.
*
* The full request list is sent over the socket at once, obs-websocket executes the requests based
* on the options provided, then returns the full list of results once all have finished.
*
* @param requests - The list of requests to send to obs-websocket
* @param options - The options to use when executing the batch
*
* @example
* ```typescript
* const results = await obs.callBatch([
* {requestType: 'CreateSceneCollection', requestData: {sceneCollectionName: 'My Scene Collection'}},
* {requestType: 'CreateScene', requestData: {sceneName: 'My Scene'}},
* ]);
* ```
*/
function callBatch(requests: RequestBatchRequest[], options?: RequestBatchOptions): Promise<ResponseMessage[]>
/**
* Enable the obs-websocket server on the local machine.
*
* @throws Error If obs-websocket could not be enabled
*/
function enableWebSocketServer(options?: object): Promise<void>
/**
* Check if the obs-websocket server is enabled on the local machine.
*
* @throws Error If obs-websocket is not installed
*/
function isWebSocketServerEnabled(): Promise<boolean>
/**
* Register an event listener for obs-websocket events.
*
* @param event - The event to listen for
* @param handler - The function to call when the event is emitted
*/
function on(event: string, handler: Function): void
/**
* Register an event listener for obs-websocket events that will only be called once.
*
* @param event - The event to listen for
* @param handler - The function to call when the event is emitted
*/
function once(event: string, handler: Function): void
/**
* Remove an event listener for obs-websocket events.
*
* @param event - The event to remove the listener from
* @param handler - The function to remove from the event
*/
function off(event: string, handler: Function): void
/**
* Register an event listener for obs-websocket events.
*
* @param event - The event to listen for
* @param handler - The function to call when the event is emitted
*/
function addListener(event: string, handler: Function): void
/**
* Remove an event listener for obs-websocket events.
*
* @param event - The event to remove the listener from
* @param handler - The function to remove from the event
*/
function removeListener(event: string, handler: Function): void
}
}
}