Skip to content

Commit a2d38df

Browse files
irataxygcf-owl-bot[bot]
authored andcommitted
docs: add Live Stream samples and tests (#28)
* 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 <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 55fa024 commit a2d38df

18 files changed

+1267
-1
lines changed

media/livestream/createChannel.js

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* Copyright 2022, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
function main(projectId, location, channelId, inputId, outputUri) {
19+
// [START livestream_create_channel]
20+
/**
21+
* TODO(developer): Uncomment these variables before running the sample.
22+
*/
23+
// projectId = 'my-project-id';
24+
// location = 'us-central1';
25+
// channelId = 'my-channel';
26+
// inputId = 'my-input';
27+
// outputUri = 'gs://my-bucket/my-output-folder/';
28+
29+
// Imports the Livestream library
30+
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;
31+
32+
// Instantiates a client
33+
const livestreamServiceClient = new LivestreamServiceClient();
34+
35+
async function createChannel() {
36+
// Construct request
37+
const request = {
38+
parent: livestreamServiceClient.locationPath(projectId, location),
39+
channelId: channelId,
40+
channel: {
41+
inputAttachments: [
42+
{
43+
key: 'my-input',
44+
input: livestreamServiceClient.inputPath(
45+
projectId,
46+
location,
47+
inputId
48+
),
49+
},
50+
],
51+
output: {
52+
uri: outputUri,
53+
},
54+
elementaryStreams: [
55+
{
56+
key: 'es_video',
57+
videoStream: {
58+
h264: {
59+
profile: 'main',
60+
heightPixels: 720,
61+
widthPixels: 1280,
62+
bitrateBps: 1000000,
63+
frameRate: 30,
64+
},
65+
},
66+
},
67+
{
68+
key: 'es_audio',
69+
audioStream: {
70+
codec: 'aac',
71+
channelCount: 2,
72+
bitrateBps: 160000,
73+
},
74+
},
75+
],
76+
muxStreams: [
77+
{
78+
key: 'mux_video',
79+
elementaryStreams: ['es_video'],
80+
segmentSettings: {
81+
seconds: 2,
82+
},
83+
},
84+
{
85+
key: 'mux_audio',
86+
elementaryStreams: ['es_audio'],
87+
segmentSettings: {
88+
seconds: 2,
89+
},
90+
},
91+
],
92+
manifests: [
93+
{
94+
fileName: 'manifest.m3u8',
95+
type: 'HLS',
96+
muxStreams: ['mux_video', 'mux_audio'],
97+
maxSegmentCount: 5,
98+
},
99+
],
100+
},
101+
};
102+
103+
// Run request
104+
const [operation] = await livestreamServiceClient.createChannel(request);
105+
const response = await operation.promise();
106+
const [channel] = response;
107+
console.log(`Channel: ${channel.name}`);
108+
}
109+
110+
createChannel();
111+
// [END livestream_create_channel]
112+
}
113+
114+
// node createChannel.js <projectId> <location> <channelId> <inputId> <outputUri>
115+
process.on('unhandledRejection', err => {
116+
console.error(err.message);
117+
process.exitCode = 1;
118+
});
119+
main(...process.argv.slice(2));
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright 2022, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
function main(projectId, location, channelId, eventId) {
19+
// [START livestream_create_channel_event]
20+
/**
21+
* TODO(developer): Uncomment these variables before running the sample.
22+
*/
23+
// projectId = 'my-project-id';
24+
// location = 'us-central1';
25+
// channelId = 'my-channel';
26+
// eventId = 'my-channel-event';
27+
28+
// Imports the Livestream library
29+
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;
30+
31+
// Instantiates a client
32+
const livestreamServiceClient = new LivestreamServiceClient();
33+
34+
async function createChannelEvent() {
35+
// Construct request
36+
const request = {
37+
parent: livestreamServiceClient.channelPath(
38+
projectId,
39+
location,
40+
channelId
41+
),
42+
eventId: eventId,
43+
event: {
44+
adBreak: {
45+
duration: {
46+
seconds: 30,
47+
},
48+
},
49+
executeNow: true,
50+
},
51+
};
52+
53+
// Run request
54+
const [event] = await livestreamServiceClient.createEvent(request);
55+
console.log(`Channel event: ${event.name}`);
56+
}
57+
58+
createChannelEvent();
59+
// [END livestream_create_channel_event]
60+
}
61+
62+
// node createChannelEvent.js <projectId> <location> <channelId> <eventId>
63+
process.on('unhandledRejection', err => {
64+
console.error(err.message);
65+
process.exitCode = 1;
66+
});
67+
main(...process.argv.slice(2));

media/livestream/createInput.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright 2022, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
function main(projectId, location, inputId) {
19+
// [START livestream_create_input]
20+
/**
21+
* TODO(developer): Uncomment these variables before running the sample.
22+
*/
23+
// projectId = 'my-project-id';
24+
// location = 'us-central1';
25+
// inputId = 'my-input';
26+
27+
// Imports the Livestream library
28+
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;
29+
30+
// Instantiates a client
31+
const livestreamServiceClient = new LivestreamServiceClient();
32+
33+
async function createInput() {
34+
// Construct request
35+
const request = {
36+
parent: livestreamServiceClient.locationPath(projectId, location),
37+
inputId: inputId,
38+
input: {
39+
type: 'RTMP_PUSH',
40+
},
41+
};
42+
43+
// Run request
44+
const [operation] = await livestreamServiceClient.createInput(request);
45+
const response = await operation.promise();
46+
const [input] = response;
47+
console.log(`Input: ${input.name}`);
48+
}
49+
50+
createInput();
51+
// [END livestream_create_input]
52+
}
53+
54+
// node createInput.js <projectId> <location> <inputId>
55+
process.on('unhandledRejection', err => {
56+
console.error(err.message);
57+
process.exitCode = 1;
58+
});
59+
main(...process.argv.slice(2));

media/livestream/deleteChannel.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright 2022, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
function main(projectId, location, channelId) {
19+
// [START livestream_delete_channel]
20+
/**
21+
* TODO(developer): Uncomment these variables before running the sample.
22+
*/
23+
// projectId = 'my-project-id';
24+
// location = 'us-central1';
25+
// channelId = 'my-channel';
26+
27+
// Imports the Livestream library
28+
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;
29+
30+
// Instantiates a client
31+
const livestreamServiceClient = new LivestreamServiceClient();
32+
33+
async function deleteChannel() {
34+
// Construct request
35+
const request = {
36+
name: livestreamServiceClient.channelPath(projectId, location, channelId),
37+
};
38+
39+
// Run request
40+
const [operation] = await livestreamServiceClient.deleteChannel(request);
41+
await operation.promise();
42+
console.log('Deleted channel');
43+
}
44+
45+
deleteChannel();
46+
// [END livestream_delete_channel]
47+
}
48+
49+
// node deleteChannel.js <projectId> <location> <channelId>
50+
process.on('unhandledRejection', err => {
51+
console.error(err.message);
52+
process.exitCode = 1;
53+
});
54+
main(...process.argv.slice(2));
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright 2022, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
function main(projectId, location, channelId, eventId) {
19+
// [START livestream_delete_channel_event]
20+
/**
21+
* TODO(developer): Uncomment these variables before running the sample.
22+
*/
23+
// projectId = 'my-project-id';
24+
// location = 'us-central1';
25+
// channelId = 'my-channel';
26+
// eventId = 'my-channel-event';
27+
28+
// Imports the Livestream library
29+
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;
30+
31+
// Instantiates a client
32+
const livestreamServiceClient = new LivestreamServiceClient();
33+
34+
async function deleteChannelEvent() {
35+
// Construct request
36+
const request = {
37+
name: livestreamServiceClient.eventPath(
38+
projectId,
39+
location,
40+
channelId,
41+
eventId
42+
),
43+
};
44+
45+
// Run request
46+
await livestreamServiceClient.deleteEvent(request);
47+
console.log('Deleted channel event');
48+
}
49+
50+
deleteChannelEvent();
51+
// [END livestream_delete_channel_event]
52+
}
53+
54+
// node deleteChannelEvent.js <projectId> <location> <channelId> <eventId>
55+
process.on('unhandledRejection', err => {
56+
console.error(err.message);
57+
process.exitCode = 1;
58+
});
59+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)