From 67558a64486657fe8979c565be0cc96f54e50a0c Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Thu, 10 Feb 2022 19:55:25 -0500 Subject: [PATCH 01/15] feat: initial generation of video livestream library (#4) Release-As: 0.1.0 --- media/livestream/package.json | 23 +++++++++ media/livestream/quickstart.js | 76 +++++++++++++++++++++++++++++ media/livestream/test/quickstart.js | 42 ++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 media/livestream/package.json create mode 100644 media/livestream/quickstart.js create mode 100644 media/livestream/test/quickstart.js diff --git a/media/livestream/package.json b/media/livestream/package.json new file mode 100644 index 0000000000..0e023f7e37 --- /dev/null +++ b/media/livestream/package.json @@ -0,0 +1,23 @@ +{ + "name": "nodejs-video-live-stream", + "private": true, + "license": "Apache-2.0", + "author": "Google LLC", + "engines": { + "node": ">=10" + }, + "files": [ + "*.js" + ], + "scripts": { + "test": "c8 mocha --timeout 600000 test/*.js" + }, + "dependencies": { + "@google-cloud/livestream": "^0.1.0" + }, + "devDependencies": { + "c8": "^7.1.0", + "chai": "^4.2.0", + "mocha": "^9.0.0" + } +} diff --git a/media/livestream/quickstart.js b/media/livestream/quickstart.js new file mode 100644 index 0000000000..c5f337ba58 --- /dev/null +++ b/media/livestream/quickstart.js @@ -0,0 +1,76 @@ +// Copyright 2021 Google LLC +// +// 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(parent) { + // [START livestream_quickstart] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The parent location for the resource, in the form of: + * `projects/{project}/locations/{location}`. + */ + // const parent = 'abc123' + /** + * The maximum number of items to return. If unspecified, server + * will pick an appropriate default. Server may return fewer items than + * requested. A caller should only rely on response's + * next_page_token google.cloud.video.livestream.v1.ListChannelsResponse.next_page_token to + * determine if there are more items left to be queried. + */ + // const pageSize = 1234 + /** + * The next_page_token value returned from a previous List request, if any. + */ + // const pageToken = 'abc123' + /** + * The filter to apply to list results. + */ + // const filter = 'abc123' + /** + * Specifies the ordering of results following syntax at + * https://cloud.google.com/apis/design/design_patterns#sorting_order. + */ + // const orderBy = 'abc123' + + // Imports the Livestream library + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + + // Instantiates a client + const livestreamClient = new LivestreamServiceClient(); + + async function callListChannels() { + // Construct request + const request = { + parent, + }; + + // Run request + const iterable = await livestreamClient.listChannelsAsync(request); + for await (const response of iterable) { + console.log(response); + } + } + + callListChannels(); + // [END livestream_quickstart] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/test/quickstart.js b/media/livestream/test/quickstart.js new file mode 100644 index 0000000000..0d0a89be23 --- /dev/null +++ b/media/livestream/test/quickstart.js @@ -0,0 +1,42 @@ +// Copyright 2021 Google LLC +// +// 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'; + +// const path = require('path'); +// const cp = require('child_process'); +const {before, describe, it} = require('mocha'); +// const {LivestreamServiceClient} = require('@google-cloud/vmmigration').v1; + +// const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +// const cwd = path.join(__dirname, '..'); + +// const client = new LivestreamServiceClient(); + +describe('Quickstart', () => { + // let projectId; + + before(async () => { + // projectId = await client.getProjectId(); + }); + + it('should run quickstart', async () => { + // API must be allow listed: + // Should have 0 exit code, and therefore not throw: + // execSync(`node ./quickstart.js projects/${projectId}/locations/global`, { + // cwd, + // }); + }); +}); From 968094ffa4ab2ff854e4eb422275b9336035cb8c Mon Sep 17 00:00:00 2001 From: Nicholas Cook Date: Mon, 2 May 2022 19:18:38 -0700 Subject: [PATCH 02/15] docs: add Live Stream samples and tests (#28) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * docs: add Live Stream samples and tests * Add project number needed for samples test in kokoro configs. * Remove project number requirements. Use project ID for function parameters * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- media/livestream/createChannel.js | 119 +++++++++ media/livestream/createChannelEvent.js | 67 ++++++ media/livestream/createInput.js | 59 +++++ media/livestream/deleteChannel.js | 54 +++++ media/livestream/deleteChannelEvent.js | 59 +++++ media/livestream/deleteInput.js | 54 +++++ media/livestream/getChannel.js | 51 ++++ media/livestream/getChannelEvent.js | 57 +++++ media/livestream/getInput.js | 51 ++++ media/livestream/listChannelEvents.js | 56 +++++ media/livestream/listChannels.js | 51 ++++ media/livestream/listInputs.js | 51 ++++ media/livestream/package.json | 3 +- media/livestream/startChannel.js | 52 ++++ media/livestream/stopChannel.js | 52 ++++ media/livestream/test/livestream.test.js | 291 +++++++++++++++++++++++ media/livestream/updateChannel.js | 75 ++++++ media/livestream/updateInput.js | 66 +++++ 18 files changed, 1267 insertions(+), 1 deletion(-) create mode 100644 media/livestream/createChannel.js create mode 100644 media/livestream/createChannelEvent.js create mode 100644 media/livestream/createInput.js create mode 100644 media/livestream/deleteChannel.js create mode 100644 media/livestream/deleteChannelEvent.js create mode 100644 media/livestream/deleteInput.js create mode 100644 media/livestream/getChannel.js create mode 100644 media/livestream/getChannelEvent.js create mode 100644 media/livestream/getInput.js create mode 100644 media/livestream/listChannelEvents.js create mode 100644 media/livestream/listChannels.js create mode 100644 media/livestream/listInputs.js create mode 100644 media/livestream/startChannel.js create mode 100644 media/livestream/stopChannel.js create mode 100644 media/livestream/test/livestream.test.js create mode 100644 media/livestream/updateChannel.js create mode 100644 media/livestream/updateInput.js diff --git a/media/livestream/createChannel.js b/media/livestream/createChannel.js new file mode 100644 index 0000000000..22fd90ae50 --- /dev/null +++ b/media/livestream/createChannel.js @@ -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: 'main', + heightPixels: 720, + widthPixels: 1280, + bitrateBps: 1000000, + 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 +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/createChannelEvent.js b/media/livestream/createChannelEvent.js new file mode 100644 index 0000000000..901a50411f --- /dev/null +++ b/media/livestream/createChannelEvent.js @@ -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 +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/createInput.js b/media/livestream/createInput.js new file mode 100644 index 0000000000..34a28a85f7 --- /dev/null +++ b/media/livestream/createInput.js @@ -0,0 +1,59 @@ +/** + * 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, inputId) { + // [START livestream_create_input] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // inputId = 'my-input'; + + // Imports the Livestream library + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + + // Instantiates a client + const livestreamServiceClient = new LivestreamServiceClient(); + + async function createInput() { + // Construct request + const request = { + parent: livestreamServiceClient.locationPath(projectId, location), + inputId: inputId, + input: { + type: 'RTMP_PUSH', + }, + }; + + // Run request + const [operation] = await livestreamServiceClient.createInput(request); + const response = await operation.promise(); + const [input] = response; + console.log(`Input: ${input.name}`); + } + + createInput(); + // [END livestream_create_input] +} + +// node createInput.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/deleteChannel.js b/media/livestream/deleteChannel.js new file mode 100644 index 0000000000..5557540555 --- /dev/null +++ b/media/livestream/deleteChannel.js @@ -0,0 +1,54 @@ +/** + * 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) { + // [START livestream_delete_channel] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // channelId = 'my-channel'; + + // Imports the Livestream library + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + + // Instantiates a client + const livestreamServiceClient = new LivestreamServiceClient(); + + async function deleteChannel() { + // Construct request + const request = { + name: livestreamServiceClient.channelPath(projectId, location, channelId), + }; + + // Run request + const [operation] = await livestreamServiceClient.deleteChannel(request); + await operation.promise(); + console.log('Deleted channel'); + } + + deleteChannel(); + // [END livestream_delete_channel] +} + +// node deleteChannel.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/deleteChannelEvent.js b/media/livestream/deleteChannelEvent.js new file mode 100644 index 0000000000..be0f5c4997 --- /dev/null +++ b/media/livestream/deleteChannelEvent.js @@ -0,0 +1,59 @@ +/** + * 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_delete_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 deleteChannelEvent() { + // Construct request + const request = { + name: livestreamServiceClient.eventPath( + projectId, + location, + channelId, + eventId + ), + }; + + // Run request + await livestreamServiceClient.deleteEvent(request); + console.log('Deleted channel event'); + } + + deleteChannelEvent(); + // [END livestream_delete_channel_event] +} + +// node deleteChannelEvent.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/deleteInput.js b/media/livestream/deleteInput.js new file mode 100644 index 0000000000..9866d5410b --- /dev/null +++ b/media/livestream/deleteInput.js @@ -0,0 +1,54 @@ +/** + * 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, inputId) { + // [START livestream_delete_input] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // inputId = 'my-input'; + + // Imports the Livestream library + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + + // Instantiates a client + const livestreamServiceClient = new LivestreamServiceClient(); + + async function deleteInput() { + // Construct request + const request = { + name: livestreamServiceClient.inputPath(projectId, location, inputId), + }; + + // Run request + const [operation] = await livestreamServiceClient.deleteInput(request); + await operation.promise(); + console.log('Deleted input'); + } + + deleteInput(); + // [END livestream_delete_input] +} + +// node deleteInput.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/getChannel.js b/media/livestream/getChannel.js new file mode 100644 index 0000000000..5c38c6a76a --- /dev/null +++ b/media/livestream/getChannel.js @@ -0,0 +1,51 @@ +/** + * 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) { + // [START livestream_get_channel] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // channelId = 'my-channel'; + + // Imports the Livestream library + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + + // Instantiates a client + const livestreamServiceClient = new LivestreamServiceClient(); + + async function getChannel() { + // Construct request + const request = { + name: livestreamServiceClient.channelPath(projectId, location, channelId), + }; + const [channel] = await livestreamServiceClient.getChannel(request); + console.log(`Channel: ${channel.name}`); + } + + getChannel(); + // [END livestream_get_channel] +} + +// node getChannel.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/getChannelEvent.js b/media/livestream/getChannelEvent.js new file mode 100644 index 0000000000..896e5d406c --- /dev/null +++ b/media/livestream/getChannelEvent.js @@ -0,0 +1,57 @@ +/** + * 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_get_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 getChannelEvent() { + // Construct request + const request = { + name: livestreamServiceClient.eventPath( + projectId, + location, + channelId, + eventId + ), + }; + const [event] = await livestreamServiceClient.getEvent(request); + console.log(`Channel event: ${event.name}`); + } + + getChannelEvent(); + // [END livestream_get_channel_event] +} + +// node getChannelEvent.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/getInput.js b/media/livestream/getInput.js new file mode 100644 index 0000000000..600493da47 --- /dev/null +++ b/media/livestream/getInput.js @@ -0,0 +1,51 @@ +/** + * 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, inputId) { + // [START livestream_get_input] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // inputId = 'my-input'; + + // Imports the Livestream library + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + + // Instantiates a client + const livestreamServiceClient = new LivestreamServiceClient(); + + async function getInput() { + // Construct request + const request = { + name: livestreamServiceClient.inputPath(projectId, location, inputId), + }; + const [input] = await livestreamServiceClient.getInput(request); + console.log(`Input: ${input.name}`); + } + + getInput(); + // [END livestream_get_input] +} + +// node getInput.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/listChannelEvents.js b/media/livestream/listChannelEvents.js new file mode 100644 index 0000000000..07dd1ce14b --- /dev/null +++ b/media/livestream/listChannelEvents.js @@ -0,0 +1,56 @@ +/** + * 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) { + // [START livestream_list_channel_events] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // channelId = 'my-channel'; + + // Imports the Livestream library + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + + // Instantiates a client + const livestreamServiceClient = new LivestreamServiceClient(); + + async function listChannelEvents() { + const [events] = await livestreamServiceClient.listEvents({ + parent: livestreamServiceClient.channelPath( + projectId, + location, + channelId + ), + }); + console.info('Channel events:'); + for (const event of events) { + console.info(event.name); + } + } + + listChannelEvents(); + // [END livestream_list_channel_events] +} + +// node listChannelEvents.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/listChannels.js b/media/livestream/listChannels.js new file mode 100644 index 0000000000..ea8d68b481 --- /dev/null +++ b/media/livestream/listChannels.js @@ -0,0 +1,51 @@ +/** + * 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) { + // [START livestream_list_channels] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + + // Imports the Livestream library + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + + // Instantiates a client + const livestreamServiceClient = new LivestreamServiceClient(); + + async function listChannels() { + const [channels] = await livestreamServiceClient.listChannels({ + parent: livestreamServiceClient.locationPath(projectId, location), + }); + console.info('Channels:'); + for (const channel of channels) { + console.info(channel.name); + } + } + + listChannels(); + // [END livestream_list_channels] +} + +// node listChannels.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/listInputs.js b/media/livestream/listInputs.js new file mode 100644 index 0000000000..ae2729ec5f --- /dev/null +++ b/media/livestream/listInputs.js @@ -0,0 +1,51 @@ +/** + * 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) { + // [START livestream_list_inputs] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + + // Imports the Livestream library + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + + // Instantiates a client + const livestreamServiceClient = new LivestreamServiceClient(); + + async function listInputs() { + const [inputs] = await livestreamServiceClient.listInputs({ + parent: livestreamServiceClient.locationPath(projectId, location), + }); + console.info('Inputs:'); + for (const input of inputs) { + console.info(input.name); + } + } + + listInputs(); + // [END livestream_list_inputs] +} + +// node listInputs.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/package.json b/media/livestream/package.json index 0e023f7e37..ec48adf84a 100644 --- a/media/livestream/package.json +++ b/media/livestream/package.json @@ -18,6 +18,7 @@ "devDependencies": { "c8": "^7.1.0", "chai": "^4.2.0", - "mocha": "^9.0.0" + "mocha": "^9.0.0", + "uuid": "^8.0.0" } } diff --git a/media/livestream/startChannel.js b/media/livestream/startChannel.js new file mode 100644 index 0000000000..8e1c628c11 --- /dev/null +++ b/media/livestream/startChannel.js @@ -0,0 +1,52 @@ +/** + * 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) { + // [START livestream_start_channel] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // channelId = 'my-channel'; + + // Imports the Livestream library + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + + // Instantiates a client + const livestreamServiceClient = new LivestreamServiceClient(); + + async function startChannel() { + // Construct request + const request = { + name: livestreamServiceClient.channelPath(projectId, location, channelId), + }; + const [operation] = await livestreamServiceClient.startChannel(request); + await operation.promise(); + console.log('Started channel'); + } + + startChannel(); + // [END livestream_start_channel] +} + +// node startChannel.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/stopChannel.js b/media/livestream/stopChannel.js new file mode 100644 index 0000000000..40c83b879c --- /dev/null +++ b/media/livestream/stopChannel.js @@ -0,0 +1,52 @@ +/** + * 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) { + // [START livestream_stop_channel] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // channelId = 'my-channel'; + + // Imports the Livestream library + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + + // Instantiates a client + const livestreamServiceClient = new LivestreamServiceClient(); + + async function stopChannel() { + // Construct request + const request = { + name: livestreamServiceClient.channelPath(projectId, location, channelId), + }; + const [operation] = await livestreamServiceClient.stopChannel(request); + await operation.promise(); + console.log('Stopped channel'); + } + + stopChannel(); + // [END livestream_stop_channel] +} + +// node stopChannel.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/test/livestream.test.js b/media/livestream/test/livestream.test.js new file mode 100644 index 0000000000..e27c2b0127 --- /dev/null +++ b/media/livestream/test/livestream.test.js @@ -0,0 +1,291 @@ +/** + * 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'; + +const path = require('path'); +const assert = require('assert'); +const {v4: uuidv4} = require('uuid'); +const {execSync} = require('child_process'); +const {describe, it, before, after} = require('mocha'); + +const uniqueID = uuidv4().split('-')[0]; +const bucketName = `nodejs-samples-livestream-test-${uniqueID}`; + +const projectId = process.env.GCLOUD_PROJECT; +const location = 'us-central1'; +const inputId = `nodejs-test-livestream-input-${uniqueID}`; +const inputNameProjectId = `projects/${projectId}/locations/${location}/inputs/${inputId}`; +const channelId = `nodejs-test-livestream-channel-${uniqueID}`; +const channelIdProjectId = `projects/${projectId}/locations/${location}/channels/${channelId}`; +const eventId = `nodejs-test-livestream-event-${uniqueID}`; +const eventIdProjectId = `projects/${projectId}/locations/${location}/channels/${channelId}/events/${eventId}`; +const outputUri = `gs://${bucketName}/test-output-channel/`; +const cwd = path.join(__dirname, '..'); + +before(async () => { + // Stop the channel if it already exists + try { + execSync(`node stopChannel.js ${projectId} ${location} ${channelId}`, { + cwd, + }); + } catch (err) { + // Ignore not found or not started error + } + + // Delete the channel if it already exists + try { + execSync(`node deleteChannel.js ${projectId} ${location} ${channelId}`, { + cwd, + }); + } catch (err) { + // Ignore not found error + } + + // Delete the default input if it already exists + try { + execSync(`node deleteInput.js ${projectId} ${location} ${inputId}`, { + cwd, + }); + } catch (err) { + // Ignore not found error + } +}); + +after(async () => { + // Delete outstanding channels and inputs created more than 3 days ago + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + const livestreamServiceClient = new LivestreamServiceClient(); + const THREE_DAYS_IN_SEC = 60 * 60 * 24 * 3; + const DATE_NOW_SEC = Math.floor(Date.now() / 1000); + + const [channels] = await livestreamServiceClient.listChannels({ + parent: livestreamServiceClient.locationPath(projectId, location), + }); + for (const channel of channels) { + if (channel.createTime.seconds < DATE_NOW_SEC - THREE_DAYS_IN_SEC) { + const request = { + name: channel.name, + }; + try { + await livestreamServiceClient.stopChannel(request); + } catch (err) { + //Ignore error when channel is not started. + console.log(err); + } + await livestreamServiceClient.deleteChannel(request); + } + } + + const [inputs] = await livestreamServiceClient.listInputs({ + parent: livestreamServiceClient.locationPath(projectId, location), + }); + for (const input of inputs) { + if (input.createTime.seconds < DATE_NOW_SEC - THREE_DAYS_IN_SEC) { + const request = { + name: input.name, + }; + await livestreamServiceClient.deleteInput(request); + } + } +}); + +describe('Input functions', () => { + it('should create an input', () => { + const output = execSync( + `node createInput.js ${projectId} ${location} ${inputId}`, + {cwd} + ); + assert.ok(output.includes(inputNameProjectId)); + }); + + it('should show a list of inputs', () => { + const output = execSync(`node listInputs.js ${projectId} ${location}`, { + cwd, + }); + assert.ok(output.includes(inputNameProjectId)); + }); + + it('should update an input', () => { + const output = execSync( + `node updateInput.js ${projectId} ${location} ${inputId}`, + {cwd} + ); + assert.ok(output.includes(inputNameProjectId)); + }); + + it('should get an input', () => { + const output = execSync( + `node getInput.js ${projectId} ${location} ${inputId}`, + {cwd} + ); + assert.ok(output.includes(inputNameProjectId)); + }); + + it('should delete an input', () => { + const output = execSync( + `node deleteInput.js ${projectId} ${location} ${inputId}`, + {cwd} + ); + assert.ok(output.includes('Deleted input')); + }); +}); + +describe('Channel functions', () => { + before(() => { + const output = execSync( + `node createInput.js ${projectId} ${location} ${inputId}`, + {cwd} + ); + assert.ok(output.includes(inputNameProjectId)); + }); + + after(() => { + const output = execSync( + `node deleteInput.js ${projectId} ${location} ${inputId}`, + {cwd} + ); + assert.ok(output.includes('Deleted input')); + }); + + it('should create a channel', () => { + const output = execSync( + `node createChannel.js ${projectId} ${location} ${channelId} ${inputId} ${outputUri}`, + {cwd} + ); + assert.ok(output.includes(channelIdProjectId)); + }); + + it('should show a list of channels', () => { + const output = execSync(`node listChannels.js ${projectId} ${location}`, { + cwd, + }); + assert.ok(output.includes(channelIdProjectId)); + }); + + it('should update an channel', () => { + const output = execSync( + `node updateChannel.js ${projectId} ${location} ${channelId} ${inputId}`, + {cwd} + ); + assert.ok(output.includes(channelIdProjectId)); + }); + + it('should get an channel', () => { + const output = execSync( + `node getChannel.js ${projectId} ${location} ${channelId}`, + {cwd} + ); + assert.ok(output.includes(channelIdProjectId)); + }); + + it('should start a channel', () => { + const output = execSync( + `node startChannel.js ${projectId} ${location} ${channelId}`, + {cwd} + ); + assert.ok(output.includes('Started channel')); + }); + + it('should stop a channel', () => { + const output = execSync( + `node stopChannel.js ${projectId} ${location} ${channelId}`, + {cwd} + ); + assert.ok(output.includes('Stopped channel')); + }); + + it('should delete a channel', () => { + const output = execSync( + `node deleteChannel.js ${projectId} ${location} ${channelId}`, + {cwd} + ); + assert.ok(output.includes('Deleted channel')); + }); +}); + +describe('Channel event functions', () => { + before(() => { + let output = execSync( + `node createInput.js ${projectId} ${location} ${inputId}`, + {cwd} + ); + assert.ok(output.includes(inputNameProjectId)); + + output = execSync( + `node createChannel.js ${projectId} ${location} ${channelId} ${inputId} ${outputUri}`, + {cwd} + ); + assert.ok(output.includes(channelIdProjectId)); + + output = execSync( + `node startChannel.js ${projectId} ${location} ${channelId}`, + {cwd} + ); + assert.ok(output.includes('Started channel')); + }); + + after(() => { + let output = execSync( + `node stopChannel.js ${projectId} ${location} ${channelId}`, + {cwd} + ); + assert.ok(output.includes('Stopped channel')); + + output = execSync( + `node deleteChannel.js ${projectId} ${location} ${channelId}`, + {cwd} + ); + assert.ok(output.includes('Deleted channel')); + + output = execSync( + `node deleteInput.js ${projectId} ${location} ${inputId}`, + {cwd} + ); + assert.ok(output.includes('Deleted input')); + }); + + it('should create a channel event', () => { + const output = execSync( + `node createChannelEvent.js ${projectId} ${location} ${channelId} ${eventId}`, + {cwd} + ); + assert.ok(output.includes(eventIdProjectId)); + }); + + it('should show a list of channel events', () => { + const output = execSync( + `node listChannelEvents.js ${projectId} ${location} ${channelId}`, + {cwd} + ); + assert.ok(output.includes(eventIdProjectId)); + }); + + it('should get a channel event', () => { + const output = execSync( + `node getChannelEvent.js ${projectId} ${location} ${channelId} ${eventId}`, + {cwd} + ); + assert.ok(output.includes(eventIdProjectId)); + }); + + it('should delete a channel event', () => { + const output = execSync( + `node deleteChannelEvent.js ${projectId} ${location} ${channelId} ${eventId}`, + {cwd} + ); + assert.ok(output.includes('Deleted channel event')); + }); +}); diff --git a/media/livestream/updateChannel.js b/media/livestream/updateChannel.js new file mode 100644 index 0000000000..6a7c36a6eb --- /dev/null +++ b/media/livestream/updateChannel.js @@ -0,0 +1,75 @@ +/** + * 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) { + // [START livestream_update_channel] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // channelId = 'my-channel'; + // inputId = 'my-input'; + + // Imports the Livestream library + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + + // Instantiates a client + const livestreamServiceClient = new LivestreamServiceClient(); + + async function updateChannel() { + // Construct request + const request = { + channel: { + name: livestreamServiceClient.channelPath( + projectId, + location, + channelId + ), + inputAttachments: [ + { + key: 'updated-input', + input: livestreamServiceClient.inputPath( + projectId, + location, + inputId + ), + }, + ], + }, + updateMask: { + paths: ['input_attachments'], + }, + }; + + // Run request + const [operation] = await livestreamServiceClient.updateChannel(request); + const response = await operation.promise(); + const [channel] = response; + console.log(`Updated channel: ${channel.name}`); + } + + updateChannel(); + // [END livestream_update_channel] +} + +// node updateChannel.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/updateInput.js b/media/livestream/updateInput.js new file mode 100644 index 0000000000..d2329116eb --- /dev/null +++ b/media/livestream/updateInput.js @@ -0,0 +1,66 @@ +/** + * 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, inputId) { + // [START livestream_update_input] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // inputId = 'my-input'; + + // Imports the Livestream library + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; + + // Instantiates a client + const livestreamServiceClient = new LivestreamServiceClient(); + + async function updateInput() { + // Construct request + const request = { + input: { + name: livestreamServiceClient.inputPath(projectId, location, inputId), + preprocessingConfig: { + crop: { + topPixels: 5, + bottomPixels: 5, + }, + }, + }, + updateMask: { + paths: ['preprocessing_config'], + }, + }; + + // Run request + const [operation] = await livestreamServiceClient.updateInput(request); + const response = await operation.promise(); + const [input] = response; + console.log(`Updated input: ${input.name}`); + } + + updateInput(); + // [END livestream_update_input] +} + +// node updateInput.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); From 56e9489a944e4a9949e6c01550b7a8ff539323ac Mon Sep 17 00:00:00 2001 From: Nicholas Cook Date: Wed, 4 May 2022 11:16:13 -0700 Subject: [PATCH 03/15] add sample for creating a channel with backup input (#30) Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/nodejs-video-live-stream/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [X] Ensure the tests and linter pass - [X] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes b:219762506 --- .../createChannelWithBackupInput.js | 138 ++++++++++++++++++ media/livestream/test/livestream.test.js | 64 +++++--- 2 files changed, 185 insertions(+), 17 deletions(-) create mode 100644 media/livestream/createChannelWithBackupInput.js diff --git a/media/livestream/createChannelWithBackupInput.js b/media/livestream/createChannelWithBackupInput.js new file mode 100644 index 0000000000..0739e0d4c5 --- /dev/null +++ b/media/livestream/createChannelWithBackupInput.js @@ -0,0 +1,138 @@ +/** + * 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, + primaryInputId, + backupInputId, + outputUri +) { + // [START livestream_create_channel_with_backup_input] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // channelId = 'my-channel'; + // primaryInputId = 'my-primary-input'; + // backupInputId = 'my-backup-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 createChannelWithBackupInput() { + // Construct request + const request = { + parent: livestreamServiceClient.locationPath(projectId, location), + channelId: channelId, + channel: { + inputAttachments: [ + { + key: 'my-primary-input', + input: livestreamServiceClient.inputPath( + projectId, + location, + primaryInputId + ), + automaticFailover: { + inputKeys: ['my-backup-input'], + }, + }, + { + key: 'my-backup-input', + input: livestreamServiceClient.inputPath( + projectId, + location, + backupInputId + ), + }, + ], + output: { + uri: outputUri, + }, + elementaryStreams: [ + { + key: 'es_video', + videoStream: { + h264: { + profile: 'main', + heightPixels: 720, + widthPixels: 1280, + bitrateBps: 1000000, + 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}`); + } + + createChannelWithBackupInput(); + // [END livestream_create_channel_with_backup_input] +} + +// node createChannelWithBackupInput.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/livestream/test/livestream.test.js b/media/livestream/test/livestream.test.js index e27c2b0127..e60121544a 100644 --- a/media/livestream/test/livestream.test.js +++ b/media/livestream/test/livestream.test.js @@ -27,11 +27,13 @@ const bucketName = `nodejs-samples-livestream-test-${uniqueID}`; const projectId = process.env.GCLOUD_PROJECT; const location = 'us-central1'; const inputId = `nodejs-test-livestream-input-${uniqueID}`; -const inputNameProjectId = `projects/${projectId}/locations/${location}/inputs/${inputId}`; +const inputName = `projects/${projectId}/locations/${location}/inputs/${inputId}`; +const backupInputId = `nodejs-test-livestream-backup-input-${uniqueID}`; +const backupInputName = `projects/${projectId}/locations/${location}/inputs/${backupInputId}`; const channelId = `nodejs-test-livestream-channel-${uniqueID}`; -const channelIdProjectId = `projects/${projectId}/locations/${location}/channels/${channelId}`; +const channelName = `projects/${projectId}/locations/${location}/channels/${channelId}`; const eventId = `nodejs-test-livestream-event-${uniqueID}`; -const eventIdProjectId = `projects/${projectId}/locations/${location}/channels/${channelId}/events/${eventId}`; +const eventName = `projects/${projectId}/locations/${location}/channels/${channelId}/events/${eventId}`; const outputUri = `gs://${bucketName}/test-output-channel/`; const cwd = path.join(__dirname, '..'); @@ -108,14 +110,14 @@ describe('Input functions', () => { `node createInput.js ${projectId} ${location} ${inputId}`, {cwd} ); - assert.ok(output.includes(inputNameProjectId)); + assert.ok(output.includes(inputName)); }); it('should show a list of inputs', () => { const output = execSync(`node listInputs.js ${projectId} ${location}`, { cwd, }); - assert.ok(output.includes(inputNameProjectId)); + assert.ok(output.includes(inputName)); }); it('should update an input', () => { @@ -123,7 +125,7 @@ describe('Input functions', () => { `node updateInput.js ${projectId} ${location} ${inputId}`, {cwd} ); - assert.ok(output.includes(inputNameProjectId)); + assert.ok(output.includes(inputName)); }); it('should get an input', () => { @@ -131,7 +133,7 @@ describe('Input functions', () => { `node getInput.js ${projectId} ${location} ${inputId}`, {cwd} ); - assert.ok(output.includes(inputNameProjectId)); + assert.ok(output.includes(inputName)); }); it('should delete an input', () => { @@ -149,7 +151,13 @@ describe('Channel functions', () => { `node createInput.js ${projectId} ${location} ${inputId}`, {cwd} ); - assert.ok(output.includes(inputNameProjectId)); + assert.ok(output.includes(inputName)); + + const output2 = execSync( + `node createInput.js ${projectId} ${location} ${backupInputId}`, + {cwd} + ); + assert.ok(output2.includes(backupInputName)); }); after(() => { @@ -158,6 +166,12 @@ describe('Channel functions', () => { {cwd} ); assert.ok(output.includes('Deleted input')); + + const output2 = execSync( + `node deleteInput.js ${projectId} ${location} ${backupInputId}`, + {cwd} + ); + assert.ok(output2.includes('Deleted input')); }); it('should create a channel', () => { @@ -165,14 +179,14 @@ describe('Channel functions', () => { `node createChannel.js ${projectId} ${location} ${channelId} ${inputId} ${outputUri}`, {cwd} ); - assert.ok(output.includes(channelIdProjectId)); + assert.ok(output.includes(channelName)); }); it('should show a list of channels', () => { const output = execSync(`node listChannels.js ${projectId} ${location}`, { cwd, }); - assert.ok(output.includes(channelIdProjectId)); + assert.ok(output.includes(channelName)); }); it('should update an channel', () => { @@ -180,7 +194,7 @@ describe('Channel functions', () => { `node updateChannel.js ${projectId} ${location} ${channelId} ${inputId}`, {cwd} ); - assert.ok(output.includes(channelIdProjectId)); + assert.ok(output.includes(channelName)); }); it('should get an channel', () => { @@ -188,7 +202,7 @@ describe('Channel functions', () => { `node getChannel.js ${projectId} ${location} ${channelId}`, {cwd} ); - assert.ok(output.includes(channelIdProjectId)); + assert.ok(output.includes(channelName)); }); it('should start a channel', () => { @@ -214,6 +228,22 @@ describe('Channel functions', () => { ); assert.ok(output.includes('Deleted channel')); }); + + it('should create a channel with backup input', () => { + const output = execSync( + `node createChannelWithBackupInput.js ${projectId} ${location} ${channelId} ${inputId} ${backupInputId} ${outputUri}`, + {cwd} + ); + assert.ok(output.includes(channelName)); + }); + + it('should delete a channel with backup input', () => { + const output = execSync( + `node deleteChannel.js ${projectId} ${location} ${channelId}`, + {cwd} + ); + assert.ok(output.includes('Deleted channel')); + }); }); describe('Channel event functions', () => { @@ -222,13 +252,13 @@ describe('Channel event functions', () => { `node createInput.js ${projectId} ${location} ${inputId}`, {cwd} ); - assert.ok(output.includes(inputNameProjectId)); + assert.ok(output.includes(inputName)); output = execSync( `node createChannel.js ${projectId} ${location} ${channelId} ${inputId} ${outputUri}`, {cwd} ); - assert.ok(output.includes(channelIdProjectId)); + assert.ok(output.includes(channelName)); output = execSync( `node startChannel.js ${projectId} ${location} ${channelId}`, @@ -262,7 +292,7 @@ describe('Channel event functions', () => { `node createChannelEvent.js ${projectId} ${location} ${channelId} ${eventId}`, {cwd} ); - assert.ok(output.includes(eventIdProjectId)); + assert.ok(output.includes(eventName)); }); it('should show a list of channel events', () => { @@ -270,7 +300,7 @@ describe('Channel event functions', () => { `node listChannelEvents.js ${projectId} ${location} ${channelId}`, {cwd} ); - assert.ok(output.includes(eventIdProjectId)); + assert.ok(output.includes(eventName)); }); it('should get a channel event', () => { @@ -278,7 +308,7 @@ describe('Channel event functions', () => { `node getChannelEvent.js ${projectId} ${location} ${channelId} ${eventId}`, {cwd} ); - assert.ok(output.includes(eventIdProjectId)); + assert.ok(output.includes(eventName)); }); it('should delete a channel event', () => { From 3f257a245868e143d0fbe50168237d0b6faf410a Mon Sep 17 00:00:00 2001 From: sofisl <55454395+sofisl@users.noreply.github.com> Date: Wed, 18 May 2022 19:00:34 -0700 Subject: [PATCH 04/15] build!: update library to use Node 12 (#34) * build!: Update library to use Node 12 Co-authored-by: Owl Bot --- media/livestream/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/media/livestream/package.json b/media/livestream/package.json index ec48adf84a..0cf71b6c4e 100644 --- a/media/livestream/package.json +++ b/media/livestream/package.json @@ -4,7 +4,7 @@ "license": "Apache-2.0", "author": "Google LLC", "engines": { - "node": ">=10" + "node": ">=12.0.0" }, "files": [ "*.js" From 14b4a5d09d6061b2aecfed89291eeaf1f7b97e2b Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 7 Jun 2022 12:37:51 -0400 Subject: [PATCH 05/15] chore(main): release 0.2.0 (#36) See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Owl Bot --- media/livestream/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/media/livestream/package.json b/media/livestream/package.json index 0cf71b6c4e..46d252e300 100644 --- a/media/livestream/package.json +++ b/media/livestream/package.json @@ -13,7 +13,7 @@ "test": "c8 mocha --timeout 600000 test/*.js" }, "dependencies": { - "@google-cloud/livestream": "^0.1.0" + "@google-cloud/livestream": "^0.2.0" }, "devDependencies": { "c8": "^7.1.0", From 95379b75578a4478dd424248575845fe50edc95b Mon Sep 17 00:00:00 2001 From: Nicholas Cook Date: Wed, 8 Jun 2022 18:31:54 -0700 Subject: [PATCH 06/15] docs: align channel config with best practices (#40) --- media/livestream/createChannel.js | 4 ++-- media/livestream/createChannelWithBackupInput.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/media/livestream/createChannel.js b/media/livestream/createChannel.js index 22fd90ae50..b180f20d1a 100644 --- a/media/livestream/createChannel.js +++ b/media/livestream/createChannel.js @@ -56,10 +56,10 @@ function main(projectId, location, channelId, inputId, outputUri) { key: 'es_video', videoStream: { h264: { - profile: 'main', + profile: 'high', heightPixels: 720, widthPixels: 1280, - bitrateBps: 1000000, + bitrateBps: 3000000, frameRate: 30, }, }, diff --git a/media/livestream/createChannelWithBackupInput.js b/media/livestream/createChannelWithBackupInput.js index 0739e0d4c5..6796bf75e9 100644 --- a/media/livestream/createChannelWithBackupInput.js +++ b/media/livestream/createChannelWithBackupInput.js @@ -75,10 +75,10 @@ function main( key: 'es_video', videoStream: { h264: { - profile: 'main', + profile: 'high', heightPixels: 720, widthPixels: 1280, - bitrateBps: 1000000, + bitrateBps: 3000000, frameRate: 30, }, }, From f78c303ef02fb362c0cf8b9e4579ad65948b4875 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 30 Jun 2022 19:08:25 +0000 Subject: [PATCH 07/15] chore(main): release 0.3.0 (#46) :robot: I have created a release *beep* *boop* --- ## [0.3.0](https://github.com/googleapis/nodejs-video-live-stream/compare/v0.2.0...v0.3.0) (2022-06-29) ### Features * support regapic LRO ([#45](https://github.com/googleapis/nodejs-video-live-stream/issues/45)) ([fc3c1b4](https://github.com/googleapis/nodejs-video-live-stream/commit/fc3c1b426407d6ff8b825483c0ab892e25a28d09)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- media/livestream/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/media/livestream/package.json b/media/livestream/package.json index 46d252e300..75d2c3481b 100644 --- a/media/livestream/package.json +++ b/media/livestream/package.json @@ -13,7 +13,7 @@ "test": "c8 mocha --timeout 600000 test/*.js" }, "dependencies": { - "@google-cloud/livestream": "^0.2.0" + "@google-cloud/livestream": "^0.3.0" }, "devDependencies": { "c8": "^7.1.0", From a4e28d3a3647288bcafd2810edd659a79fcdda99 Mon Sep 17 00:00:00 2001 From: Nicholas Cook Date: Fri, 15 Jul 2022 16:47:32 -0700 Subject: [PATCH 08/15] docs: update list calls to async (#44) --- media/livestream/listChannelEvents.js | 6 +++--- media/livestream/listChannels.js | 6 +++--- media/livestream/listInputs.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/media/livestream/listChannelEvents.js b/media/livestream/listChannelEvents.js index 07dd1ce14b..de4fee0a3b 100644 --- a/media/livestream/listChannelEvents.js +++ b/media/livestream/listChannelEvents.js @@ -31,7 +31,7 @@ function main(projectId, location, channelId) { const livestreamServiceClient = new LivestreamServiceClient(); async function listChannelEvents() { - const [events] = await livestreamServiceClient.listEvents({ + const iterable = await livestreamServiceClient.listEventsAsync({ parent: livestreamServiceClient.channelPath( projectId, location, @@ -39,8 +39,8 @@ function main(projectId, location, channelId) { ), }); console.info('Channel events:'); - for (const event of events) { - console.info(event.name); + for await (const response of iterable) { + console.log(response.name); } } diff --git a/media/livestream/listChannels.js b/media/livestream/listChannels.js index ea8d68b481..a8380177cf 100644 --- a/media/livestream/listChannels.js +++ b/media/livestream/listChannels.js @@ -30,12 +30,12 @@ function main(projectId, location) { const livestreamServiceClient = new LivestreamServiceClient(); async function listChannels() { - const [channels] = await livestreamServiceClient.listChannels({ + const iterable = await livestreamServiceClient.listChannelsAsync({ parent: livestreamServiceClient.locationPath(projectId, location), }); console.info('Channels:'); - for (const channel of channels) { - console.info(channel.name); + for await (const response of iterable) { + console.log(response.name); } } diff --git a/media/livestream/listInputs.js b/media/livestream/listInputs.js index ae2729ec5f..e2a7b0c1ff 100644 --- a/media/livestream/listInputs.js +++ b/media/livestream/listInputs.js @@ -30,12 +30,12 @@ function main(projectId, location) { const livestreamServiceClient = new LivestreamServiceClient(); async function listInputs() { - const [inputs] = await livestreamServiceClient.listInputs({ + const iterable = await livestreamServiceClient.listInputsAsync({ parent: livestreamServiceClient.locationPath(projectId, location), }); console.info('Inputs:'); - for (const input of inputs) { - console.info(input.name); + for await (const response of iterable) { + console.log(response.name); } } From 0f6d259f3f32fb7506e56a565b289ada34441f46 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Fri, 26 Aug 2022 12:11:40 -0700 Subject: [PATCH 09/15] chore(main): release 0.3.1 (#52) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(main): release 0.3.1 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Owl Bot --- media/livestream/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/media/livestream/package.json b/media/livestream/package.json index 75d2c3481b..e1f9bfea15 100644 --- a/media/livestream/package.json +++ b/media/livestream/package.json @@ -13,7 +13,7 @@ "test": "c8 mocha --timeout 600000 test/*.js" }, "dependencies": { - "@google-cloud/livestream": "^0.3.0" + "@google-cloud/livestream": "^0.3.1" }, "devDependencies": { "c8": "^7.1.0", From 0c903423745ae6d82a4ca61c413fd1aacabe9ba5 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 8 Sep 2022 16:52:15 -0400 Subject: [PATCH 10/15] chore(main): release 0.3.2 (#63) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(main): release 0.3.2 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Owl Bot --- media/livestream/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/media/livestream/package.json b/media/livestream/package.json index e1f9bfea15..1916b90211 100644 --- a/media/livestream/package.json +++ b/media/livestream/package.json @@ -13,7 +13,7 @@ "test": "c8 mocha --timeout 600000 test/*.js" }, "dependencies": { - "@google-cloud/livestream": "^0.3.1" + "@google-cloud/livestream": "^0.3.2" }, "devDependencies": { "c8": "^7.1.0", From 52bf15cca7a212810067938a694a9404f9d9ae32 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 9 Sep 2022 01:06:13 +0200 Subject: [PATCH 11/15] chore(deps): update dependency uuid to v9 (#64) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [uuid](https://togithub.com/uuidjs/uuid) | [`^8.0.0` -> `^9.0.0`](https://renovatebot.com/diffs/npm/uuid/8.3.2/9.0.0) | [![age](https://badges.renovateapi.com/packages/npm/uuid/9.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/uuid/9.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/uuid/9.0.0/compatibility-slim/8.3.2)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/uuid/9.0.0/confidence-slim/8.3.2)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
uuidjs/uuid ### [`v9.0.0`](https://togithub.com/uuidjs/uuid/blob/HEAD/CHANGELOG.md#​900-httpsgithubcomuuidjsuuidcomparev832v900-2022-09-05) [Compare Source](https://togithub.com/uuidjs/uuid/compare/v8.3.2...v9.0.0) ##### âš  BREAKING CHANGES - Drop Node.js 10.x support. This library always aims at supporting one EOLed LTS release which by this time now is 12.x which has reached EOL 30 Apr 2022. - Remove the minified UMD build from the package. Minified code is hard to audit and since this is a widely used library it seems more appropriate nowadays to optimize for auditability than to ship a legacy module format that, at best, serves educational purposes nowadays. For production browser use cases, users should be using a bundler. For educational purposes, today's online sandboxes like replit.com offer convenient ways to load npm modules, so the use case for UMD through repos like UNPKG or jsDelivr has largely vanished. - Drop IE 11 and Safari 10 support. Drop support for browsers that don't correctly implement const/let and default arguments, and no longer transpile the browser build to ES2015. This also removes the fallback on msCrypto instead of the crypto API. Browser tests are run in the first supported version of each supported browser and in the latest (as of this commit) version available on Browserstack. ##### Features - optimize uuid.v1 by 1.3x uuid.v4 by 4.3x (430%) ([#​597](https://togithub.com/uuidjs/uuid/issues/597)) ([3a033f6](https://togithub.com/uuidjs/uuid/commit/3a033f6bab6bb3780ece6d645b902548043280bc)) - remove UMD build ([#​645](https://togithub.com/uuidjs/uuid/issues/645)) ([e948a0f](https://togithub.com/uuidjs/uuid/commit/e948a0f22bf22f4619b27bd913885e478e20fe6f)), closes [#​620](https://togithub.com/uuidjs/uuid/issues/620) - use native crypto.randomUUID when available ([#​600](https://togithub.com/uuidjs/uuid/issues/600)) ([c9e076c](https://togithub.com/uuidjs/uuid/commit/c9e076c852edad7e9a06baaa1d148cf4eda6c6c4)) ##### Bug Fixes - add Jest/jsdom compatibility ([#​642](https://togithub.com/uuidjs/uuid/issues/642)) ([16f9c46](https://togithub.com/uuidjs/uuid/commit/16f9c469edf46f0786164cdf4dc980743984a6fd)) - change default export to named function ([#​545](https://togithub.com/uuidjs/uuid/issues/545)) ([c57bc5a](https://togithub.com/uuidjs/uuid/commit/c57bc5a9a0653273aa639cda9177ce52efabe42a)) - handle error when parameter is not set in v3 and v5 ([#​622](https://togithub.com/uuidjs/uuid/issues/622)) ([fcd7388](https://togithub.com/uuidjs/uuid/commit/fcd73881692d9fabb63872576ba28e30ff852091)) - run npm audit fix ([#​644](https://togithub.com/uuidjs/uuid/issues/644)) ([04686f5](https://togithub.com/uuidjs/uuid/commit/04686f54c5fed2cfffc1b619f4970c4bb8532353)) - upgrading from uuid3 broken link ([#​568](https://togithub.com/uuidjs/uuid/issues/568)) ([1c849da](https://togithub.com/uuidjs/uuid/commit/1c849da6e164259e72e18636726345b13a7eddd6)) ##### build - drop Node.js 8.x from babel transpile target ([#​603](https://togithub.com/uuidjs/uuid/issues/603)) ([aa11485](https://togithub.com/uuidjs/uuid/commit/aa114858260402107ec8a1e1a825dea0a259bcb5)) - drop support for legacy browsers (IE11, Safari 10) ([#​604](https://togithub.com/uuidjs/uuid/issues/604)) ([0f433e5](https://togithub.com/uuidjs/uuid/commit/0f433e5ec444edacd53016de67db021102f36148)) - drop node 10.x to upgrade dev dependencies ([#​653](https://togithub.com/uuidjs/uuid/issues/653)) ([28a5712](https://togithub.com/uuidjs/uuid/commit/28a571283f8abda6b9d85e689f95b7d3ee9e282e)), closes [#​643](https://togithub.com/uuidjs/uuid/issues/643) ##### [8.3.2](https://togithub.com/uuidjs/uuid/compare/v8.3.1...v8.3.2) (2020-12-08) ##### Bug Fixes - lazy load getRandomValues ([#​537](https://togithub.com/uuidjs/uuid/issues/537)) ([16c8f6d](https://togithub.com/uuidjs/uuid/commit/16c8f6df2f6b09b4d6235602d6a591188320a82e)), closes [#​536](https://togithub.com/uuidjs/uuid/issues/536) ##### [8.3.1](https://togithub.com/uuidjs/uuid/compare/v8.3.0...v8.3.1) (2020-10-04) ##### Bug Fixes - support expo>=39.0.0 ([#​515](https://togithub.com/uuidjs/uuid/issues/515)) ([c65a0f3](https://togithub.com/uuidjs/uuid/commit/c65a0f3fa73b901959d638d1e3591dfacdbed867)), closes [#​375](https://togithub.com/uuidjs/uuid/issues/375)
--- ### Configuration 📅 **Schedule**: Branch creation - "after 9am and before 3pm" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/nodejs-video-live-stream). --- media/livestream/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/media/livestream/package.json b/media/livestream/package.json index 1916b90211..df1a219b39 100644 --- a/media/livestream/package.json +++ b/media/livestream/package.json @@ -19,6 +19,6 @@ "c8": "^7.1.0", "chai": "^4.2.0", "mocha": "^9.0.0", - "uuid": "^8.0.0" + "uuid": "^9.0.0" } } From 49b8f0eaf0cb6cba0606b3f0e23f10a57cf351a4 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Mon, 26 Sep 2022 15:36:13 +0000 Subject: [PATCH 12/15] chore(main): release 0.3.3 (#66) :robot: I have created a release *beep* *boop* --- ## [0.3.3](https://github.com/googleapis/nodejs-video-live-stream/compare/v0.3.2...v0.3.3) (2022-09-14) ### Bug Fixes * Preserve default values in x-goog-request-params header ([#65](https://github.com/googleapis/nodejs-video-live-stream/issues/65)) ([a612a49](https://github.com/googleapis/nodejs-video-live-stream/commit/a612a492a4d4016b913b97431a741c95a0cdd09d)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- media/livestream/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/media/livestream/package.json b/media/livestream/package.json index df1a219b39..2d1d43bd14 100644 --- a/media/livestream/package.json +++ b/media/livestream/package.json @@ -13,7 +13,7 @@ "test": "c8 mocha --timeout 600000 test/*.js" }, "dependencies": { - "@google-cloud/livestream": "^0.3.2" + "@google-cloud/livestream": "^0.3.3" }, "devDependencies": { "c8": "^7.1.0", From 55d45b226acc84d8ab6f6530ebad311341347b59 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Fri, 11 Nov 2022 02:56:20 +0000 Subject: [PATCH 13/15] chore(main): release 0.3.4 (#84) :robot: I have created a release *beep* *boop* --- ## [0.3.4](https://togithub.com/googleapis/nodejs-video-live-stream/compare/v0.3.3...v0.3.4) (2022-11-11) ### Bug Fixes * **deps:** Use google-gax v3.5.2 ([#82](https://togithub.com/googleapis/nodejs-video-live-stream/issues/82)) ([f032c54](https://togithub.com/googleapis/nodejs-video-live-stream/commit/f032c546a3e61f4064439ed2a452c5d3fbeae8e8)) * Regenerated protos JS and TS definitions ([#86](https://togithub.com/googleapis/nodejs-video-live-stream/issues/86)) ([9942fd4](https://togithub.com/googleapis/nodejs-video-live-stream/commit/9942fd4f62d287df3e3d02d75f3eccb698edc62e)) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please). --- media/livestream/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/media/livestream/package.json b/media/livestream/package.json index 2d1d43bd14..df930d216e 100644 --- a/media/livestream/package.json +++ b/media/livestream/package.json @@ -13,7 +13,7 @@ "test": "c8 mocha --timeout 600000 test/*.js" }, "dependencies": { - "@google-cloud/livestream": "^0.3.3" + "@google-cloud/livestream": "^0.3.4" }, "devDependencies": { "c8": "^7.1.0", From 8f23bcece6fdb892847275fa2797a0eaf4a65c9f Mon Sep 17 00:00:00 2001 From: Nick Cook Date: Wed, 18 Jan 2023 10:28:35 -0800 Subject: [PATCH 14/15] add workflows and remove unused quickstart files --- .github/workflows/media-livestream.yaml | 71 +++++++++++++++++++++++ .github/workflows/workflows.json | 1 + media/livestream/quickstart.js | 76 ------------------------- media/livestream/test/quickstart.js | 42 -------------- 4 files changed, 72 insertions(+), 118 deletions(-) create mode 100644 .github/workflows/media-livestream.yaml delete mode 100644 media/livestream/quickstart.js delete mode 100644 media/livestream/test/quickstart.js diff --git a/.github/workflows/media-livestream.yaml b/.github/workflows/media-livestream.yaml new file mode 100644 index 0000000000..8311d16289 --- /dev/null +++ b/.github/workflows/media-livestream.yaml @@ -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/checkout@v3.1.0 + with: + ref: ${{github.event.pull_request.head.sha}} + - uses: 'google-github-actions/auth@v1.0.0' + with: + workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider' + service_account: 'kokoro-system-test@long-door-651.iam.gserviceaccount.com' + create_credentials_file: 'true' + access_token_lifetime: 600s + - uses: actions/setup-node@v3.5.1 + 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}} diff --git a/.github/workflows/workflows.json b/.github/workflows/workflows.json index a9457d68c3..b224ef1bc2 100644 --- a/.github/workflows/workflows.json +++ b/.github/workflows/workflows.json @@ -69,6 +69,7 @@ "healthcare/hl7v2", "iam", "kms", + "media/livestream", "media/transcoder", "media/video-stitcher", "mediatranslation", diff --git a/media/livestream/quickstart.js b/media/livestream/quickstart.js deleted file mode 100644 index c5f337ba58..0000000000 --- a/media/livestream/quickstart.js +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2021 Google LLC -// -// 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(parent) { - // [START livestream_quickstart] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. The parent location for the resource, in the form of: - * `projects/{project}/locations/{location}`. - */ - // const parent = 'abc123' - /** - * The maximum number of items to return. If unspecified, server - * will pick an appropriate default. Server may return fewer items than - * requested. A caller should only rely on response's - * next_page_token google.cloud.video.livestream.v1.ListChannelsResponse.next_page_token to - * determine if there are more items left to be queried. - */ - // const pageSize = 1234 - /** - * The next_page_token value returned from a previous List request, if any. - */ - // const pageToken = 'abc123' - /** - * The filter to apply to list results. - */ - // const filter = 'abc123' - /** - * Specifies the ordering of results following syntax at - * https://cloud.google.com/apis/design/design_patterns#sorting_order. - */ - // const orderBy = 'abc123' - - // Imports the Livestream library - const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; - - // Instantiates a client - const livestreamClient = new LivestreamServiceClient(); - - async function callListChannels() { - // Construct request - const request = { - parent, - }; - - // Run request - const iterable = await livestreamClient.listChannelsAsync(request); - for await (const response of iterable) { - console.log(response); - } - } - - callListChannels(); - // [END livestream_quickstart] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/media/livestream/test/quickstart.js b/media/livestream/test/quickstart.js deleted file mode 100644 index 0d0a89be23..0000000000 --- a/media/livestream/test/quickstart.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2021 Google LLC -// -// 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'; - -// const path = require('path'); -// const cp = require('child_process'); -const {before, describe, it} = require('mocha'); -// const {LivestreamServiceClient} = require('@google-cloud/vmmigration').v1; - -// const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -// const cwd = path.join(__dirname, '..'); - -// const client = new LivestreamServiceClient(); - -describe('Quickstart', () => { - // let projectId; - - before(async () => { - // projectId = await client.getProjectId(); - }); - - it('should run quickstart', async () => { - // API must be allow listed: - // Should have 0 exit code, and therefore not throw: - // execSync(`node ./quickstart.js projects/${projectId}/locations/global`, { - // cwd, - // }); - }); -}); From 0573950b6995be4ed271fc5dbf54bf28cd1e6f24 Mon Sep 17 00:00:00 2001 From: Nick Cook Date: Wed, 18 Jan 2023 13:34:51 -0800 Subject: [PATCH 15/15] Add channel event deletion to clean up outdated resources; remove unneeded checks --- media/livestream/test/livestream.test.js | 53 +++++++++--------------- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/media/livestream/test/livestream.test.js b/media/livestream/test/livestream.test.js index e60121544a..6b210b97d7 100644 --- a/media/livestream/test/livestream.test.js +++ b/media/livestream/test/livestream.test.js @@ -38,55 +38,40 @@ const outputUri = `gs://${bucketName}/test-output-channel/`; const cwd = path.join(__dirname, '..'); before(async () => { - // Stop the channel if it already exists - try { - execSync(`node stopChannel.js ${projectId} ${location} ${channelId}`, { - cwd, - }); - } catch (err) { - // Ignore not found or not started error - } - - // Delete the channel if it already exists - try { - execSync(`node deleteChannel.js ${projectId} ${location} ${channelId}`, { - cwd, - }); - } catch (err) { - // Ignore not found error - } - - // Delete the default input if it already exists - try { - execSync(`node deleteInput.js ${projectId} ${location} ${inputId}`, { - cwd, - }); - } catch (err) { - // Ignore not found error - } -}); - -after(async () => { - // Delete outstanding channels and inputs created more than 3 days ago + // Delete outstanding channels and inputs created more than 3 hours ago const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; const livestreamServiceClient = new LivestreamServiceClient(); - const THREE_DAYS_IN_SEC = 60 * 60 * 24 * 3; + const THREE_HOURS_IN_SEC = 60 * 60 * 3; const DATE_NOW_SEC = Math.floor(Date.now() / 1000); const [channels] = await livestreamServiceClient.listChannels({ parent: livestreamServiceClient.locationPath(projectId, location), }); for (const channel of channels) { - if (channel.createTime.seconds < DATE_NOW_SEC - THREE_DAYS_IN_SEC) { + if (channel.createTime.seconds < DATE_NOW_SEC - THREE_HOURS_IN_SEC) { const request = { name: channel.name, }; try { - await livestreamServiceClient.stopChannel(request); + const [operation] = await livestreamServiceClient.stopChannel(request); + await operation.promise(); } catch (err) { //Ignore error when channel is not started. + console.log( + 'Existing channel already stopped. Ignore the following error.' + ); console.log(err); } + + const [events] = await livestreamServiceClient.listEvents({ + parent: channel.name, + }); + + for (const event of events) { + await livestreamServiceClient.deleteEvent({ + name: event.name, + }); + } await livestreamServiceClient.deleteChannel(request); } } @@ -95,7 +80,7 @@ after(async () => { parent: livestreamServiceClient.locationPath(projectId, location), }); for (const input of inputs) { - if (input.createTime.seconds < DATE_NOW_SEC - THREE_DAYS_IN_SEC) { + if (input.createTime.seconds < DATE_NOW_SEC - THREE_HOURS_IN_SEC) { const request = { name: input.name, };