-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·264 lines (243 loc) · 13.8 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php
date_default_timezone_set('America/New_York');
require_once('./KalturaClient/KalturaClient.php');
require_once('./AppSettings.php');
require_once('./Metadata.php');
// Get Kaltura client
$config = new KalturaConfiguration();
$config->setServiceUrl('https://www.kaltura.com');
$client = new KalturaClient($config);
// Use an Admin KS to create the live stream (webcast) entry (needed for operations like listing of conversion profiles)
$ks = $client->generateSession(API_ADMIN_SECRET, ADMIN_USER_ID, KalturaSessionType::ADMIN, PARTNER_ID, KS_EXPIRY);
$client->setKS($ks);
// update the webcasting access control profile (ACP) to use simulive and/or live delivery profiles
/* NOTE: THIS ONLY NEEDS TO BE DONE ONCE ON THIS ACP */
$accessControlProfile = new KalturaAccessControlProfile();
$accessControlProfile->rules = [];
$accessControlProfile->rules[0] = new KalturaRule();
$accessControlProfile->rules[0]->code = "simuliveProfile";
$accessControlProfile->rules[0]->actions = [];
$accessControlProfile->rules[0]->actions[0] = new KalturaAccessControlLimitDeliveryProfilesAction();
$accessControlProfile->rules[0]->actions[0]->deliveryProfileIds = "21633,15282"; //simulive delivery profile and webcasting live delivery profile
$accessControlProfile->rules[0]->actions[0]->isBlockedList = false;
$accessControlProfile = $client->accessControlProfile->update(WEBCASTING_ACP, $accessControlProfile);
// Get the necessary conversion profiles
// Live ingest conversion profiles
$filter = new KalturaConversionProfileFilter();
$filter->systemNameEqual = "Default_Live"; // systemName=Default_Live is the Cloud Transcode, and systemName=Passthrough_Live
$liveConversionProfile = $client->conversionProfile->listAction($filter)->objects[0];
// Presentation (document to images) conversion profile
$filter = new KalturaConversionProfileFilter();
$filter->systemNameEqual = "KMS54_NEW_DOC_CONV_IMAGE_WIDE";
$presentationConversionProfile = $client->conversionProfile->listAction($filter)->objects[0];
// create the live stream entry; see documentation here:
// * https://developer.kaltura.com/api-docs/General_Objects/Objects/KalturaLiveStreamEntry
$liveStreamEntry = new KalturaLiveStreamEntry();
$liveStreamEntry->name = WEBCAST_NAME.' '.date("Y-m-d H:i");
$liveStreamEntry->description = WEBCAST_DESCRIPTION;
$liveStreamEntry->mediaType = KalturaMediaType::LIVE_STREAM_FLASH; //indicates rtmp/rtsp source broadcast
$liveStreamEntry->dvrStatus = KalturaDVRStatus::ENABLED; //enable or disable DVR
$liveStreamEntry->dvrWindow = 10; // how long should the DVR be, specified in minutes
$liveStreamEntry->sourceType = KalturaSourceType::LIVE_STREAM;
$liveStreamEntry->adminTags = "kms-webcast-event,vpaas-webcast"; // for analytics tracking of source as webcast vs. source as regular live (don't change this value)
$liveStreamEntry->pushPublishEnabled = KalturaLivePublishStatus::DISABLED;
$liveStreamEntry->conversionProfileId = $liveConversionProfile->id;
$liveStreamEntry->explicitLive = KalturaNullableBoolean::FALSE_VALUE;
$liveStreamEntry->entitledUsersEdit = PRESENTER_USER_ID; // give the presenter access to this live stream entry
$liveStreamEntry->recordStatus = KalturaRecordStatus::DISABLED; // Recording per event, append all events to one recording, or disable recording
$liveStreamEntry->accessControlId = WEBCASTING_ACP; // set the access control profile ID
// Add the live stream entry; see documentation here:
// * https://developer.kaltura.com/console/service/liveStream/action/add
$liveStreamEntry = $client->liveStream->add($liveStreamEntry, KalturaSourceType::LIVE_STREAM);
// Schedule an event; IMPORTANT - do this AFTER liveStream has been completely created.
$eventStartDateTime = DateTime::createFromFormat('j-M-y g:i:s A', SIMULIVE_SESSION_START, new DateTimeZone(TIMEZONE_UTC_OFFSET))->format('U');
$eventEndDateTime = DateTime::createFromFormat('j-M-y g:i:s A', SIMULIVE_SESSION_END, new DateTimeZone(TIMEZONE_UTC_OFFSET))->format('U');
$scheduleEvent = new KalturaLiveStreamScheduleEvent();
$scheduleEvent->summary = 'simulive schedule test';
$scheduleEvent->startDate = $eventStartDateTime;
$scheduleEvent->endDate = $eventEndDateTime;
$scheduleEvent->recurrenceType = KalturaScheduleEventRecurrenceType::NONE;
$scheduleEvent->templateEntryId = $liveStreamEntry->id;
$scheduleEvent->sourceEntryId = VOD_SOURCE_ENTRY_ID;
$scheduleEvent->preStartTime = SIMULIVE_PRE_START_TIME;
$schedulePlugin = KalturaScheduleClientPlugin::get($client);
$scheduleEvent = $schedulePlugin->scheduleEvent->add($scheduleEvent);
// Set the metadata to specify that the live stream entry is a container for a webcast.
// call metadata profile list action with a filter on the profile name
// * https://developer.kaltura.com/console/service/metadataProfile/action/list
$metadataService = KalturaMetadataClientPlugin::get($client);
$metadataFilter = new KalturaMetadataProfileFilter();
$metadataFilter->systemNameEqual = METADATA_PROFILE_SYS_NAME_KWEBCAST;
$metadataProfileId = $metadataService->metadataProfile->listAction($metadataFilter)->objects[0]->id;
$metadataXml = getMetadataSimpleTemplate($client, $metadataProfileId); // from Metadata.php
$metadataXml->IsKwebcastEntry = 1; // always set to 1
$metadataXml->IsSelfServe = 1; // should we enable self-served broadcasting using webcam/audio without external encoder?
//$metadataXml->SlidesDocEntryId = ''; // if there are pre-uploaded slides entry, assign the entry id here
metadataUpsert($client, $metadataProfileId, KalturaMetadataObjectType::ENTRY, $liveStreamEntry->id, $metadataXml); // from Metadata.php
// Set the Event timing metadata (used to present "time to event start" in KMS);
// * https://developer.kaltura.com/console/service/metadataProfile/action/list
$webcastStartTime = strtotime('+5 minutes');
$webcastEndTime = strtotime('+1 hour');
$metadataService = KalturaMetadataClientPlugin::get($client);
$metadataFilter = new KalturaMetadataProfileFilter();
$metadataFilter->systemNameEqual = METADATA_PROFILE_SYS_NAME_EVENTS;
$eventsMetadataProfileId = $metadataService->metadataProfile->listAction($metadataFilter)->objects[0]->id;
$eventMetadataXml = getMetadataSimpleTemplate($client, $eventsMetadataProfileId); // from Metadata.php
$eventMetadataXml->StartTime = $webcastStartTime; // indicate when the webcast will begin
$eventMetadataXml->EndTime = $webcastEndTime; // indicate when the webcast will end
$eventMetadataXml->Timezone = 'America/New_York'; // valid PHP timezone - https://www.php.net/manual/en/timezones.php
$eventMetadataXml->Presenter->PresenterId = PRESENTER_USER_ID;
$eventMetadataXml->Presenter->PresenterName = PRESENTER_NAME;
$eventMetadataXml->Presenter->PresenterTitle = PRESENTER_TITLE;
$eventMetadataXml->Presenter->PresenterBio = PRESENTER_BIO;
$eventMetadataXml->Presenter->PresenterLink = PRESENTER_LINK;
//$eventMetadataXml->Presenter->PresenterImage = ''; //Thumbnail Asset ID, on the webcast entry, that holds the speaker image
// See Metadata.php for metadataUpsert function
metadataUpsert($client, $eventsMetadataProfileId, KalturaMetadataObjectType::ENTRY, $liveStreamEntry->id, $eventMetadataXml);
// Create the Kaltura Session for webcast app
$expiresAt = time() + KS_EXPIRY;
$ks = $client->generateSession(API_ADMIN_SECRET, PRESENTER_USER_ID, KalturaSessionType::USER, PARTNER_ID, KS_EXPIRY, 'setrole:WEBCAST_PRODUCER_DEVICE_ROLE,sview:*,list:'.$liveStreamEntry->id.',download:'.$liveStreamEntry->id);
$client->setKS($ks);
// https://developer.kaltura.com/console/service/uiConf/action/listTemplates
$userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$isMac = strpos(strtolower($userAgent), 'mac') !== false;
$filter = new KalturaUiConfFilter();
$filter->objTypeEqual = KalturaUiConfObjType::WEBCASTING;
$filter->nameLike = "WebcastingVersionInfo";
$filter->partner = 0;
$systemUiconf = $client->uiConf->listTemplates($filter);
$systemUiconf = json_decode($systemUiconf->objects[0]->config);
if (JSON_ERROR_NONE !== json_last_error()) {
// Kwebcast: uiconf JSON is invalid. Reason: ' . json_last_error_msg()
}
$winUiconf = (WIN_UI_CONF_ID)? $client->uiConf->get(WIN_UI_CONF_ID): null;
$macUiconf = (MAC_UI_CONF_ID)? $client->uiConf->get(MAC_UI_CONF_ID): null;
$winConfig = json_decode($winUiconf->config);
if (JSON_ERROR_NONE !== json_last_error()) {
// 'Kwebcast: uiconf JSON is invalid. Reason: ' . json_last_error_msg()
}
$macConfig = json_decode($macUiconf->config);
if (JSON_ERROR_NONE !== json_last_error()) {
// 'Kwebcast: uiconf JSON is invalid. Reason: ' . json_last_error_msg()
}
if (!($winConfig->ignoreOptionalUpdates) && version_compare($systemUiconf->windows->recommendedVersion, $winUiconf->swfUrlVersion) > 0) {
$winDownloadUrl = $systemUiconf->windows->recommendedVersionUrl;
} else {
$winDownloadUrl = !empty($winConfig->recommendedVersionUrl) ? $winConfig->recommendedVersionUrl : $config->serviceUrl . '/kgeneric/ui_conf_id/' . WIN_UI_CONF_ID;
}
if (!($macConfig->ignoreOptionalUpdates) &&
version_compare($systemUiconf->osx->recommendedVersion, $macUiconf->swfUrlVersion) > 0) {
$macDownloadUrl = $systemUiconf->osx->recommendedVersionUrl;
} else {
$macDownloadUrl = !empty($macConfig->recommendedVersionUrl) ? $macConfig->recommendedVersionUrl : $config->serviceUrl . '/kgeneric/ui_conf_id/' . MAC_UI_CONF_ID;
}
// Get absolute URL
$s = $_SERVER;
$useForwardedHost = false;
$ssl = ( ! empty( $s['HTTPS'] ) && $s['HTTPS'] == 'on' );
$sp = strtolower( $s['SERVER_PROTOCOL'] );
$protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );
$port = $s['SERVER_PORT'];
$port = ( ( ! $ssl && $port=='80' ) || ( $ssl && $port=='443' ) ) ? '' : ':'.$port;
$host = ( $useForwardedHost && isset( $s['HTTP_X_FORWARDED_HOST'] ) ) ? $s['HTTP_X_FORWARDED_HOST'] : ( isset( $s['HTTP_HOST'] ) ? $s['HTTP_HOST'] : null );
$host = isset( $host ) ? $host : $s['SERVER_NAME'] . $port;
$absoluteUrl = $protocol . '://' . $host . $s['REQUEST_URI'];
$logoUrl = $absoluteUrl."kaltura-logo.png";
// This is the page where the webcast can be viewed.
$playbackPageUrl = $absoluteUrl.'/webcast-viewer/?entryId='.$liveStreamEntry->id;
?>
<html>
<head>
<title>Kaltura Webcaster</title>
<script type="text/javascript" src="KAppLauncher.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<style>
body {
font-family: 'robotolight', 'Open Sans', 'Helvetica', 'Arial', sans-serif;
text-align: center;
font-weight: 300;
}
.launch {
font-size: 14px;
text-align: center;
text-decoration: none;
display: inline-block;
padding: 14px 0px 14px 0px;
margin-bottom: 10px;
width: 200px;
border-radius: 5px;
background-color: #fc9003;
color: white;
-webkit-appearance: none;
}
.divider { color: #83C36D }
h1 { font-weight: 300; }
h2 { font-weight: 300; }
h3 { font-weight: 300; }
h4 { font-weight: 300; }
</style>
</head>
<body>
<img src="<?php echo $logoUrl; ?>" height="60"/>
<h1>Webcaster</h1>
<h4 class="divider">_______________</h4>
<h3>Created Webcast Entry: <?php echo $liveStreamEntry->id; ?></h3>
<h4>Entry can be found in the <a target="_blank" href="https://kmc.kaltura.com/index.php/kmcng/content/entries/list">KMC</a><h4>
<h4>RTMP URL: <?php echo $liveStreamEntry->primaryBroadcastingUrl; ?></h4>
<h4 class="divider">_______________</h4>
<h3>Prior to First Webcast</h3>
<h4>Download Kaltura Webcast Studio</h4>
<ul style="list-style-type:none">
<li><a href="<?php echo $winDownloadUrl; ?>" target="_blank">Windows (Win 7 and up)</a></li>
<li><a href="<?php echo $macDownloadUrl; ?>" target="_blank">macOS (10.7+)</a></li>
</ul>
<h4 class="divider">_______________</h4>
<h3>Prepare and Launch Webcast</h3>
<h4>via Kaltura Webcast Studio</h4>
<button id="launchProducerApp" class="launch">launch</button>
<h4 class="divider">_______________</h4>
<h3><a target="_blank" id="launchPlayer">View Webcast</a></h3>
<script>
// Handle click on Launch button
document.getElementById("launchProducerApp").onclick = launchKalturaWebcast;
function launchKalturaWebcast() {
var kapp = new KAppLauncher();
var params = <?php
echo json_encode(array(
'ks' => $ks,
'ks_expiry' => date('Y-m-d\TH:i:sP', $expiresAt),
'MediaEntryId' => $liveStreamEntry->id,
'uiConfID' => $isMac == 1 ? MAC_UI_CONF_ID : WIN_UI_CONF_ID,
'serverAddress' => $config->serviceUrl,
'eventsMetadataProfileId' => $eventsMetadataProfileId,
'kwebcastMetadataProfileId' => $metadataProfileId,
'appName' => APP_NAME,
'logoUrl' => $logoUrl,
'fromDate' => date('Y-m-d\TH:i:sP', $webcastStartTime),
'toDate' => date('Y-m-d\TH:i:sP', $webcastEndTime),
'userId' => PRESENTER_USER_ID,
'QnAEnabled' => QNA_ENABLED,
'pollsEnabled' => POLLS_ENABLED,
'userRole' => 'adminRole', // adminRole, viewerRole, unmoderatedAdminRole, privateOnlyRole
'presentationConversionProfileId' => $presentationConversionProfile->id,
'referer' => APP_DOMAIN,
'debuggingMode' => false,
'verifySSL' => true,
'selfServeEnabled' => true,
'appHostUrl' => '', // in embedded apps, such as KAF, set to empty string
'instanceProfile' => APP_NAME
));
?>;
kapp.startApp(params, function(isSupported, failReason) {
if (!isSupported && failReason !== 'browserNotAware') {
alert(res + " " + reason);
} else {
var playerLink = document.getElementById("launchPlayer");
playerLink.href = "<?php echo $playbackPageUrl; ?>";
playerLink.style.display = "inline";
}
}, 3000, true);
}
</script>
</body>
</html>