|
1 | 1 | import { EventEmitter } from 'events';
|
| 2 | +import { URL } from 'url'; |
| 3 | +import fs from 'fs'; |
2 | 4 | import http from 'http';
|
3 | 5 | import querystring from 'querystring';
|
4 | 6 |
|
@@ -95,7 +97,7 @@ type StatusStopped = StatusBase & {
|
95 | 97 |
|
96 | 98 | type Status = StatusPaused | StatusPlaying | StatusStopped;
|
97 | 99 |
|
98 |
| -const enum CommandScope { |
| 100 | +enum CommandScope { |
99 | 101 | BROWSE = '/requests/browse.json',
|
100 | 102 | STATUS = '/requests/status.json',
|
101 | 103 | PLAYLIST = '/requests/playlist.json'
|
@@ -144,6 +146,16 @@ type Playlist = PlaylistNode | PlaylistLeaf;
|
144 | 146 | const waitFor = (ms: number): Promise<void> =>
|
145 | 147 | new Promise(resolve => setTimeout(resolve, ms));
|
146 | 148 |
|
| 149 | +const pathlikeToString = (path: fs.PathLike) => { |
| 150 | + if (Buffer.isBuffer(path)) { |
| 151 | + return path.toString('utf8'); |
| 152 | + } else if (path instanceof URL) { |
| 153 | + return path.href; |
| 154 | + } |
| 155 | + |
| 156 | + return path; |
| 157 | +}; |
| 158 | + |
147 | 159 | export type VLCOptions = {
|
148 | 160 | host?: string;
|
149 | 161 | port?: number;
|
@@ -240,7 +252,7 @@ function equal(a: any, b: any) {
|
240 | 252 | return true;
|
241 | 253 | }
|
242 | 254 |
|
243 |
| - return false |
| 255 | + return false; |
244 | 256 | }
|
245 | 257 |
|
246 | 258 | export class VLC extends EventEmitter {
|
@@ -437,30 +449,30 @@ export class VLC extends EventEmitter {
|
437 | 449 | * Add `uri` to playlist and start playback.
|
438 | 450 | */
|
439 | 451 | public addToQueueAndPlay(
|
440 |
| - uri: string, |
| 452 | + uri: fs.PathLike, |
441 | 453 | option?: 'noaudio' | 'novideo'
|
442 | 454 | ): Promise<Status> {
|
443 |
| - const options = { |
444 |
| - input: uri, |
| 455 | + return this._sendCommand(CommandScope.STATUS, 'in_play', { |
| 456 | + input: pathlikeToString(uri), |
445 | 457 | option
|
446 |
| - }; |
447 |
| - |
448 |
| - return this._sendCommand(CommandScope.STATUS, 'in_play', options); |
| 458 | + }); |
449 | 459 | }
|
450 | 460 |
|
451 | 461 | /**
|
452 | 462 | * Add `uri` to playlist.
|
453 | 463 | */
|
454 |
| - public addToQueue(uri: string): Promise<Status> { |
455 |
| - return this._sendCommand(CommandScope.STATUS, 'in_enqueue', { input: uri }); |
| 464 | + public addToQueue(uri: fs.PathLike): Promise<Status> { |
| 465 | + return this._sendCommand(CommandScope.STATUS, 'in_enqueue', { |
| 466 | + input: pathlikeToString(uri) |
| 467 | + }); |
456 | 468 | }
|
457 | 469 |
|
458 | 470 | /**
|
459 | 471 | * Add subtitle to currently playing file.
|
460 | 472 | */
|
461 |
| - public addSubtitle(uri: string): Promise<Status> { |
| 473 | + public addSubtitle(uri: fs.PathLike): Promise<Status> { |
462 | 474 | return this._sendCommand(CommandScope.STATUS, 'addsubtitle', {
|
463 |
| - input: uri |
| 475 | + input: pathlikeToString(uri) |
464 | 476 | });
|
465 | 477 | }
|
466 | 478 |
|
|
0 commit comments