forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js.php
350 lines (309 loc) · 12.4 KB
/
api.js.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
// this script will be executed on the AVideo side
$meetPlugin = AVideoPlugin::getDataObjectIfEnabled("Meet");
if (empty($meetPlugin)) {
return false;
}
$rtmpLink = "";
$livePlugin = AVideoPlugin::getDataObjectIfEnabled("Live");
if (!empty($livePlugin) && User::canStream()) {
$trasnmition = LiveTransmition::createTransmitionIfNeed(User::getId());
$dropURL = "{$global['webSiteRootURL']}plugin/Live/droplive.json.php?live_transmition_id={$trasnmition['id']}&live_servers_id=" . Live::getCurrentLiveServersId();
$rtmpLink = Live::getRTMPLink(User::getId());
}
if (empty($meet_schedule_id)) {
$meet_schedule_id = 0;
} else {
$meet_schedule_id = intval($meet_schedule_id);
}
?>
<script src="<?php echo getURL('plugin/Meet/external_api.js'); ?>" type="text/javascript"></script>
<script src="<?php echo getURL('node_modules/sweetalert/dist/sweetalert.min.js'); ?>" type="text/javascript"></script>
<script>
var webSiteRootURL = "<?php echo $global['webSiteRootURL']; ?>";
var webSiteTitle = "<?php echo $config->getWebSiteTitle(); ?>";
var lastLiveStatus;
var eventMethod = window.addEventListener ?
"addEventListener" :
"attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod === "attachEvent" ?
"onmessage" :
"message";
eventer(messageEvent, function(e) {
if (typeof e.data.isLive !== 'undefined') {
if (lastLiveStatus !== e.data.isLive) {
lastLiveStatus = e.data.isLive;
console.log("YPTMeetScript live status changed");
if (lastLiveStatus) {
if (typeof event_on_live !== "undefined") {
event_on_live();
}
} else {
if (typeof event_on_liveStop !== "undefined") {
event_on_liveStop();
}
}
if (typeof event_on_liveStatusChange !== "undefined") {
event_on_liveStatusChange();
}
}
} else if (typeof e.data.YPTisReady !== 'undefined') {
if (typeof event_on_meetReady !== "undefined") {
event_on_meetReady();
}
console.log("YPTMeetScript is loaded");
} else if (typeof e.data.conferenceIsReady !== 'undefined') {
if (typeof event_on_meetReady !== "undefined") {
event_on_meetReady();
}
aVideoMeetCreateButtons();
<?php
$css = file_get_contents($global['systemRootPath'] . 'plugin/Meet/meet.mobile.css');
if (!isMobile()) {
$css = "@media (max-width: 767px) {{$css}}";
}
$css .= file_get_contents($global['systemRootPath'] . 'plugin/Meet/meet.css');
?>
aVideoMeetAppendElement("head", <?php echo json_encode("<style>{$css}</style>"); ?>);
console.log("YPTMeetScript conference is ready");
} else if (typeof e.data.aVideoMeetStartRecording !== 'undefined') {
console.log("YPTMeetScript aVideoMeetStartRecording");
aVideoMeetStartRecording(e.data.aVideoMeetStartRecording.RTMPLink, e.data.aVideoMeetStartRecording.dropURL);
} else if (typeof e.data.aVideoMeetStopRecording !== 'undefined') {
console.log("YPTMeetScript aVideoMeetStopRecording");
aVideoMeetStopRecording(e.data.aVideoMeetStopRecording.dropURL);
} else if (typeof e.data.terminateMeet !== 'undefined' && e.data.terminateMeet == 1) {
console.log("YPTMeetScript terminateMeet");
terminateMeet();
}
});
function aVideoMeetZoom(zoom) {
//document.querySelector("iframe").contentWindow.postMessage({zoom: zoom}, "*");
}
function getMeetDisplayName(domain, roomName, jwt, email, TOOLBAR_BUTTONS) {
console.log('getMeetDisplayName');
swal({
text: "<?php echo __("Please, enter your name"); ?>",
content: "input",
button: {
text: "<?php echo __("Start Now"); ?>",
closeModal: true,
},
}).then(function(displayName) {
displayName = displayName.trim();
if (!displayName || /^$|^\s+$/.test(displayName)) {
//avideoAlertError('<?php echo __("You must provide a name"); ?>');
return getMeetDisplayName(domain, roomName, jwt, email, TOOLBAR_BUTTONS);
} else {
return aVideoMeetStart(domain, roomName, jwt, email, displayName, TOOLBAR_BUTTONS);
}
});
return false;
}
var api;
function aVideoMeetStart(domain, roomName, jwt, email, displayName, TOOLBAR_BUTTONS) {
if (!displayName || displayName == '') {
displayName = getMeetDisplayName();
return getMeetDisplayName(domain, roomName, jwt, email, TOOLBAR_BUTTONS);
}
const options = {
roomName: roomName,
jwt: jwt,
parentNode: document.querySelector('#divMeetToIFrame'),
userInfo: {
email: email,
displayName: displayName
},
ConfigOverwrite: {
disableDeepLinking: true,
disableInviteFunctions: true,
openBridgeChannel: 'websocket',
liveStreamingEnabled: true,
fileRecordingsEnabled: false,
//inviteUrl: window.location.href
},
interfaceConfigOverwrite: {
TOOLBAR_BUTTONS: TOOLBAR_BUTTONS,
DISABLE_JOIN_LEAVE_NOTIFICATIONS: true,
MOBILE_APP_PROMO: false,
HIDE_INVITE_MORE_HEADER: true,
//disableAudioLevels: true,
requireDisplayName: true,
enableLayerSuspension: true,
channelLastN: 4,
startVideoMuted: 10,
startAudioMuted: 10,
disableInviteFunctions: true,
DEFAULT_LOGO_URL: webSiteRootURL + "videos/userPhoto/logo.png",
DEFAULT_REMOTE_DISPLAY_NAME: webSiteTitle,
JITSI_WATERMARK_LINK: webSiteRootURL,
LIVE_STREAMING_HELP_LINK: webSiteRootURL,
PROVIDER_NAME: webSiteTitle,
SUPPORT_URL: webSiteRootURL,
BRAND_WATERMARK_LINK: webSiteRootURL,
NATIVE_APP_NAME: webSiteTitle,
APP_NAME: webSiteTitle
}
};
api = new JitsiMeetExternalAPI(domain, options);
const iframe = api.getIFrame();
var src = $(iframe).attr('src');
var srcParts = src.split("#");
var newSRC = srcParts[0] + "&getRTMPLink=<?php echo urlencode($rtmpLink); ?>#" + srcParts[1];
$(iframe).attr('src', newSRC);
api.addEventListeners({
readyToClose: readyToClose,
});
let myUserID;
api.addListener('participantJoined', (participan) => {
// Log the event details for debugging
console.log('participantJoined: Event triggered:', participan);
});
api.addListener('participantUpdated', (event) => {
console.log('participantUpdated event:', event);
});
// Listener for the breakoutRoomsUpdated event
api.addListener('breakoutRoomsUpdated', (event) => {
console.log('breakoutRoomsUpdated: Event triggered:', event);
});
// Listener for the breakoutRoomsUpdated event
api.addListener('notificationTriggered', (event) => {
console.log('notificationTriggered: Event triggered:', event);
});
// Listener for the dataChannelOpened event
api.addListener('dataChannelOpened', (event) => {
console.log('dataChannelOpened: Event triggered:', event);
});
// Listener for the endpointTextMessageReceived event
api.addListener('endpointTextMessageReceived', (event) => {
console.log('endpointTextMessageReceived: Event triggered:', event);
});
// Listener for the nonParticipantMessageReceived event
api.addListener('nonParticipantMessageReceived', (event) => {
console.log('nonParticipantMessageReceived: Event triggered:', event);
});
// Listener for the log event
api.addListener('log', (event) => {
console.log('log event: Event triggered:', event);
});
<?php
if (!empty($rtmpLink) && !empty($_REQUEST['startLiveMeet'])) {
?>
console.log('Live meet will start now');
startLiveMeet();
<?php
}
?>
}
function aVideoMeetStartRecording(RTMPLink, dropURL) {
if (api.getNumberOfParticipants() === 0) {
setTimeout(function() {
aVideoMeetStartRecording(RTMPLink, dropURL);
}, 1000);
return false;
}
if (typeof on_processingLive === 'function') {
on_processingLive();
}
if (dropURL) {
$.ajax({
url: dropURL,
success: function(response) {
console.log("YPTMeetScript Start Recording Drop");
console.log(response);
}
}).always(function(dataOrjqXHR, textStatus, jqXHRorErrorThrown) {
api.executeCommand('startRecording', {
mode: 'stream',
youtubeStreamKey: RTMPLink,
});
});
} else {
api.executeCommand('startRecording', {
mode: 'stream',
youtubeStreamKey: RTMPLink,
});
}
}
function aVideoMeetStopRecording(dropURL) {
if (typeof on_processingLive === 'function') {
on_processingLive();
}
api.executeCommand('stopRecording', 'stream');
if (dropURL) {
setTimeout(function() { // if I run the drop on the same time, the stopRecording fails
$.ajax({
url: dropURL,
success: function(response) {
console.log("YPTMeetScript Stop Recording Drop");
console.log(response);
}
});
}, 5000);
}
}
function aVideoMeetConferenceIsReady() {
}
function aVideoMeetHideElement(selectors) {
document.querySelector("iframe").contentWindow.postMessage({
hideElement: selectors
}, "*");
}
function aVideoMeetAppendElement(parentSelector, html) {
var append = {
parentSelector: parentSelector,
html: html
};
document.querySelector("iframe").contentWindow.postMessage({
append: append
}, "*");
}
function aVideoMeetPrependElement(parentSelector, html) {
var prepend = {
parentSelector: parentSelector,
html: html
};
document.querySelector("iframe").contentWindow.postMessage({
prepend: prepend
}, "*");
}
function aVideoMeetCreateButtons() {
<?php
if (!empty($rtmpLink) && Meet::isModerator($meet_schedule_id)) {
?>
aVideoMeetAppendElement(".button-group-center", <?php echo json_encode(Meet::createJitsiRecordStartStopButton($rtmpLink, $dropURL)); ?>);
<?php
}
?>
}
function readyToClose() {
window.parent.postMessage({
"meetIsClosed": true
}, "*");
if (typeof _readyToClose == "function") {
_readyToClose();
}
}
function startLiveMeet() {
if (api.getNumberOfParticipants() === 0) {
console.log('startLiveMeet: No participants yet, try in 1 second');
setTimeout(function() {
startLiveMeet();
}, 1000);
return false;
} else {
console.log('startLiveMeet: Participants found, we will start in 5 seconds');
setTimeout(function() {
console.log('startLiveMeet: Start now');
aVideoMeetStartRecording('<?php echo $rtmpLink; ?>', '<?php echo $dropURL; ?>');
}, 5000);
}
}
function terminateMeet() {
Participants = api.getParticipantsInfo();
for (var index in Participants) {
api.executeCommand('kickParticipant', Participants[index].participantId);
}
}
</script>