Skip to content

Commit

Permalink
https://github.com/WWBN/AVideo/issues/9455
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Oct 2, 2024
1 parent 97bc892 commit 920ea09
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
11 changes: 10 additions & 1 deletion plugin/Live/myLiveControls.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class="btn btn-success <?php echo $class; ?> " disabled
<div class="form-group">
<input type="text" class="form-control" id="customUrl" placeholder="https://example.com/custom">
</div>
<div class="form-group">
<textarea class="form-control" id="customMessage" placeholder="<?php echo __('Enter a custom message for your viewers'); ?>"><?php echo __('I hope you enjoyed the stream! As a bonus, we\'ll be sending you to a special page now'); ?>.</textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success btn-block" id="saveUrlBtn">
Expand All @@ -98,11 +101,13 @@ class="btn btn-success <?php echo $class; ?> " disabled

<script>
var viewerUrl = '';
var customMessage = '';

$(document).ready(function() {
// Disable Send Viewers button initially// Load viewerUrl from the cookie if it exists
if (Cookies.get('viewerUrl')) {
viewerUrl = Cookies.get('viewerUrl');
customMessage = Cookies.get('customMessage');
$('#customUrl').val(viewerUrl); // Update the displayed URL
$('.currentUrlText').text(viewerUrl); // Update the displayed URL
$('#sendViewersBtn').prop('disabled', false); // Enable Send Viewers button if URL is present
Expand Down Expand Up @@ -159,6 +164,7 @@ function promptForViewerUrl() {
$('#saveUrlBtn').click(function() {
var selectedUrl = $('#urlList .list-group-item.active').find('.media-url').text().trim();
var customUrl = $('#customUrl').val().trim();
var _customMessage = $('#customMessage').val().trim();

// Determine which URL to use
if (customUrl !== '') {
Expand All @@ -167,8 +173,10 @@ function promptForViewerUrl() {
return;
}
viewerUrl = customUrl;
customMessage = _customMessage;
} else if (selectedUrl !== '') {
viewerUrl = selectedUrl;
customMessage = _customMessage;
} else {
avideoAlertError(__("Please select or enter a URL."));
return;
Expand Down Expand Up @@ -221,6 +229,7 @@ function sendViewers() {
type: 'POST',
data: {
'viewerUrl': viewerUrl,
'customMessage': $('#customMessage').val(),
'live_key': '<?php echo $live_key; ?>',
'live_servers_id': '<?php echo $live_servers_id;?>'
},
Expand All @@ -229,7 +238,7 @@ function sendViewers() {
if (response.error) {
avideoAlertError(response.msg);
} else {
avideoAlertSuccess(__("Viewers sent successfully!"));
avideoToastSuccess(__("Viewers sent successfully!"));
// Optionally, disable the button after sending
$('#sendViewersBtn').prop('disabled', true);
}
Expand Down
1 change: 1 addition & 0 deletions plugin/Live/sendViewers.json.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
$obj = new stdClass();
$obj->row = $row;
$obj->viewerUrl = $_REQUEST['viewerUrl'];
$obj->customMessage = $_REQUEST['customMessage'];
$obj->live_key = $_REQUEST['live_key'];
$obj->live_servers_id = intval(@$_REQUEST['live_servers_id']);

Expand Down
7 changes: 4 additions & 3 deletions plugin/Live/view/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function redirectLive(json, countdown = 15) {
}

var viewerUrl = json.redirectLive && json.redirectLive.viewerUrl;
var customMessage = json.redirectLive && json.redirectLive.customMessage;
if (!viewerUrl) {
console.error("Viewer URL not found.");
return;
Expand All @@ -114,11 +115,11 @@ function redirectLive(json, countdown = 15) {

// Calculate the progress percentage
var progressPercent = ((initialCountdown - countdown) / initialCountdown) * 100;

// Update the progress bar in the avideoConfirm modal with smooth transition
$('#countdownProgressBar').css({
'width': progressPercent + '%',
'transition': 'width 1s linear'
'transition': 'width 1s linear'
});

if (countdown <= 0) {
Expand All @@ -129,7 +130,7 @@ function redirectLive(json, countdown = 15) {
}

// Use avideoConfirm to ask for user confirmation and include a progress bar
avideoConfirm(__("You will be redirected to the following URL:") + "<br><strong>" + viewerUrl + "</strong><br><div class='progress' style='height: 10px;'><div id='countdownProgressBar' class='progress-bar progress-bar-striped progress-bar-animated' role='progressbar' style='width: 0%;' aria-valuenow='0' aria-valuemin='0' aria-valuemax='100'></div></div>").then(function (confirmed) {
avideoConfirm(customMessage + '<hr>' + __("You will be redirected to the following URL:") + "<br><strong>" + viewerUrl + "</strong><br><div class='progress' style='height: 10px;'><div id='countdownProgressBar' class='progress-bar progress-bar-striped progress-bar-animated' role='progressbar' style='width: 0%;' aria-valuenow='0' aria-valuemin='0' aria-valuemax='100'></div></div>").then(function (confirmed) {
if (confirmed) {
clearInterval(countdownInterval); // Stop countdown if user confirms
redirectToUrl(viewerUrl);
Expand Down

0 comments on commit 920ea09

Please sign in to comment.