@mux/cli 0.8.0 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +1216 -259
- package/bin/mux +31 -0
- package/package.json +64 -103
- package/bin/run +0 -6
- package/bin/run.cmd +0 -3
- package/lib/command-bases/asset-base.d.ts +0 -11
- package/lib/command-bases/asset-base.js +0 -41
- package/lib/command-bases/base.d.ts +0 -14
- package/lib/command-bases/base.js +0 -62
- package/lib/command-bases/live-base.d.ts +0 -11
- package/lib/command-bases/live-base.js +0 -31
- package/lib/commands/assets/create.d.ts +0 -10
- package/lib/commands/assets/create.js +0 -64
- package/lib/commands/assets/upload.d.ts +0 -20
- package/lib/commands/assets/upload.js +0 -148
- package/lib/commands/init.d.ts +0 -20
- package/lib/commands/init.js +0 -115
- package/lib/commands/live/complete.d.ts +0 -12
- package/lib/commands/live/complete.js +0 -54
- package/lib/commands/live/disable.d.ts +0 -13
- package/lib/commands/live/disable.js +0 -40
- package/lib/commands/live/enable.d.ts +0 -13
- package/lib/commands/live/enable.js +0 -40
- package/lib/commands/sign.d.ts +0 -11
- package/lib/commands/sign.js +0 -68
- package/lib/commands/spaces/sign.d.ts +0 -11
- package/lib/commands/spaces/sign.js +0 -79
- package/lib/config.d.ts +0 -10
- package/lib/config.js +0 -12
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -7
- package/oclif.manifest.json +0 -1
- package/src/command-bases/asset-base.ts +0 -52
- package/src/command-bases/base.ts +0 -72
- package/src/command-bases/live-base.ts +0 -35
- package/src/commands/assets/create.ts +0 -74
- package/src/commands/assets/upload.ts +0 -192
- package/src/commands/init.ts +0 -150
- package/src/commands/live/complete.ts +0 -63
- package/src/commands/live/disable.ts +0 -47
- package/src/commands/live/enable.ts +0 -47
- package/src/commands/sign.ts +0 -76
- package/src/commands/spaces/sign.ts +0 -90
- package/src/config.ts +0 -13
- package/src/index.ts +0 -3
- package/yarn.lock +0 -7350
package/lib/commands/init.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const mux_node_1 = require("@mux/mux-node");
|
|
4
|
-
const command_1 = require("@oclif/command");
|
|
5
|
-
const chalk = require("chalk");
|
|
6
|
-
const dotenv = require("dotenv");
|
|
7
|
-
const fs = require("fs-extra");
|
|
8
|
-
const inquirer = require("inquirer");
|
|
9
|
-
const path = require("path");
|
|
10
|
-
const base_1 = require("../command-bases/base");
|
|
11
|
-
class Init extends base_1.default {
|
|
12
|
-
constructor() {
|
|
13
|
-
super(...arguments);
|
|
14
|
-
this.muxConfig = {};
|
|
15
|
-
}
|
|
16
|
-
async run() {
|
|
17
|
-
const { args, flags } = this.parse(Init);
|
|
18
|
-
let prompts = [];
|
|
19
|
-
if (args.envFile) {
|
|
20
|
-
const envFile = path.resolve(args.envFile);
|
|
21
|
-
const env = dotenv.config({ path: envFile });
|
|
22
|
-
if (env.error) {
|
|
23
|
-
this.error(`Unable to load env file: ${envFile}`);
|
|
24
|
-
}
|
|
25
|
-
else if (env.parsed) {
|
|
26
|
-
this.log(chalk `Loaded your Mux .env file! Using token with id: {blue ${env.parsed.MUX_TOKEN_ID}}`);
|
|
27
|
-
process.env.MUX_TOKEN_ID = env.parsed.MUX_TOKEN_ID;
|
|
28
|
-
process.env.MUX_TOKEN_SECRET = env.parsed.MUX_TOKEN_SECRET;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
prompts = [
|
|
33
|
-
{
|
|
34
|
-
name: 'tokenId',
|
|
35
|
-
message: "What's your token ID?",
|
|
36
|
-
type: 'string',
|
|
37
|
-
default: process.env.MUX_TOKEN_ID,
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: 'tokenSecret',
|
|
41
|
-
message: "What's your token secret?",
|
|
42
|
-
type: 'password',
|
|
43
|
-
default: process.env.MUX_TOKEN_SECRET,
|
|
44
|
-
},
|
|
45
|
-
];
|
|
46
|
-
}
|
|
47
|
-
if (!flags.force && (await fs.pathExists(this.configFile))) {
|
|
48
|
-
this.log(chalk `{bold.underline.red You are attempting to initialize with an existing configuration file!} If this is intentional, please pass {bold.yellow --force}.`);
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
|
-
const signingKeyPrompt = {
|
|
52
|
-
name: 'createSigningKey',
|
|
53
|
-
message: 'Do you want to go ahead and set up a Signing Key? This is used to create tokens for signed playback policies.',
|
|
54
|
-
type: 'confirm',
|
|
55
|
-
};
|
|
56
|
-
if (process.env.MUX_SIGNING_KEY || process.env.MUX_PRIVATE_KEY) {
|
|
57
|
-
signingKeyPrompt.message =
|
|
58
|
-
'Looks like you already have a signing key configured. Would you like to create a new one?';
|
|
59
|
-
}
|
|
60
|
-
prompts = [...prompts, signingKeyPrompt];
|
|
61
|
-
const answers = await inquirer.prompt(prompts);
|
|
62
|
-
let { createSigningKey, tokenId, tokenSecret } = answers;
|
|
63
|
-
// If the token was loaded from an env file they'll already be set in the appropriate environment variables and
|
|
64
|
-
// the prompts themselves will be null.
|
|
65
|
-
this.muxConfig.configVersion = 1;
|
|
66
|
-
this.muxConfig.tokenId = process.env.MUX_TOKEN_ID = tokenId || process.env.MUX_TOKEN_ID;
|
|
67
|
-
this.muxConfig.tokenSecret = process.env.MUX_TOKEN_SECRET = tokenSecret || process.env.MUX_TOKEN_SECRET;
|
|
68
|
-
if (createSigningKey) {
|
|
69
|
-
const { Video } = new mux_node_1.default();
|
|
70
|
-
try {
|
|
71
|
-
// this is not great; we need to also update mux-node for this call
|
|
72
|
-
// but that's a bigger can of worms. We'll come back to this one.
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
const { id, private_key } = await Video.SigningKeys.create();
|
|
75
|
-
this.muxConfig.signingKeyId = process.env.MUX_SIGNING_KEY = id;
|
|
76
|
-
this.muxConfig.signingKeySecret = process.env.MUX_PRIVATE_KEY = private_key;
|
|
77
|
-
}
|
|
78
|
-
catch (_a) {
|
|
79
|
-
this.error("Couldn't create a signing key pair! Are you sure your token credentials were right?");
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
try {
|
|
83
|
-
await fs.ensureDir(this.config.configDir);
|
|
84
|
-
await fs.writeFile(this.configFile, JSON.stringify(this.muxConfig), 'utf8');
|
|
85
|
-
}
|
|
86
|
-
catch (err) {
|
|
87
|
-
// TODO: improve error handling type safety here
|
|
88
|
-
if (err instanceof Error) {
|
|
89
|
-
this.error(err);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
throw err;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
this.log(chalk `{bold.underline Configuration written to:} ${this.configFile}`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.default = Init;
|
|
99
|
-
Init.description = 'set up a user-level config';
|
|
100
|
-
Init.args = [
|
|
101
|
-
{
|
|
102
|
-
name: 'envFile',
|
|
103
|
-
required: false,
|
|
104
|
-
description: 'path to a Mux access token .env file',
|
|
105
|
-
parse: (input) => path.resolve(input),
|
|
106
|
-
},
|
|
107
|
-
];
|
|
108
|
-
Init.flags = {
|
|
109
|
-
force: command_1.flags.boolean({
|
|
110
|
-
name: 'force',
|
|
111
|
-
char: 'f',
|
|
112
|
-
description: 'Will initialize a new file even if one already exists.',
|
|
113
|
-
default: false,
|
|
114
|
-
}),
|
|
115
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { IFlag } from '@oclif/command/lib/flags';
|
|
2
|
-
import LiveCommandBase from '../../command-bases/live-base';
|
|
3
|
-
export default class LiveComplete extends LiveCommandBase {
|
|
4
|
-
static description: string;
|
|
5
|
-
static args: {
|
|
6
|
-
name: string;
|
|
7
|
-
description: string;
|
|
8
|
-
required: boolean;
|
|
9
|
-
}[];
|
|
10
|
-
static flags: Record<string, IFlag<any>>;
|
|
11
|
-
run(): Promise<void>;
|
|
12
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const Listr = require("listr");
|
|
4
|
-
const command_1 = require("@oclif/command");
|
|
5
|
-
const live_base_1 = require("../../command-bases/live-base");
|
|
6
|
-
const chalk = require("chalk");
|
|
7
|
-
class LiveComplete extends live_base_1.default {
|
|
8
|
-
async run() {
|
|
9
|
-
const { args, flags } = this.parse(LiveComplete);
|
|
10
|
-
const streamId = this.getStreamId(flags, args.streamName);
|
|
11
|
-
try {
|
|
12
|
-
await (new Listr([
|
|
13
|
-
{
|
|
14
|
-
title: `Signaling completion of '${streamId}'`,
|
|
15
|
-
task: async (ctx, task) => {
|
|
16
|
-
await this.Video.LiveStreams.signalComplete(streamId),
|
|
17
|
-
task.title = `${task.title} (OK)`;
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
title: `Disabling '${streamId}'`,
|
|
22
|
-
enabled: () => flags.disableAfterCompletion,
|
|
23
|
-
task: async (ctx, task) => {
|
|
24
|
-
await this.Video.LiveStreams.disable(streamId);
|
|
25
|
-
task.title = `${task.title} (OK)`;
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
], {}).run());
|
|
29
|
-
}
|
|
30
|
-
catch (err) {
|
|
31
|
-
// TODO: make this clearer
|
|
32
|
-
console.log(chalk.redBright('Error:') +
|
|
33
|
-
"\n\n" +
|
|
34
|
-
err);
|
|
35
|
-
if (err instanceof Error) {
|
|
36
|
-
this.error(err);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
throw err;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.default = LiveComplete;
|
|
45
|
-
LiveComplete.description = "Signal to Mux that a live stream has concluded and should be closed.";
|
|
46
|
-
LiveComplete.args = [
|
|
47
|
-
...live_base_1.default.argsForSingleLiveStream,
|
|
48
|
-
];
|
|
49
|
-
LiveComplete.flags = Object.assign(Object.assign({}, live_base_1.default.flagsForSingleLiveStream), { disableAfterCompletion: command_1.flags.boolean({
|
|
50
|
-
name: 'disable-after-completion',
|
|
51
|
-
char: 'd',
|
|
52
|
-
description: 'If set, disables the stream upon completion.',
|
|
53
|
-
default: false,
|
|
54
|
-
}) });
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import LiveCommandBase from '../../command-bases/live-base';
|
|
2
|
-
export default class LiveDisable extends LiveCommandBase {
|
|
3
|
-
static description: string;
|
|
4
|
-
static args: {
|
|
5
|
-
name: string;
|
|
6
|
-
description: string;
|
|
7
|
-
required: boolean;
|
|
8
|
-
}[];
|
|
9
|
-
static flags: {
|
|
10
|
-
[x: string]: import("@oclif/command/lib/flags").IFlag<any>;
|
|
11
|
-
};
|
|
12
|
-
run(): Promise<void>;
|
|
13
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const Listr = require("listr");
|
|
4
|
-
const live_base_1 = require("../../command-bases/live-base");
|
|
5
|
-
const chalk = require("chalk");
|
|
6
|
-
class LiveDisable extends live_base_1.default {
|
|
7
|
-
async run() {
|
|
8
|
-
const { args, flags } = this.parse(LiveDisable);
|
|
9
|
-
const streamId = this.getStreamId(flags, args.streamName);
|
|
10
|
-
try {
|
|
11
|
-
await (new Listr([
|
|
12
|
-
{
|
|
13
|
-
title: `Disabling '${streamId}'`,
|
|
14
|
-
task: async (ctx, task) => {
|
|
15
|
-
await this.Video.LiveStreams.disable(streamId);
|
|
16
|
-
task.title = `${task.title} (OK)`;
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
], {}).run());
|
|
20
|
-
}
|
|
21
|
-
catch (err) {
|
|
22
|
-
// TODO: make this clearer
|
|
23
|
-
console.log(chalk.redBright('Error:') +
|
|
24
|
-
"\n\n" +
|
|
25
|
-
err);
|
|
26
|
-
if (err instanceof Error) {
|
|
27
|
-
this.error(err);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
throw err;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.default = LiveDisable;
|
|
36
|
-
LiveDisable.description = "Disables a live stream and prevents encoders from streaming to it.";
|
|
37
|
-
LiveDisable.args = [
|
|
38
|
-
...live_base_1.default.argsForSingleLiveStream,
|
|
39
|
-
];
|
|
40
|
-
LiveDisable.flags = Object.assign({}, live_base_1.default.flagsForSingleLiveStream);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import LiveCommandBase from '../../command-bases/live-base';
|
|
2
|
-
export default class LiveEnable extends LiveCommandBase {
|
|
3
|
-
static description: string;
|
|
4
|
-
static args: {
|
|
5
|
-
name: string;
|
|
6
|
-
description: string;
|
|
7
|
-
required: boolean;
|
|
8
|
-
}[];
|
|
9
|
-
static flags: {
|
|
10
|
-
[x: string]: import("@oclif/command/lib/flags").IFlag<any>;
|
|
11
|
-
};
|
|
12
|
-
run(): Promise<void>;
|
|
13
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const Listr = require("listr");
|
|
4
|
-
const live_base_1 = require("../../command-bases/live-base");
|
|
5
|
-
const chalk = require("chalk");
|
|
6
|
-
class LiveEnable extends live_base_1.default {
|
|
7
|
-
async run() {
|
|
8
|
-
const { args, flags } = this.parse(LiveEnable);
|
|
9
|
-
const streamId = this.getStreamId(flags, args.streamName);
|
|
10
|
-
try {
|
|
11
|
-
await (new Listr([
|
|
12
|
-
{
|
|
13
|
-
title: `Enabling '${streamId}'`,
|
|
14
|
-
task: async (ctx, task) => {
|
|
15
|
-
await this.Video.LiveStreams.enable(streamId);
|
|
16
|
-
task.title = `${task.title} (OK)`;
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
], {}).run());
|
|
20
|
-
}
|
|
21
|
-
catch (err) {
|
|
22
|
-
// TODO: make this clearer
|
|
23
|
-
console.log(chalk.redBright('Error:') +
|
|
24
|
-
"\n\n" +
|
|
25
|
-
err);
|
|
26
|
-
if (err instanceof Error) {
|
|
27
|
-
this.error(err);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
throw err;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.default = LiveEnable;
|
|
36
|
-
LiveEnable.description = "Enables a live stream, allowing encoders to streaming to it.";
|
|
37
|
-
LiveEnable.args = [
|
|
38
|
-
...live_base_1.default.argsForSingleLiveStream,
|
|
39
|
-
];
|
|
40
|
-
LiveEnable.flags = Object.assign({}, live_base_1.default.flagsForSingleLiveStream);
|
package/lib/commands/sign.d.ts
DELETED
package/lib/commands/sign.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const command_1 = require("@oclif/command");
|
|
4
|
-
const chalk = require("chalk");
|
|
5
|
-
const clipboard = require("clipboardy");
|
|
6
|
-
const base_1 = require("../command-bases/base");
|
|
7
|
-
class Sign extends base_1.default {
|
|
8
|
-
async run() {
|
|
9
|
-
const parsed = this.parse(Sign);
|
|
10
|
-
const args = parsed.args;
|
|
11
|
-
const flags = parsed.flags;
|
|
12
|
-
const playbackId = args['playback-id'];
|
|
13
|
-
const options = {
|
|
14
|
-
expiration: flags.expiresIn,
|
|
15
|
-
type: flags.type,
|
|
16
|
-
keyId: this.MuxConfig.signingKeyId,
|
|
17
|
-
keySecret: this.MuxConfig.signingKeySecret,
|
|
18
|
-
};
|
|
19
|
-
const key = this.JWT.sign(playbackId, options);
|
|
20
|
-
const url = `https://stream.mux.com/${playbackId}.m3u8?token=${key}`;
|
|
21
|
-
if (flags.raw) {
|
|
22
|
-
console.log(url);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
this.log(chalk `
|
|
26
|
-
🔑 {bold.underline Your Mux Signed Token}
|
|
27
|
-
{blue ${key}}
|
|
28
|
-
|
|
29
|
-
🌏 {bold.underline Full URL}
|
|
30
|
-
{green ${url}}
|
|
31
|
-
`);
|
|
32
|
-
try {
|
|
33
|
-
await clipboard.write(url);
|
|
34
|
-
this.log(`👉 Copied Full URL to your system clipboard`);
|
|
35
|
-
}
|
|
36
|
-
catch (_a) {
|
|
37
|
-
this.error('Unable to copy full url automatically');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.default = Sign;
|
|
43
|
-
Sign.description = 'Creates a new signed URL token for a playback ID';
|
|
44
|
-
Sign.args = [
|
|
45
|
-
{
|
|
46
|
-
name: 'playback-id',
|
|
47
|
-
description: 'Playback ID to create a signed URL token for.',
|
|
48
|
-
required: true,
|
|
49
|
-
},
|
|
50
|
-
];
|
|
51
|
-
Sign.flags = {
|
|
52
|
-
expiresIn: command_1.flags.string({
|
|
53
|
-
char: 'e',
|
|
54
|
-
description: 'How long the signature is valid for. If no unit is specified, milliseconds is assumed.',
|
|
55
|
-
default: '7d',
|
|
56
|
-
}),
|
|
57
|
-
type: command_1.flags.string({
|
|
58
|
-
char: 't',
|
|
59
|
-
description: 'What type of token this signature is for.',
|
|
60
|
-
default: 'video',
|
|
61
|
-
options: ['video', 'thumbnail', 'gif', 'storyboard'],
|
|
62
|
-
}),
|
|
63
|
-
raw: command_1.flags.boolean({
|
|
64
|
-
char: 'r',
|
|
65
|
-
description: 'If set, emits only the URL+JWT. Defaults to true for non-TTY.',
|
|
66
|
-
default: !process.stdin.isTTY,
|
|
67
|
-
}),
|
|
68
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import MuxBase from '../../command-bases/base';
|
|
2
|
-
export default class SignSpace extends MuxBase {
|
|
3
|
-
static description: string;
|
|
4
|
-
static args: {
|
|
5
|
-
name: string;
|
|
6
|
-
description: string;
|
|
7
|
-
required: boolean;
|
|
8
|
-
}[];
|
|
9
|
-
static flags: any;
|
|
10
|
-
run(): Promise<void>;
|
|
11
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const command_1 = require("@oclif/command");
|
|
4
|
-
const JWT = require("jsonwebtoken");
|
|
5
|
-
const chalk = require("chalk");
|
|
6
|
-
const clipboard = require("clipboardy");
|
|
7
|
-
const base_1 = require("../../command-bases/base");
|
|
8
|
-
class SignSpace extends base_1.default {
|
|
9
|
-
async run() {
|
|
10
|
-
const parsed = this.parse(SignSpace);
|
|
11
|
-
const args = parsed.args;
|
|
12
|
-
const flags = parsed.flags;
|
|
13
|
-
const signingKeySecret = this.MuxConfig.signingKeySecret;
|
|
14
|
-
if (!signingKeySecret) {
|
|
15
|
-
throw new Error("No signing key found. Re-run `mux init` and generate one!");
|
|
16
|
-
}
|
|
17
|
-
// TODO: replace with mux-node-sdk signing when available
|
|
18
|
-
const payload = {
|
|
19
|
-
role: flags.role,
|
|
20
|
-
participant_id: flags.participantId,
|
|
21
|
-
kid: this.MuxConfig.signingKeyId,
|
|
22
|
-
};
|
|
23
|
-
const jwtOptions = {
|
|
24
|
-
audience: 'rt',
|
|
25
|
-
subject: args['space-id'],
|
|
26
|
-
algorithm: 'RS256',
|
|
27
|
-
noTimestamp: true,
|
|
28
|
-
expiresIn: flags.expiresIn,
|
|
29
|
-
};
|
|
30
|
-
const key = Buffer.from(signingKeySecret, 'base64');
|
|
31
|
-
const jwt = JWT.sign(payload, key, jwtOptions);
|
|
32
|
-
if (flags.raw) {
|
|
33
|
-
console.log(jwt);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this.log(chalk `
|
|
37
|
-
🔑 Your JWT for Mux Spaces
|
|
38
|
-
{cyan ${jwt}}
|
|
39
|
-
`);
|
|
40
|
-
try {
|
|
41
|
-
await clipboard.write(jwt);
|
|
42
|
-
this.log(`👉 Copied your JWT to your system clipboard`);
|
|
43
|
-
}
|
|
44
|
-
catch (_a) {
|
|
45
|
-
this.error('Unable to copy JWT automatically');
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.default = SignSpace;
|
|
51
|
-
SignSpace.description = 'Creates a new signed token for a Mux Space';
|
|
52
|
-
SignSpace.args = [
|
|
53
|
-
{
|
|
54
|
-
name: 'space-id',
|
|
55
|
-
description: 'Space ID for which a token shall be generated.',
|
|
56
|
-
required: true,
|
|
57
|
-
},
|
|
58
|
-
];
|
|
59
|
-
SignSpace.flags = {
|
|
60
|
-
raw: command_1.flags.boolean({
|
|
61
|
-
char: 'r',
|
|
62
|
-
description: "prints a raw JWT to stdout (default if not tty)",
|
|
63
|
-
default: !process.stdin.isTTY,
|
|
64
|
-
}),
|
|
65
|
-
participantId: command_1.flags.string({
|
|
66
|
-
char: 'p',
|
|
67
|
-
description: 'Optional, user-specified participant ID.',
|
|
68
|
-
}),
|
|
69
|
-
role: command_1.flags.string({
|
|
70
|
-
char: 'R',
|
|
71
|
-
description: 'One of \'publisher\' or \'subscriber\'.',
|
|
72
|
-
default: 'publisher',
|
|
73
|
-
}),
|
|
74
|
-
expiresIn: command_1.flags.string({
|
|
75
|
-
char: 'e',
|
|
76
|
-
description: 'How long the signature is valid for. If no unit is specified, milliseconds is assumed.',
|
|
77
|
-
default: '7d',
|
|
78
|
-
}),
|
|
79
|
-
};
|
package/lib/config.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as RT from 'runtypes';
|
|
2
|
-
export declare const MuxCliConfigV1: RT.Record<{
|
|
3
|
-
configVersion: RT.Literal<1>;
|
|
4
|
-
tokenId: RT.String;
|
|
5
|
-
tokenSecret: RT.String;
|
|
6
|
-
signingKeyId: RT.Union<[RT.String, RT.Literal<undefined>]>;
|
|
7
|
-
signingKeySecret: RT.Union<[RT.String, RT.Literal<undefined>]>;
|
|
8
|
-
baseUrl: RT.String;
|
|
9
|
-
}, false>;
|
|
10
|
-
export declare type MuxCliConfigV1 = RT.Static<typeof MuxCliConfigV1>;
|
package/lib/config.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MuxCliConfigV1 = void 0;
|
|
4
|
-
const RT = require("runtypes");
|
|
5
|
-
exports.MuxCliConfigV1 = RT.Record({
|
|
6
|
-
configVersion: RT.Literal(1),
|
|
7
|
-
tokenId: RT.String,
|
|
8
|
-
tokenSecret: RT.String,
|
|
9
|
-
signingKeyId: RT.String.Or(RT.Undefined),
|
|
10
|
-
signingKeySecret: RT.String.Or(RT.Undefined),
|
|
11
|
-
baseUrl: RT.String,
|
|
12
|
-
});
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommandBase = exports.run = void 0;
|
|
4
|
-
var command_1 = require("@oclif/command");
|
|
5
|
-
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return command_1.run; } });
|
|
6
|
-
var base_1 = require("./command-bases/base");
|
|
7
|
-
Object.defineProperty(exports, "CommandBase", { enumerable: true, get: function () { return base_1.default; } });
|
package/oclif.manifest.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":"0.8.0","commands":{"init":{"id":"init","description":"set up a user-level config","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"force":{"name":"force","type":"boolean","char":"f","description":"Will initialize a new file even if one already exists.","allowNo":false}},"args":[{"name":"envFile","description":"path to a Mux access token .env file","required":false}]},"sign":{"id":"sign","description":"Creates a new signed URL token for a playback ID","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"expiresIn":{"name":"expiresIn","type":"option","char":"e","description":"How long the signature is valid for. If no unit is specified, milliseconds is assumed.","default":"7d"},"type":{"name":"type","type":"option","char":"t","description":"What type of token this signature is for.","options":["video","thumbnail","gif","storyboard"],"default":"video"},"raw":{"name":"raw","type":"boolean","char":"r","description":"If set, emits only the URL+JWT. Defaults to true for non-TTY.","allowNo":false}},"args":[{"name":"playback-id","description":"Playback ID to create a signed URL token for.","required":true}]},"assets:create":{"id":"assets:create","description":"Create a new asset in Mux using a file that's already available online","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"private":{"name":"private","type":"boolean","char":"p","description":"add a private playback policy to the created asset","allowNo":false}},"args":[{"name":"input","description":"input URL for the file you'd like to create this asset from","required":true}]},"assets:upload":{"id":"assets:upload","description":"Create a new asset in Mux via a local file","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"private":{"name":"private","type":"boolean","char":"p","allowNo":false},"filter":{"name":"filter","type":"option","char":"f","description":"regex that filters the selected destination if the provided path is a folder"},"concurrent":{"name":"concurrent","type":"option","char":"c","description":"max number of files to upload at once","default":3}},"args":[{"name":"path","description":"local path for the file (or folder) you'd like to upload","required":true}]},"live:complete":{"id":"live:complete","description":"Signal to Mux that a live stream has concluded and should be closed.","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"streamId":{"name":"streamId","type":"option","char":"t","description":"the type of the provided reference name","options":["stream-id"],"default":"stream-id"},"disableAfterCompletion":{"name":"disableAfterCompletion","type":"boolean","char":"d","description":"If set, disables the stream upon completion.","allowNo":false}},"args":[{"name":"streamName","description":"the name (coupled with --reference-type) to look up in Mux to yield this livestream","required":true}]},"live:disable":{"id":"live:disable","description":"Disables a live stream and prevents encoders from streaming to it.","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"streamId":{"name":"streamId","type":"option","char":"t","description":"the type of the provided reference name","options":["stream-id"],"default":"stream-id"}},"args":[{"name":"streamName","description":"the name (coupled with --reference-type) to look up in Mux to yield this livestream","required":true}]},"live:enable":{"id":"live:enable","description":"Enables a live stream, allowing encoders to streaming to it.","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"streamId":{"name":"streamId","type":"option","char":"t","description":"the type of the provided reference name","options":["stream-id"],"default":"stream-id"}},"args":[{"name":"streamName","description":"the name (coupled with --reference-type) to look up in Mux to yield this livestream","required":true}]},"spaces:sign":{"id":"spaces:sign","description":"Creates a new signed token for a Mux Space","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"raw":{"name":"raw","type":"boolean","char":"r","description":"prints a raw JWT to stdout (default if not tty)","allowNo":false},"participantId":{"name":"participantId","type":"option","char":"p","description":"Optional, user-specified participant ID."},"role":{"name":"role","type":"option","char":"R","description":"One of 'publisher' or 'subscriber'.","default":"publisher"},"expiresIn":{"name":"expiresIn","type":"option","char":"e","description":"How long the signature is valid for. If no unit is specified, milliseconds is assumed.","default":"7d"}},"args":[{"name":"space-id","description":"Space ID for which a token shall be generated.","required":true}]}}}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Asset } from '@mux/mux-node';
|
|
2
|
-
import { flags } from '@oclif/command';
|
|
3
|
-
import * as Parser from '@oclif/parser';
|
|
4
|
-
import CommandBase from './base';
|
|
5
|
-
|
|
6
|
-
export type AssetBaseFlags = {
|
|
7
|
-
private: Parser.flags.IBooleanFlag<boolean>;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export default abstract class AssetCommandBase extends CommandBase {
|
|
11
|
-
static flags: AssetBaseFlags = {
|
|
12
|
-
private: flags.boolean({
|
|
13
|
-
char: 'p',
|
|
14
|
-
description: 'add a private playback policy to the created asset',
|
|
15
|
-
}),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
playbackUrl(asset: Asset) {
|
|
19
|
-
const publicPlaybackId = (asset.playback_ids ?? []).find(
|
|
20
|
-
p => p.policy === 'public'
|
|
21
|
-
);
|
|
22
|
-
if (!publicPlaybackId) {
|
|
23
|
-
return 'No public playback policies found!';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return `https://mux-playground.now.sh/videojs?playback_id=${
|
|
27
|
-
publicPlaybackId.id
|
|
28
|
-
}`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
pollAsset(assetId: string): Promise<Asset> {
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
const poll = () =>
|
|
34
|
-
setTimeout(async () => {
|
|
35
|
-
try {
|
|
36
|
-
const asset = await this.Video.Assets.get(assetId);
|
|
37
|
-
if (asset.status === 'ready') {
|
|
38
|
-
return resolve(asset);
|
|
39
|
-
} else if (asset.status === 'errored') {
|
|
40
|
-
return reject(asset);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
poll();
|
|
44
|
-
} catch (err) {
|
|
45
|
-
reject(err);
|
|
46
|
-
}
|
|
47
|
-
}, 500);
|
|
48
|
-
|
|
49
|
-
poll();
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import Mux, { Video as MuxVideo, Data as MuxData, JWT as MuxJWT } from '@mux/mux-node';
|
|
2
|
-
import Command from '@oclif/command';
|
|
3
|
-
import * as chalk from 'chalk';
|
|
4
|
-
import * as fs from 'fs-extra';
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
|
|
7
|
-
import { MuxCliConfigV1 } from '../config';
|
|
8
|
-
|
|
9
|
-
export const MUX_API_BASE_URL = "https://api.mux.com";
|
|
10
|
-
|
|
11
|
-
export default abstract class CommandBase extends Command {
|
|
12
|
-
configFile = path.join(this.config.configDir, 'config.json');
|
|
13
|
-
|
|
14
|
-
MuxConfig!: MuxCliConfigV1;
|
|
15
|
-
Mux!: Mux;
|
|
16
|
-
Video!: MuxVideo;
|
|
17
|
-
Data!: MuxData;
|
|
18
|
-
JWT!: typeof MuxJWT;
|
|
19
|
-
|
|
20
|
-
async readConfigV1(): Promise<MuxCliConfigV1> {
|
|
21
|
-
const configAlreadyExists = await fs.pathExists(this.configFile);
|
|
22
|
-
try {
|
|
23
|
-
const configRaw =
|
|
24
|
-
configAlreadyExists
|
|
25
|
-
? await fs.readJSON(this.configFile)
|
|
26
|
-
: {};
|
|
27
|
-
|
|
28
|
-
// Mux SDK configuration options
|
|
29
|
-
configRaw.tokenId = process.env.MUX_TOKEN_ID ?? configRaw.tokenId;
|
|
30
|
-
configRaw.tokenSecret = process.env.MUX_TOKEN_SECRET ?? configRaw.tokenSecret;
|
|
31
|
-
configRaw.signingKeyId = process.env.MUX_SIGNING_KEY ?? configRaw.signingKeyId;
|
|
32
|
-
configRaw.signingKeySecret = process.env.MUX_PRIVATE_KEY ?? configRaw.signingKeySecret;
|
|
33
|
-
|
|
34
|
-
// Mux CLI specific configuration options
|
|
35
|
-
configRaw.configVersion = configRaw.configVersion ?? 1;
|
|
36
|
-
configRaw.baseUrl = process.env.MUX_CLI_BASE_URL ?? configRaw.baseUrl ?? MUX_API_BASE_URL;
|
|
37
|
-
return MuxCliConfigV1.check(configRaw);
|
|
38
|
-
} catch (err) {
|
|
39
|
-
if (configAlreadyExists) {
|
|
40
|
-
// we have a bad config file, and should say so
|
|
41
|
-
this.log(
|
|
42
|
-
chalk`{bold.underline.red Invalid Mux configuration file found at {bold.underline.cyan ${this.configFile}}:}\n\n` +
|
|
43
|
-
Object.entries((err as any).details).map(tup => " - " + chalk`{cyan ${tup[0]}}` + `: ${tup[1]}`) +
|
|
44
|
-
chalk`\n\nPlease fix the file or run {bold.magenta mux init --force} to create a new one.`
|
|
45
|
-
)
|
|
46
|
-
} else {
|
|
47
|
-
this.log(
|
|
48
|
-
chalk`{bold.underline.red No Mux configuration file found!} If you'd like to create ` +
|
|
49
|
-
chalk`one, run the {bold.magenta init} command. Otherwise, make sure to have the ` +
|
|
50
|
-
chalk`{bold.yellow MUX_TOKEN_ID} and {bold.yellow MUX_TOKEN_SECRET} environment variables set. 👋`
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async init() {
|
|
59
|
-
if (this.id === 'init') return; // If we're initing we don't want any of this!
|
|
60
|
-
|
|
61
|
-
const config = await this.readConfigV1();
|
|
62
|
-
const mux = new Mux(config?.tokenId, config?.tokenSecret, {
|
|
63
|
-
baseUrl: config?.baseUrl,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
this.Mux = mux;
|
|
67
|
-
this.MuxConfig = config;
|
|
68
|
-
this.Video = this.Mux.Video;
|
|
69
|
-
this.Data = this.Mux.Data;
|
|
70
|
-
this.JWT = Mux.JWT;
|
|
71
|
-
}
|
|
72
|
-
}
|