Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from awslabs/master
Browse files Browse the repository at this point in the history
Adding Delete
  • Loading branch information
axptwig authored Nov 27, 2019
2 parents b4bc5c0 + c376acb commit a0580aa
Show file tree
Hide file tree
Showing 74 changed files with 7,183 additions and 727 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Amplify Video Plugin
<p>
<a href="https://www.npmjs.com/package/amplify-category-video">
<img src="https://img.shields.io/npm/v/amplify-category-video.svg" />
</a>
</p>

An open source plugin for the Amplify CLI that makes it easy to incorporate video streaming into your mobile and web applications powered by [AWS Amplify](https://aws-amplify.github.io/) and [AWS Media Services](https://aws.amazon.com/media-services/)

Expand Down
20 changes: 20 additions & 0 deletions amplify-plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "video",
"type": "category",
"commands": [
"add",
"get-info",
"help",
"push",
"remove",
"setup",
"setup-obs",
"start",
"stop",
"update",
"version"
],
"eventHandlers":[
"PrePush"
]
}
20 changes: 12 additions & 8 deletions commands/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ module.exports = {
description: `Takes you through a CLI flow to add a ${featureName} resource to your local backend`,
},
{
name: 'update',
description: `Takes you through a CLI flow to update a ${featureName} resource`,
name: 'get-info',
description: `Gets info for ${featureName} resource from the CloudFormation template`,
},
{
name: 'push',
description: `Provisions ${featureName} cloud resources and it's dependencies with the latest local developments`,
},
{
name: 'get-info',
description: `Gets info for ${featureName} resource from the CloudFormation template`,
name: 'remove',
description: `Removes ${featureName} resource from your local backend and will remove them on amplify push`,
},
{
name: 'setup-obs',
description: 'Sets up OBS with your stream settings.',
},
{
name: 'start',
Expand All @@ -40,12 +44,12 @@ module.exports = {
description: `Puts your ${featureName} stream into an idle state`,
},
{
name: 'remove',
description: `Removes ${featureName} resource from your local backend and will remove them on amplify push`,
name: 'update',
description: `Takes you through a CLI flow to update a ${featureName} resource`,
},
{
name: 'setup-obs',
description: 'Sets up OBS with your stream settings.',
name: 'version',
description: 'Prints the version of Amplify Video that you are using',
},
];

Expand Down
26 changes: 24 additions & 2 deletions commands/video/add.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
const fs = require('fs');

const serviceMetadata = JSON.parse(fs.readFileSync(`${__dirname}/../../provider-utils/supported-services.json`));
const subcommand = 'add';
const category = 'video';

let options;

module.exports = {
name: 'add',
name: subcommand,
run: async (context) => {
context.createLiveStream();
const { amplify } = context;
return amplify.serviceSelectionPrompt(context, category, serviceMetadata).then((results) => {
options = {
service: category,
serviceType: results.service,
providerPlugin: results.providerName,
};
const providerController = require(`../../provider-utils/${results.providerName}/index`);
if (!providerController) {
context.print.error('Provider not configured for this category');
return;
}
return providerController.addResource(context, results.service, options);
});
},

};
36 changes: 34 additions & 2 deletions commands/video/get-info.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
const inquirer = require('inquirer');

const subcommand = 'get-info';
const category = 'video';

module.exports = {
name: 'get-info',
name: subcommand,
run: async (context) => {
context.getInfo();
const { amplify } = context;
const amplifyMeta = amplify.getProjectMeta();

if (!(category in amplifyMeta) || Object.keys(amplifyMeta[category]).length === 0) {
context.print.error(`You have no ${category} projects.`);
return;
}

const chooseProject = [
{
type: 'list',
name: 'resourceName',
message: 'Choose what project you want to get info for?',
choices: Object.keys(amplifyMeta[category]),
default: Object.keys(amplifyMeta[category])[0],
},
];
const props = await inquirer.prompt(chooseProject);

const options = amplifyMeta.video[props.resourceName];

const infoController = require(`../../provider-utils/${options.providerPlugin}/utils/video-getinfo`);
if (!infoController) {
context.print.error('Info controller not configured for this category');
return;
}

return infoController.getVideoInfo(context, props.resourceName);
},
};
11 changes: 7 additions & 4 deletions commands/video/push.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const inquirer = require('inquirer');

const subcommand = 'push';
const category = 'video';

module.exports = {
name: 'push',
name: subcommand,
run: async (context) => {
const { amplify } = context;

Expand All @@ -10,14 +13,14 @@ module.exports = {
type: 'list',
name: 'resourceName',
message: 'Choose what project you want to update?',
choices: Object.keys(context.amplify.getProjectMeta().video),
default: Object.keys(context.amplify.getProjectMeta().video)[0],
choices: Object.keys(context.amplify.getProjectMeta()[category]),
default: Object.keys(context.amplify.getProjectMeta()[category])[0],
},
];

const answer = await inquirer.prompt(chooseProject);
amplify.constructExeInfo(context);
return amplify.pushResources(context, 'video', answer.resourceName)
return amplify.pushResources(context, category, answer.resourceName)
.catch((err) => {
context.print.info(err.stack);
context.print.error('There was an error pushing the video resource');
Expand Down
7 changes: 5 additions & 2 deletions commands/video/remove.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const subcommand = 'remove';
const category = 'video';

module.exports = {
name: 'remove',
name: subcommand,
run: async (context) => {
context.removeLiveStream(context);
await context.amplify.removeResource(context, category);
},
};
36 changes: 34 additions & 2 deletions commands/video/setup-obs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
const inquirer = require('inquirer');

const subcommand = 'setup-obs';
const category = 'video';

module.exports = {
name: 'setup-obs',
name: subcommand,
run: async (context) => {
context.setupOBS();
const { amplify } = context;
const amplifyMeta = amplify.getProjectMeta();

if (!(category in amplifyMeta) || Object.keys(amplifyMeta[category]).length === 0) {
context.print.error(`You have no ${category} projects.`);
return;
}

const chooseProject = [
{
type: 'list',
name: 'resourceName',
message: 'Choose what project you want to get info for?',
choices: Object.keys(amplifyMeta[category]),
default: Object.keys(amplifyMeta[category])[0],
},
];
const props = await inquirer.prompt(chooseProject);

const options = amplifyMeta.video[props.resourceName];

const obsController = require(`../../provider-utils/${options.providerPlugin}/utils/livestream-obs`);
if (!obsController && obsController.serviceType !== 'livestream') {
context.print.error('OBS controller not configured for this project.');
return;
}

return obsController.setupOBS(context, props.resourceName);
},
};
38 changes: 36 additions & 2 deletions commands/video/setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
const inquirer = require('inquirer');

const subcommand = 'setup';
const category = 'video';

module.exports = {
name: 'setup',
name: subcommand,
run: async (context) => {
context.pushStaticFiles();
const { amplify } = context;
const amplifyMeta = amplify.getProjectMeta();

if (!(category in amplifyMeta) || Object.keys(amplifyMeta[category]).length === 0) {
context.print.error(`You have no ${category} projects.`);
return;
}

const chooseProject = [
{
type: 'list',
name: 'resourceName',
message: 'Choose what project you want to setup s3 for?',
choices: Object.keys(amplifyMeta[category]),
default: Object.keys(amplifyMeta[category])[0],
},
];

const props = await inquirer.prompt(chooseProject);

const options = amplifyMeta.video[props.resourceName];

const providerController = require(`../../provider-utils/${options.providerPlugin}/index`);
if (!providerController) {
context.print.error('Provider not configured for this category');
return;
}
/* eslint-disable */
return providerController.setupCloudFormation(context, options.serviceType, options, props.resourceName);
/* eslint-enable */
},
};
39 changes: 37 additions & 2 deletions commands/video/start.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
const inquirer = require('inquirer');

const subcommand = 'start';
const category = 'video';

module.exports = {
name: 'start',
name: subcommand,
run: async (context) => {
context.startStream();
const { amplify } = context;
const amplifyMeta = amplify.getProjectMeta();

if (!(category in amplifyMeta) || Object.keys(amplifyMeta[category]).length === 0) {
context.print.error(`You have no ${category} projects.`);
return;
}

const chooseProject = [
{
type: 'list',
name: 'resourceName',
message: 'Choose what project you want to start?',
choices: Object.keys(amplifyMeta[category]),
default: Object.keys(amplifyMeta[category])[0],
},
];

const props = await inquirer.prompt(chooseProject);

const options = amplifyMeta.video[props.resourceName];

const providerController = require(`../../provider-utils/${options.providerPlugin}/index`);
if (!providerController) {
context.print.error('Provider not configured for this category');
return;
}

/* eslint-disable */
return providerController.livestreamStartStop(context, options.serviceType, options, props.resourceName, false);
/* eslint-enable */
},
};
39 changes: 37 additions & 2 deletions commands/video/stop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
const inquirer = require('inquirer');

const subcommand = 'stop';
const category = 'video';

module.exports = {
name: 'stop',
name: subcommand,
run: async (context) => {
context.stopStream();
const { amplify } = context;
const amplifyMeta = amplify.getProjectMeta();

if (!(category in amplifyMeta) || Object.keys(amplifyMeta[category]).length === 0) {
context.print.error(`You have no ${category} projects.`);
return;
}

const chooseProject = [
{
type: 'list',
name: 'resourceName',
message: 'Choose what project you want to stop?',
choices: Object.keys(amplifyMeta[category]),
default: Object.keys(amplifyMeta[category])[0],
},
];

const props = await inquirer.prompt(chooseProject);

const options = amplifyMeta.video[props.resourceName];

const providerController = require(`../../provider-utils/${options.providerPlugin}/index`);
if (!providerController) {
context.print.error('Provider not configured for this category');
return;
}

/* eslint-disable */
return providerController.livestreamStartStop(context, options.serviceType, options, props.resourceName, true);
/* eslint-enable */
},
};
Loading

0 comments on commit a0580aa

Please sign in to comment.