From dc3f30321bc6e59593e37e6716b7f85c82b94ed8 Mon Sep 17 00:00:00 2001 From: Matteo Nastasi Date: Sun, 7 Jan 2018 14:10:47 +0100 Subject: [PATCH] replaced obsolete flash audioplayer with html5 version --- web/Obj/brisk.phh | 4 +- web/briskin5/Obj/briskin5.phh | 2 +- web/briskin5/index.php | 7 ++- web/briskin5/index_wr.php | 2 +- web/commons.js | 115 ++++++++++++++++++++++------------ web/index.php | 30 ++++----- web/room.css | 2 +- 7 files changed, 100 insertions(+), 62 deletions(-) diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index 62fc1a4..5bf51e1 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -3441,9 +3441,9 @@ function validate_name($name) return (FALSE); } -function playsound($filename) +function playsound($name) { - return (sprintf('playsound("flasou", "%s");', $filename)); + return (sprintf('g_jukebox.play("%s");', $name)); } function secstoword($secs) diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index c197b16..35d316e 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -1604,7 +1604,7 @@ function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again) $ret .= table_welcome($user); if ($is_transition && !$is_again) { // just sit, play cow - $ret .= playsound("cow.mp3"); + $ret .= playsound("cow"); } diff --git a/web/briskin5/index.php b/web/briskin5/index.php index 64e7bc5..8d9c6c6 100644 --- a/web/briskin5/index.php +++ b/web/briskin5/index.php @@ -64,6 +64,7 @@ function bin5_index_main($transp_type, $header, &$header_out, $addr, $get, $post ?> + Brisk - Tavolo <?php echo "$table_idx";?> @@ -85,7 +86,7 @@ function bin5_index_main($transp_type, $header, &$header_out, $addr, $get, $post var stat = "table"; var subst = "none"; var table_pos = ""; - var g_withflash = false; + var g_jukebox = null; var asta_ptr; var area_ptr; @@ -107,7 +108,9 @@ var g_imgtot = g_preload_img_arr.length; var g_exitlock = 0; window.onload = function() { - g_withflash = DetectFlashVer(6,0,0); + g_jukebox = new jukebox([{'name': 'cow', 'file': 'cow.mp3'}, + {'name': 'rooster', 'file': 'rooster.mp3'}, + {'name': 'ringbell', 'file': 'ringbell.mp3'}]); remark_off(); preferences_init(); diff --git a/web/briskin5/index_wr.php b/web/briskin5/index_wr.php index d188c0f..a82b39c 100644 --- a/web/briskin5/index_wr.php +++ b/web/briskin5/index_wr.php @@ -362,7 +362,7 @@ function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie) if ($user_cur->privflags & BIN5_USER_FLAG_RING_ENDAUCT) { // $ret .= "var de_che= 33;"; - $ret .= playsound("ringbell.mp3"); + $ret .= playsound("ringbell"); } $ret .= sprintf('document.title = "Brisk - Tavolo %d";', $user->table_orig); diff --git a/web/commons.js b/web/commons.js index 29f6056..af1664a 100644 --- a/web/commons.js +++ b/web/commons.js @@ -2,7 +2,7 @@ * brisk - commons.js * * Copyright (C) 2006-2015 Matteo Nastasi - * mailto: nastasi@alternativeoutput.it + * mailto: nastasi@alternativeoutput.it * matteo.nastasi@milug.org * web: http://www.alternativeoutput.it * @@ -27,7 +27,7 @@ var cookiepath = "/brisk/"; var mlang_commons = { 'imgload_a' : { 'it' : 'Immagini caricate ', 'en' : 'Loaded images ' }, - 'imgload_b' : { 'it' : '%.', + 'imgload_b' : { 'it' : '%.', 'en' : '%.' }, 'gamleav' : { 'it' : 'Sei sicuro di volere lasciare questa mano?' , 'en' : 'Are you sure to leave this game?' }, @@ -64,7 +64,7 @@ function dec2hex(d, padding) return hex; } -function getStyle(x,IEstyleProp, MozStyleProp) +function getStyle(x,IEstyleProp, MozStyleProp) { if (x.currentStyle) { var y = x.currentStyle[IEstyleProp]; @@ -91,14 +91,14 @@ function getStyle(x,IEstyleProp, MozStyleProp) param[i-2] = arguments[i]; } } - + if(typeof(fn)=='function') { - + return (function (fn,ms,param) { var fo = function () { fn.apply(window,param); }; - return nativeSetInterval(fo,ms); + return nativeSetInterval(fo,ms); })(fn,ms,param); } else if(typeof(fn)=='string') @@ -123,9 +123,9 @@ function getStyle(x,IEstyleProp, MozStyleProp) param[i-2] = arguments[i]; } } - + if(typeof(fn)=='function') { - + return (function (fn,ms,param) { var fo = function () { fn.apply(window,param); @@ -235,7 +235,7 @@ function update_images() function preload_images(arr,idx) { var im = new Image; - + // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.
"; im.onload = update_images; im.onerror = error_images; @@ -268,7 +268,7 @@ function send_mesg(mesg) { var xhr_wr = createXMLHttpRequest(); var is_conn = (sess == "not_connected" ? false : true); - + // alert("xhr_wr: "+xhr_wr+" is_conn: "+is_conn); xhr_wr.open('GET', 'index_wr.php?&'+(is_conn ? 'sess='+sess : '')+'&stp='+gst.st+'&mesg='+mesg, (is_conn ? true : false)); xhr_wr.setRequestHeader("If-Modified-Since", new Date().toUTCString()); @@ -315,7 +315,7 @@ function server_request() // alert("Args: "+arguments.length); var is_conn = (sess == "not_connected" ? false : true); - + // console.log("server_request:preresp: "+xhr_wr.responseText); if (is_post) { @@ -327,7 +327,7 @@ function server_request() } xhr_wr.onreadystatechange = function() { return; }; xhr_wr.send(post_collect); - + if (xhr_wr.responseText != null) { // console.log("server_request:resp: "+xhr_wr.responseText); return (xhr_wr.responseText); @@ -572,18 +572,18 @@ slowimg.prototype = { tout: 0, action: null, srcend: null, - + setstart: function(x0,y0) { this.x0 = x0; this.y0 = y0; }, - + setaction: function(act) { this.action = act; }, - + settime: function(time) { @@ -598,17 +598,17 @@ slowimg.prototype = { this.step_free = parseInt(this.step_n * this.free); } }, - + start: function(st) { // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART
"; this.st = st; this.st.st_loc_new++; - + this.img.style.visibility = "visible"; setTimeout(function(obj){ obj.animate(); }, this.deltat, this); }, - + animate: function() { // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "
"; @@ -825,11 +825,11 @@ function notify_ex(st, text, tout, butt, w, h, is_opa, block_time) { var clo, box; var t = this; - + this.st = st; this.ancestor = document.body; - + this.st.st_loc_new++; clo = document.createElement("input"); @@ -878,9 +878,9 @@ function notify_ex(st, text, tout, butt, w, h, is_opa, block_time) box.style.visibility = "visible"; this.notitag = box; - + this.ancestor.appendChild(box); - + this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this); if (block_time != 0) { @@ -910,7 +910,7 @@ notify_ex.prototype = { this.st.st_loc++; } }, - + hide: function() { clearTimeout(this.toutid); @@ -929,7 +929,7 @@ function notify(st, text, tout, butt, w, h) { notify_ex.call(this, st, text, tout, butt, w, h, false, 0); } - + function globst() { this.st = -1; this.st_loc = -1; @@ -964,7 +964,7 @@ globst.prototype = { function remark_step() { var ct = $("remark").l_remct; - + if (ct != 0) { ct++; if (ct > 2) @@ -975,7 +975,7 @@ function remark_step() } else $("remark").className = "remark0"; - + return; } @@ -1057,7 +1057,7 @@ function user_dec_and_state(el) content = user_decorator(el, true); content += state_add(el[0],(typeof(el[2]) != 'undefined' ? el[2] : null)); - + return (content); } @@ -1092,7 +1092,7 @@ function chatt_sub(dt,data,str) } // $("txt").innerHTML; - + if (must_scroll) { $("txt").scrollTop = 10000000; } @@ -1134,12 +1134,12 @@ function onbeforeunload_cb () { } function onunload_cb () { - + if (typeof(xstm) != "undefined") xstm.the_end = true; act_shutdown(); - + return(false); } @@ -1189,7 +1189,7 @@ function unescapeHTML(cont) { var length = div.childNodes.length, results = new Array(length); while (length--) results[length] = div.childNodes[length]; - + for (i=0 ; i' + -'' + -'' + -''; - } +/* + samples = [{'name': , 'file': }, ... ] +*/ +function jukebox(samples) +{ + var source, a; + this.enable = false; + this.audio = {}; + + var pro_audio_el = document.createElement('audio'); + this.enable = !!(pro_audio_el.canPlayType && pro_audio_el.canPlayType('audio/mpeg;').replace(/no/, '')); + if (this.enable) { + for (i in samples) { + sample = samples[i]; + + this.audio[sample['name']] = a = document.createElement('audio'); + + source = document.createElement('source'); + source.setAttribute('src', sample['file']); + source.setAttribute('type', 'audio/mpeg'); + a.appendChild(source); + a.load(); + } + } +} + +jukebox.prototype = { + is_enabled: function() { + return this.enable; + }, + + play: function(name) { + var a; + if (! this.enable) + return; + + if (!(name in this.audio)) { + return false; + } + a = this.audio[name]; + a.currentTime = 0; + a.play(); + } } function topbanner_init() diff --git a/web/index.php b/web/index.php index 478d880..562dac8 100644 --- a/web/index.php +++ b/web/index.php @@ -1000,7 +1000,7 @@ supported by:
' . ( /* NOTE: here facebook or fake facebook */ (!$G_is_local && $_cookie_law_3party == 'true') ? '
-' : '' ) . '
+' : '' ) . '
%s %s @@ -1044,7 +1044,7 @@ var g_tables_auth_n = ; var g_tables_cert_n = ; var g_prefs, g_prefs_new = null; var g_listen; -var g_withflash = false; +var g_jukebox = null; var g_is_spawn = 0; var g_nd = null; var g_brow = null; @@ -1071,12 +1071,13 @@ window.onload = function() { sidebanners_init($G_sidebanner_idx); ?> - g_withflash = DetectFlashVer(6,0,0); - if (g_withflash == false) { - $("proflash").innerHTML = 'Audio con Flash.
'; + g_jukebox = new jukebox([]); + if (g_jukebox.is_enabled() == false) { + $("proaudio").innerHTML = 'Audio HTML5 non supportato.'; + } + else { + $("proaudioext").innerHTML = ""; } - else - $("proflashext").innerHTML = ""; $("nameid").focus(); } //--> @@ -1215,7 +1216,7 @@ cookie_law(null); var g_prefs, g_prefs_new = null; var g_listen; var g_is_spawn = 0; - var g_withflash = false; + var g_jukebox = null; var g_imgct = 0; var g_imgtot = g_preload_img_arr.length; var g_brow = null; @@ -1253,17 +1254,18 @@ cookie_law(null); sidebanners_init($G_sidebanner_idx); ?> sess = ""; -xstm = new xynt_streaming(window, , 2, null /* console */, gst, 'index_php', 'sess', sess, $('sandbox'), 'index_rd.php', function(com){eval(com);}); + xstm = new xynt_streaming(window, , 2, null /* console */, gst, 'index_php', 'sess', sess, $('sandbox'), 'index_rd.php', function(com){eval(com);}); xstm.hbit_set(heartbit); tra = new train($('room_tit')); window.onunload = onunload_cb; window.onbeforeunload = onbeforeunload_cb; - g_withflash = DetectFlashVer(6,0,0); - if (g_withflash == false) { - $("proflash").innerHTML = 'Audio con Flash.
'; + g_jukebox = new jukebox([]); + if (g_jukebox.is_enabled() == false) { + $("proaudio").innerHTML = 'Audio HTML5 non supportato.'; + } + else { + $("proaudioext").innerHTML = ""; } - else - $("proflashext").innerHTML = ""; // console.log("session from main: "+sess); xstm.start(); diff --git a/web/room.css b/web/room.css index 5666b0c..bb64dac 100644 --- a/web/room.css +++ b/web/room.css @@ -70,7 +70,7 @@ div.topmenu { padding: 2px 2px 0 2px; } -div.proflash { +div.proaudio { border: 1px solid gray; background-color: RGB(246,246,246); text-align: center; -- 2.17.1