Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate code from googleapis/nodejs-video-live-stream #2992

Merged
merged 16 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/media-livestream.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: media-livestream
on:
push:
branches:
- main
paths:
- 'media/livestream/**'
- '.github/workflows/media-livestream.yaml'
pull_request:
paths:
- 'media/livestream/**'
- '.github/workflows/media-livestream.yaml'
pull_request_target:
types: [labeled]
paths:
- 'media/livestream/**'
- '.github/workflows/media-livestream.yaml'
schedule:
- cron: '0 0 * * 0'
jobs:
test:
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: 'write'
pull-requests: 'write'
id-token: 'write'
steps:
- uses: actions/[email protected]
with:
ref: ${{github.event.pull_request.head.sha}}
- uses: 'google-github-actions/[email protected]'
with:
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
service_account: '[email protected]'
create_credentials_file: 'true'
access_token_lifetime: 600s
- uses: actions/[email protected]
with:
node-version: 16
- run: npm install
working-directory: media/livestream
- run: npm test
working-directory: media/livestream
env:
MOCHA_REPORTER_SUITENAME: media_livestream
MOCHA_REPORTER_OUTPUT: media_livestream_sponge_log.xml
MOCHA_REPORTER: xunit
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
name: 'actions:force-run',
owner: 'GoogleCloudPlatform',
repo: 'nodejs-docs-samples',
issue_number: context.payload.pull_request.number
});
} catch (e) {
if (!e.message.includes('Label does not exist')) {
throw e;
}
}
- if: ${{ github.event_name == 'schedule' && always() }}
run: |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
chmod +x ./flakybot
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
1 change: 1 addition & 0 deletions .github/workflows/workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"healthcare/hl7v2",
"iam",
"kms",
"media/livestream",
"media/transcoder",
"media/video-stitcher",
"mediatranslation",
Expand Down
119 changes: 119 additions & 0 deletions media/livestream/createChannel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* Copyright 2022, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location, channelId, inputId, outputUri) {
// [START livestream_create_channel]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// channelId = 'my-channel';
// inputId = 'my-input';
// outputUri = 'gs://my-bucket/my-output-folder/';

// Imports the Livestream library
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;

// Instantiates a client
const livestreamServiceClient = new LivestreamServiceClient();

async function createChannel() {
// Construct request
const request = {
parent: livestreamServiceClient.locationPath(projectId, location),
channelId: channelId,
channel: {
inputAttachments: [
{
key: 'my-input',
input: livestreamServiceClient.inputPath(
projectId,
location,
inputId
),
},
],
output: {
uri: outputUri,
},
elementaryStreams: [
{
key: 'es_video',
videoStream: {
h264: {
profile: 'high',
heightPixels: 720,
widthPixels: 1280,
bitrateBps: 3000000,
frameRate: 30,
},
},
},
{
key: 'es_audio',
audioStream: {
codec: 'aac',
channelCount: 2,
bitrateBps: 160000,
},
},
],
muxStreams: [
{
key: 'mux_video',
elementaryStreams: ['es_video'],
segmentSettings: {
seconds: 2,
},
},
{
key: 'mux_audio',
elementaryStreams: ['es_audio'],
segmentSettings: {
seconds: 2,
},
},
],
manifests: [
{
fileName: 'manifest.m3u8',
type: 'HLS',
muxStreams: ['mux_video', 'mux_audio'],
maxSegmentCount: 5,
},
],
},
};

// Run request
const [operation] = await livestreamServiceClient.createChannel(request);
const response = await operation.promise();
const [channel] = response;
console.log(`Channel: ${channel.name}`);
}

createChannel();
// [END livestream_create_channel]
}

// node createChannel.js <projectId> <location> <channelId> <inputId> <outputUri>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
67 changes: 67 additions & 0 deletions media/livestream/createChannelEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Copyright 2022, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location, channelId, eventId) {
// [START livestream_create_channel_event]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// channelId = 'my-channel';
// eventId = 'my-channel-event';

// Imports the Livestream library
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;

// Instantiates a client
const livestreamServiceClient = new LivestreamServiceClient();

async function createChannelEvent() {
// Construct request
const request = {
parent: livestreamServiceClient.channelPath(
projectId,
location,
channelId
),
eventId: eventId,
event: {
adBreak: {
duration: {
seconds: 30,
},
},
executeNow: true,
},
};

// Run request
const [event] = await livestreamServiceClient.createEvent(request);
console.log(`Channel event: ${event.name}`);
}

createChannelEvent();
// [END livestream_create_channel_event]
}

// node createChannelEvent.js <projectId> <location> <channelId> <eventId>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
Loading