var quote = String.fromCharCode(39)
var list_playlist = []
var result_search = []
var socket = io('https://iptv.mrk.ovh', {
secure: true,
rejectUnauthorized: false // Only for self-signed certificates
});
socket.on('connect', function() {
$('#sidClient').val(socket.id)
console.log("client connected sid = " + $('#sidClient').val())
});
socket.on('communication', function(data) {
console.log('communication', data)
// RECEPTION RETURN WARNING
if (data['typeCommand'] == 'warning') {
$('#warning').html(data['payload'])
$('#warning').show('slow')
setTimeout(() => { $('#warning').hide('slow') }, 5000);
}
})
$(window).on('scroll resize', lazyLoad);
// INITIALISAITON DES TABS
$('#tab_home').show()
update_list_playlist()
//get_search_channel()
$('#tab_search').hide()
$('#tab_playlist').hide()
$('#tab_devices').hide()
// CLICK TAB HOME
$('#display_tab_home').click(function(){
var triggerTab = new bootstrap.Tab($('#display_tab_home'));
triggerTab.show();
$('#tab_home').show()
$('#tab_search').hide()
$('#tab_playlist').hide()
$('#tab_devices').hide()
get_search_channel()
})
// CLICK TAB PLAYLIST
$('#display_tab_playlist').click(function(){
var triggerTab = new bootstrap.Tab($('#display_tab_playlist'));
triggerTab.show();
$('#tab_home').hide()
$('#tab_search').hide()
$('#tab_playlist').show()
$('#tab_devices').hide()
})
// CLICK TAB DEVICES
$('#display_tab_devices').click(function(){
var triggerTab = new bootstrap.Tab($('#display_tab_devices'));
triggerTab.show();
$('#tab_home').hide()
$('#tab_search').hide()
$('#tab_playlist').hide()
$('#tab_devices').show()
})
// CLICK TAB SEARCH
$('#display_tab_search').click(function(){
var triggerTab = new bootstrap.Tab($('#display_tab_devices'));
triggerTab.show();
$('#tab_home').hide()
$('#tab_search').show()
$('#tab_playlist').hide()
$('#tab_devices').hide()
})
// UPDATE TAB DEVICES
updateListDevices()
setInterval(updateListDevices, 10000)
$('#btn_search').click(function(){
get_search_channel($('#input_search').val())
})
$('#btn_initdb').click(function(){
$.get('init_db').done(function(data){
window.location.href = "/"
})
})
function isInViewport(element) {
const rect = element[0].getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
function lazyLoad() {
$('.lazy').each(function () {
const img = $(this);
if (isInViewport(img) && !img.hasClass('loaded')) {
img.attr('src', img.data('src')); // Load the image
img.on('load', function () {
img.addClass('loaded'); // Add loaded class for fade-in
});
}
});
}
// DISPLAY CHANNELS
function displayResult() {
$('#listChannels').show()
if ($('#typeDisplay').val() == 'list') html = '
'
else html = ''
result_search.forEach(element => {
var id_channel = element['id_channel']
var name_channel = element['Name']
var url_channel = element['url']
var url_channel_macos = url_channel.replace("http://", 'rtmp://')
//url_channel_macos = url_channel.replace("https://", 'rtmp://')
if ($('#typeDisplay').val() == 'list') {
html += `
${name_channel}`
} else {
html += `
\

\
\
${name_channel}
\
\
vlc ios \
\
`
}
})
if ($('#typeDisplay').val() == 'list') html += ''
else html += '
'
$('#listChannels').html(html)
$('.btn_play_media').click(function(){
var name = $(this).data('name_channel')
var url = $(this).data('url_channel')
console.log('play media', name, url)
socket.emit('communication', {fromSidDevice : $('#sidClient').val(), toSidDevice: $('#sidDevice').val(), typeCommand : "on", payload: {name:name, url:url}, "packet":0});
})
$('.btn_display_url').click(function() {
var url = $(this).data('display_url')
alert(url)
})
}
// GET RESULT SEARCH
function get_search_channel() {
var keyword = $('#input_search').val()
if (keyword.length>0) {
$.post('list_channel', {keyword:encodeURIComponent(keyword)}).done(function(data){
$('#list_channels').html('')
var html =''
console.log(data)
result_search = JSON.parse(data)
displayResult()
lazyLoad();
})
}
}
// UPDATE LIST PLAYLIST
function update_list_playlist() {
$.get('get_list_playlists').done(function(data){
console.log(data)
$('#list_playlist').html('')
var html = ' \
\
\
| # | \
Title | \
End Date | \
Num channels | \
| \
| \
\
\
\
'
var dataJSON = JSON.parse(data)
//list_playlist = dataJSON
for (var i=0;i\
${i.toString()} | \
${dataJSON[i].title_playlist} | \
${dataJSON[i].date_end_playlist} | \
${dataJSON[i].num_channels} | \
\
| \
\
\
| \
`
}
html += '
'
$('#list_playlist').html(html)
for (var i=0;i'
var media = ''+dataJSON[i].mediaRunning+''
if (delta < 60) {
status = 'Online'
status2 = '#ebfaeb'
}
if (delta > 86400) {
status = 'Offline'
status2 = '#e6e6ff'
}
if ((delta > 60) && (delta <= 86400)) {
status = '' + Math.floor(delta / 60).toString() + ' min'
status2 = '#ffe6e6'
}
html += `\
| ${i.toString()} | \
${dataJSON[i].name} | \
${status} | \
${media} | \
\
`
html2 += '- '+dataJSON[i].name+'
'
html3 += ' \
\
\
'+status+'
\
'+media+'
\
\
'
}
html += ' '
$('#listDevices').html(html)
//$('#list_device_home').html(html2)
//$('#zone_device_main').html(html3)
function configure_current_device(element) {
const id_device = $(element).data('param1');
const name_device = $(element).data('param2');
const sid = $(element).data('param3');
console.log(id_device, name_device)
$('#id_device').val(id_device)
$('#sidDevice').val(sid)
$('#btn_select_device').html(name_device)
}
for (var i=0;iPlease select a file')
return;
}
const formData = new FormData();
formData.append("file", file);
const xhr = new XMLHttpRequest();
xhr.open("POST", "/upload", true);
// Update progress bar
xhr.upload.onprogress = function (event) {
if (event.lengthComputable) {
const percentComplete = Math.round((event.loaded / event.total) * 100);
$("#progress-bar").val(percentComplete);
$("#progress-text").text(percentComplete + "%");
}
};
xhr.onloadstart = function () {
$("#progress-container").show();
};
xhr.onload = function () {
if (xhr.status === 200) {
$('#add_playlist_alert').html('Upload successful!
')
var response =JSON.parse(xhr.response)
id_playlist = response['id_playlist']
if (response.status == 'ok') {
$.post('analyse_m3u_file', {'id_playlist':id_playlist,
'title':$('#playlist_title').val(),
'url':$('#playlist_url').val(),
'date_end':$('#playlist_end_date').val(),
'filename':$("#fileName").val()}).done(function(data){
var num_channel = data.num_channel
if (num_channel>0) {
$('#add_playlist_alert').html('Num channel : '+String(num_channel)+'
')
} else {
$('#add_playlist_alert').html('No channel in the file
')
}
update_list_playlist()
$('#modal_add_playlist').modal('hide')
})
}
} else {
$('#add_playlist_alert').html('Upload failed!
')
}
$("#progress-container").hide();
};
xhr.onerror = function () {
alert("An error occurred while uploading.");
$("#progress-container").hide();
};
xhr.send(formData);
}
});
$("#typeDisplay").change(function(){
console.log($("#typeDisplay").val())
displayResult()
})
$('#btn_display_player').click(function () {
if($('#player').css('display') == 'none'){
$('#player').show('slow');
$('#valRange').html='0'
$('#Range').val(0)
} else {
$('#player').hide('slow');
}
})
$(".dropdown-submenu .dropdown-toggle").on("click", function (e) {
e.preventDefault(); // Prevent link from navigating
e.stopPropagation(); // Prevent closing the whole dropdown
let $submenu = $(this).next(".dropdown-menu");
// Toggle the submenu visibility
$(".dropdown-submenu .dropdown-menu").not($submenu).removeClass("show"); // Close other submenus
$submenu.toggleClass("show");
});
// Close submenus when clicking outside
$(document).on("click", function (e) {
if (!$(e.target).closest(".dropdown-submenu").length) {
$(".dropdown-submenu .dropdown-menu").removeClass("show");
}
});
function off(){
console.log('OFF ',$('#sidDevice').val(), $('#sidClient').val())
socket.emit('communication', {fromSidDevice : $('#sidClient').val(), toSidDevice: $('#sidDevice').val(), typeCommand : "off", payload: 0, "packet":0});
}