Skip to content

Commit f7b0dd1

Browse files
authored
feat: [LiveStream] add channel event samples and tests (GoogleCloudPlatform#1765)
1 parent 80116b7 commit f7b0dd1

File tree

6 files changed

+357
-3
lines changed

6 files changed

+357
-3
lines changed

media/livestream/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
"require": {
55
"google/cloud-video-live-stream": "^0.2.4"
66
}
7-
}
7+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2022 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\LiveStream;
26+
27+
// [START livestream_create_channel_event]
28+
use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient;
29+
use Google\Cloud\Video\LiveStream\V1\Event;
30+
use Google\Protobuf\Duration;
31+
32+
/**
33+
* Creates a channel event. This particular sample inserts an ad break marker.
34+
* Other event types are supported.
35+
*
36+
* @param string $callingProjectId The project ID to run the API call under
37+
* @param string $location The location of the channel
38+
* @param string $channelId The ID of the channel
39+
* @param string $eventId The ID of the channel event
40+
*/
41+
function create_channel_event(
42+
string $callingProjectId,
43+
string $location,
44+
string $channelId,
45+
string $eventId
46+
): void {
47+
// Instantiate a client.
48+
$livestreamClient = new LivestreamServiceClient();
49+
50+
$parent = $livestreamClient->channelName($callingProjectId, $location, $channelId);
51+
52+
$eventAdBreak = (new Event\AdBreakTask())
53+
->setDuration(new Duration(['seconds' => 30]));
54+
$event = (new Event())
55+
->setAdBreak($eventAdBreak)
56+
->setExecuteNow(true);
57+
58+
// Run the channel event creation request.
59+
$response = $livestreamClient->createEvent($parent, $event, $eventId);
60+
// Print results.
61+
printf('Channel event: %s' . PHP_EOL, $response->getName());
62+
}
63+
// [END livestream_create_channel_event]
64+
65+
// The following 2 lines are only needed to run the samples
66+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
67+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2022 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\LiveStream;
26+
27+
// [START livestream_delete_channel_event]
28+
use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient;
29+
30+
/**
31+
* Deletes a channel event.
32+
*
33+
* @param string $callingProjectId The project ID to run the API call under
34+
* @param string $location The location of the channel
35+
* @param string $channelId The ID of the channel
36+
* @param string $eventId The ID of the channel event to be deleted
37+
*/
38+
function delete_channel_event(
39+
string $callingProjectId,
40+
string $location,
41+
string $channelId,
42+
string $eventId
43+
): void {
44+
// Instantiate a client.
45+
$livestreamClient = new LivestreamServiceClient();
46+
$formattedName = $livestreamClient->eventName($callingProjectId, $location, $channelId, $eventId);
47+
48+
// Run the channel event deletion request.
49+
$livestreamClient->deleteEvent($formattedName);
50+
printf('Deleted channel event %s' . PHP_EOL, $eventId);
51+
}
52+
// [END livestream_delete_channel_event]
53+
54+
// The following 2 lines are only needed to run the samples
55+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
56+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2022 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\LiveStream;
26+
27+
// [START livestream_get_channel_event]
28+
use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient;
29+
30+
/**
31+
* Gets a channel event.
32+
*
33+
* @param string $callingProjectId The project ID to run the API call under
34+
* @param string $location The location of the channel
35+
* @param string $channelId The ID of the channel
36+
* @param string $eventId The ID of the channel event
37+
*/
38+
function get_channel_event(
39+
string $callingProjectId,
40+
string $location,
41+
string $channelId,
42+
string $eventId
43+
): void {
44+
// Instantiate a client.
45+
$livestreamClient = new LivestreamServiceClient();
46+
$formattedName = $livestreamClient->eventName($callingProjectId, $location, $channelId, $eventId);
47+
48+
// Get the channel event.
49+
$response = $livestreamClient->getEvent($formattedName);
50+
printf('Channel event: %s' . PHP_EOL, $response->getName());
51+
}
52+
// [END livestream_get_channel_event]
53+
54+
// The following 2 lines are only needed to run the samples
55+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
56+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2022 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\LiveStream;
26+
27+
// [START livestream_list_channel_events]
28+
use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient;
29+
30+
/**
31+
* Lists the channel events for a given channel.
32+
*
33+
* @param string $callingProjectId The project ID to run the API call under
34+
* @param string $location The location of the channel
35+
* @param string $channelId The ID of the channel
36+
*/
37+
function list_channel_events(
38+
string $callingProjectId,
39+
string $location,
40+
string $channelId
41+
): void {
42+
// Instantiate a client.
43+
$livestreamClient = new LivestreamServiceClient();
44+
$parent = $livestreamClient->channelName($callingProjectId, $location, $channelId);
45+
46+
$response = $livestreamClient->listEvents($parent);
47+
// Print the channel list.
48+
$events = $response->iterateAllElements();
49+
print('Channel events:' . PHP_EOL);
50+
foreach ($events as $event) {
51+
printf('%s' . PHP_EOL, $event->getName());
52+
}
53+
}
54+
// [END livestream_list_channel_events]
55+
56+
// The following 2 lines are only needed to run the samples
57+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
58+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

0 commit comments

Comments
 (0)