Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Poner sonidos en chat

Estas en el tema de Poner sonidos en chat en el foro de Frameworks JS en Foros del Web. Buenos dias! Tengo un chat ya en funcionamiento que cuando yegan los mensajes cambia de color parapadeando, lo que me gustaria poner tambien algun sonido ...
  #1 (permalink)  
Antiguo 09/08/2012, 04:48
 
Fecha de Ingreso: noviembre-2011
Mensajes: 516
Antigüedad: 12 años, 4 meses
Puntos: 10
Poner sonidos en chat

Buenos dias!
Tengo un chat ya en funcionamiento que cuando yegan los mensajes cambia de color parapadeando, lo que me gustaria poner tambien algun sonido para que te enteres de que te yego un mensaje, como podria hacer esto??? otra cosa que me gustaría hacerle es que al cambiar de web dentro de la misma es decir del index.php a otra web no se me cierren las ventanitas abiertas del chat como puedo conseguir estas dos cosas??? gracias. un saludo.
  #2 (permalink)  
Antiguo 09/08/2012, 18:35
Avatar de flashmax  
Fecha de Ingreso: julio-2012
Ubicación: Bs.As. Argentina
Mensajes: 507
Antigüedad: 11 años, 8 meses
Puntos: 86
Respuesta: Poner sonidos en chat

sin código o links de tu sitio sera imposible que te ayuden!
  #3 (permalink)  
Antiguo 10/08/2012, 04:56
 
Fecha de Ingreso: noviembre-2011
Mensajes: 516
Antigüedad: 12 años, 4 meses
Puntos: 10
Respuesta: Poner sonidos en chat

Si perdonen por no poner el codigo, donde quiero poner el sonido al chat es este:
chat.js
[HIGHLIGHT="Javascript"]
var windowFocus = true;
var username;
var chatHeartbeatCount = 0;
var minChatHeartbeat = 1000;
var maxChatHeartbeat = 33000;
var chatHeartbeatTime = minChatHeartbeat;
var originalTitle;
var blinkOrder = 0;

var chatboxFocus = new Array();
var newMessages = new Array();
var newMessagesWin = new Array();
var chatBoxes = new Array();

function restructureChatBoxes() {
align = 0;
for (x in chatBoxes) {
chatboxtitle = chatBoxes[x];

if ($("#chatbox_"+chatboxtitle).css('display') != 'none') {
if (align == 0) {
$("#chatbox_"+chatboxtitle).css('right', '20px');
} else {
width = (align)*(225+7)+20;
$("#chatbox_"+chatboxtitle).css('right', width+'px');
}
align++;
}
}
}

function chatWith(chatuser) {
createChatBox(chatuser);
$("#chatbox_"+chatuser+" .chatboxtextarea").focus();
}

function createChatBox(chatboxtitle,minimizeChatBox) {
if ($("#chatbox_"+chatboxtitle).length > 0) {
if ($("#chatbox_"+chatboxtitle).css('display') == 'none') {
$("#chatbox_"+chatboxtitle).css('display','block') ;
restructureChatBoxes();
}
$("#chatbox_"+chatboxtitle+" .chatboxtextarea").focus();
return;
}

$(" <div />" ).attr("id","chatbox_"+chatboxtitle)
.addClass("chatbox")
.html('<div class="chatboxhead"><div class="chatboxtitle">'+chatboxtitle+'</div><div class="chatboxoptions"><a href="javascript:void(0)" onclick="javascript:toggleChatBoxGrowth(\''+chatbo xtitle+'\')">-</a> <a href="javascript:void(0)" onclick="javascript:closeChatBox(\''+chatboxtitle+ '\')">X</a></div><br clear="all"/></div><div class="chatboxcontent"></div><div class="chatboxinput"><textarea class="chatboxtextarea" onkeydown="javascript:return checkChatBoxInputKey(event,this,\''+chatboxtitle+' \');"></textarea></div>')
.appendTo($( "body" ));

$("#chatbox_"+chatboxtitle).css('bottom', '0px');

chatBoxeslength = 0;

for (x in chatBoxes) {
if ($("#chatbox_"+chatBoxes[x]).css('display') != 'none') {
chatBoxeslength++;
}
}

if (chatBoxeslength == 0) {
$("#chatbox_"+chatboxtitle).css('right', '20px');
} else {
width = (chatBoxeslength)*(225+7)+20;
$("#chatbox_"+chatboxtitle).css('right', width+'px');
}

chatBoxes.push(chatboxtitle);

if (minimizeChatBox == 1) {
minimizedChatBoxes = new Array();

if ($.cookie('chatbox_minimized')) {
minimizedChatBoxes = $.cookie('chatbox_minimized').split(/\|/);
}
minimize = 0;
for (j=0;j<minimizedChatBoxes.length;j++) {
if (minimizedChatBoxes[j] == chatboxtitle) {
minimize = 1;
}
}

if (minimize == 1) {
$('#chatbox_'+chatboxtitle+' .chatboxcontent').css('display','none');
$('#chatbox_'+chatboxtitle+' .chatboxinput').css('display','none');
}
}

chatboxFocus[chatboxtitle] = false;

$("#chatbox_"+chatboxtitle+" .chatboxtextarea").blur(function(){
chatboxFocus[chatboxtitle] = false;
$("#chatbox_"+chatboxtitle+" .chatboxtextarea").removeClass('chatboxtextareasel ected');
}).focus(function(){
chatboxFocus[chatboxtitle] = true;
newMessages[chatboxtitle] = false;
$('#chatbox_'+chatboxtitle+' .chatboxhead').removeClass('chatboxblink');
$("#chatbox_"+chatboxtitle+" .chatboxtextarea").addClass('chatboxtextareaselect ed');
});

$("#chatbox_"+chatboxtitle).click(function() {
if ($('#chatbox_'+chatboxtitle+' .chatboxcontent').css('display') != 'none') {
$("#chatbox_"+chatboxtitle+" .chatboxtextarea").focus();
}
});

$("#chatbox_"+chatboxtitle).show();
}


function chatHeartbeat(){

var itemsfound = 0;

if (windowFocus == false) {

var blinkNumber = 0;
var titleChanged = 0;
for (x in newMessagesWin) {
if (newMessagesWin[x] == true) {
++blinkNumber;
if (blinkNumber >= blinkOrder) {
document.title = x+' a enviado...';
titleChanged = 1;
break;
}
}
}

if (titleChanged == 0) {
document.title = originalTitle;
blinkOrder = 0;
} else {
++blinkOrder;
}

} else {
for (x in newMessagesWin) {
newMessagesWin[x] = false;
}
}

for (x in newMessages) {
if (newMessages[x] == true) {
if (chatboxFocus[x] == false) {
//FIXME: add toggle all or none policy, otherwise it looks funny
$('#chatbox_'+x+' .chatboxhead').toggleClass('chatboxblink');
}
}
}

$.ajax({
url: "chat.php?action=chatheartbeat",
cache: false,
dataType: "json",
success: function(data) {

$.each(data.items, function(i,item){
if (item) { // fix strange ie bug

chatboxtitle = item.f;

if ($("#chatbox_"+chatboxtitle).length <= 0) {
createChatBox(chatboxtitle);
}
if ($("#chatbox_"+chatboxtitle).css('display') == 'none') {
$("#chatbox_"+chatboxtitle).css('display','block') ;
restructureChatBoxes();
}

if (item.s == 1) {
item.f = username;
}

if (item.s == 2) {
$("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
} else {
newMessages[chatboxtitle] = true;
newMessagesWin[chatboxtitle] = true;
$("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+item.f+':&nbsp;&nbsp; </span><span class="chatboxmessagecontent">'+item.m+'</span></div>');
}

$("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxt itle+" .chatboxcontent")[0].scrollHeight);
itemsfound += 1;
}
});

chatHeartbeatCount++;

if (itemsfound > 0) {
chatHeartbeatTime = minChatHeartbeat;
chatHeartbeatCount = 1;
} else if (chatHeartbeatCount >= 10) {
chatHeartbeatTime *= 2;
chatHeartbeatCount = 1;
if (chatHeartbeatTime > maxChatHeartbeat) {
chatHeartbeatTime = maxChatHeartbeat;
}
}

setTimeout('chatHeartbeat();',chatHeartbeatTime);
}});
}

function closeChatBox(chatboxtitle) {
$('#chatbox_'+chatboxtitle).css('display','none');
restructureChatBoxes();

$.post("chat.php?action=closechat", { chatbox: chatboxtitle} , function(data){
});

}

function toggleChatBoxGrowth(chatboxtitle) {
if ($('#chatbox_'+chatboxtitle+' .chatboxcontent').css('display') == 'none') {

var minimizedChatBoxes = new Array();

if ($.cookie('chatbox_minimized')) {
minimizedChatBoxes = $.cookie('chatbox_minimized').split(/\|/);
}

var newCookie = '';

for (i=0;i<minimizedChatBoxes.length;i++) {
if (minimizedChatBoxes[i] != chatboxtitle) {
newCookie += chatboxtitle+'|';
}
}

newCookie = newCookie.slice(0, -1)


$.cookie('chatbox_minimized', newCookie);
$('#chatbox_'+chatboxtitle+' .chatboxcontent').css('display','block');
$('#chatbox_'+chatboxtitle+' .chatboxinput').css('display','block');
$("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxt itle+" .chatboxcontent")[0].scrollHeight);
} else {

var newCookie = chatboxtitle;

if ($.cookie('chatbox_minimized')) {
newCookie += '|'+$.cookie('chatbox_minimized');
}


$.cookie('chatbox_minimized',newCookie);
$('#chatbox_'+chatboxtitle+' .chatboxcontent').css('display','none');
$('#chatbox_'+chatboxtitle+' .chatboxinput').css('display','none');
}

}

function checkChatBoxInputKey(event,chatboxtextarea,chatbox title) {

if(event.keyCode == 13 && event.shiftKey == 0) {
message = $(chatboxtextarea).val();
message = message.replace(/^\s+|\s+$/g,"");

$(chatboxtextarea).val('');
$(chatboxtextarea).focus();
$(chatboxtextarea).css('height','44px');
if (message != '') {
$.post("chat.php?action=sendchat", {to: chatboxtitle, message: message} , function(data){
message = message.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");
$("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+username+':&nbsp;&nbs p;</span><span class="chatboxmessagecontent">'+message+'</span></div>');
$("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxt itle+" .chatboxcontent")[0].scrollHeight);
});
}
chatHeartbeatTime = minChatHeartbeat;
chatHeartbeatCount = 1;

return false;
}

var adjustedHeight = chatboxtextarea.clientHeight;
var maxHeight = 94;

if (maxHeight > adjustedHeight) {
adjustedHeight = Math.max(chatboxtextarea.scrollHeight, adjustedHeight);
if (maxHeight)
adjustedHeight = Math.min(maxHeight, adjustedHeight);
if (adjustedHeight > chatboxtextarea.clientHeight)
$(chatboxtextarea).css('height',adjustedHeight+8 +'px');
} else {
$(chatboxtextarea).css('overflow','auto');
}

}
HIGHLIGHT]
  #4 (permalink)  
Antiguo 10/08/2012, 04:57
 
Fecha de Ingreso: noviembre-2011
Mensajes: 516
Antigüedad: 12 años, 4 meses
Puntos: 10
Respuesta: Poner sonidos en chat

segunda parte del chat.js
Código Javascript:
Ver original
  1. function startChatSession(){  
  2.     $.ajax({
  3.       url: "chat.php?action=startchatsession",
  4.       cache: false,
  5.       dataType: "json",
  6.       success: function(data) {
  7.  
  8.         username = data.username;
  9.  
  10.         $.each(data.items, function(i,item){
  11.             if (item)   {
  12.                 chatboxtitle = item.f;
  13.  
  14.                 if ($("#chatbox_"+chatboxtitle).length <= 0) {
  15.                     createChatBox(chatboxtitle,1);
  16.                 }
  17.                
  18.                 if (item.s == 1) {
  19.                     item.f = username;
  20.                 }
  21.  
  22.                 if (item.s == 2) {
  23.                     $("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
  24.                 } else {
  25.                     $("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+item.f+':&nbsp;&nbsp;</span><span class="chatboxmessagecontent">'+item.m+'</span></div>');
  26.                 }
  27.             }
  28.         });
  29.        
  30.         for (i=0;i<chatBoxes.length;i++) {
  31.             chatboxtitle = chatBoxes[i];
  32.             $("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);
  33.             setTimeout('$("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);', 100); }
  34.     setTimeout('chatHeartbeat();',chatHeartbeatTime);
  35.        
  36.     }});
  37. }
  38. jQuery.cookie = function(name, value, options) {
  39.     if (typeof value != 'undefined') {
  40.         options = options || {};
  41.         if (value === null) {
  42.             value = '';
  43.             options.expires = -1;
  44.         }
  45.         var expires = '';
  46.         if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  47.             var date;
  48.             if (typeof options.expires == 'number') {
  49.                 date = new Date();
  50.                 date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  51.             } else {
  52.                 date = options.expires;
  53.             }
  54.             expires = '; expires=' + date.toUTCString();
  55.         }
  56.         var path = options.path ? '; path=' + (options.path) : '';
  57.         var domain = options.domain ? '; domain=' + (options.domain) : '';
  58.         var secure = options.secure ? '; secure' : '';
  59.         document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  60.     } else {
  61.         var cookieValue = null;
  62.         if (document.cookie && document.cookie != '') {
  63.             var cookies = document.cookie.split(';');
  64.             for (var i = 0; i < cookies.length; i++) {
  65.                 var cookie = jQuery.trim(cookies[i]);
  66.                 if (cookie.substring(0, name.length + 1) == (name + '=')) {
  67.                     cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  68.                     break;
  69.                 }
  70.             }
  71.         }
  72.         return cookieValue;
  73.     }
  74. };
Y estos son codigos de php
chat.php
Código PHP:
Ver original
  1. define ('DBPATH','localhost');
  2. define ('DBUSER','root');
  3. define ('DBPASS','pass');
  4. define ('DBNAME','chat');
  5.  
  6. session_start();
  7.  
  8. global $dbh;
  9. $dbh = mysql_connect(DBPATH,DBUSER,DBPASS);
  10. mysql_selectdb(DBNAME,$dbh);
  11.  
  12. if ($_GET['action'] == "chatheartbeat") { chatHeartbeat(); }
  13. if ($_GET['action'] == "sendchat") { sendChat(); }
  14. if ($_GET['action'] == "closechat") { closeChat(); }
  15. if ($_GET['action'] == "startchatsession") { startChatSession(); }
  16.  
  17. if (!isset($_SESSION['chatHistory'])) {
  18.     $_SESSION['chatHistory'] = array();
  19. }
  20.  
  21. if (!isset($_SESSION['openChatBoxes'])) {
  22.     $_SESSION['openChatBoxes'] = array();  
  23. }
  24.  
  25. function chatHeartbeat() {
  26.    
  27.     $sql = "select * from chat where (chat.to = '".mysql_real_escape_string($_SESSION['logueado_nombre'])."' AND recd = 0) order by id ASC";
  28.     $query = mysql_query($sql);
  29.     $items = '';
  30.  
  31.     $chatBoxes = array();
  32.  
  33.     while ($chat = mysql_fetch_array($query)) {
  34.  
  35.         if (!isset($_SESSION['openChatBoxes'][$chat['from']]) && isset($_SESSION['chatHistory'][$chat['from']])) {
  36.             $items = $_SESSION['chatHistory'][$chat['from']];
  37.         }
  38.  
  39.         $chat['message'] = sanitize($chat['message']);
  40.  
  41.         $items .= <<<EOD
  42.                        {
  43.             "s": "0",
  44.             "f": "{$chat['from']}",
  45.             "m": "{$chat['message']}"
  46.        },
  47. EOD;
  48.  
  49.     if (!isset($_SESSION['chatHistory'][$chat['from']])) {
  50.         $_SESSION['chatHistory'][$chat['from']] = '';
  51.     }
  52.  
  53.     $_SESSION['chatHistory'][$chat['from']] .= <<<EOD
  54.                            {
  55.             "s": "0",
  56.             "f": "{$chat['from']}",
  57.             "m": "{$chat['message']}"
  58.        },
  59. EOD;
  60.        
  61.         unset($_SESSION['tsChatBoxes'][$chat['from']]);
  62.         $_SESSION['openChatBoxes'][$chat['from']] = $chat['sent'];
  63.     }
  64.  
  65.     if (!empty($_SESSION['openChatBoxes'])) {
  66.     foreach ($_SESSION['openChatBoxes'] as $chatbox => $time) {
  67.         if (!isset($_SESSION['tsChatBoxes'][$chatbox])) {
  68.             $now = time()-strtotime($time);
  69.             $time = date('g:iA M dS', strtotime($time));
  70.  
  71.             $message = "Sent at $time";
  72.             if ($now > 180) {
  73.                 $items .= <<<EOD
  74. {
  75. "s": "2",
  76. "f": "$chatbox",
  77. "m": "{$message}"
  78. },
  79. EOD;
  80.  
  81.     if (!isset($_SESSION['chatHistory'][$chatbox])) {
  82.         $_SESSION['chatHistory'][$chatbox] = '';
  83.     }
  84.  
  85.     $_SESSION['chatHistory'][$chatbox] .= <<<EOD
  86.         {
  87. "s": "2",
  88. "f": "$chatbox",
  89. "m": "{$message}"
  90. },
  91. EOD;
  92.             $_SESSION['tsChatBoxes'][$chatbox] = 1;
  93.         }
  94.         }
  95.     }
  96. }
  97.  
  98.     $sql = "update chat set recd = 1 where chat.to = '".mysql_real_escape_string($_SESSION['logueado_nombre'])."' and recd = 0";
  99.     $query = mysql_query($sql);
  100.  
  101.     if ($items != '') {
  102.         $items = substr($items, 0, -1);
  103.     }
  104. header('Content-type: application/json');
  105. ?>
  106. {
  107.         "items": [
  108.             <?php echo $items;?>
  109.         ]
  110. }
  111.  
  112. <?php
  113.             exit(0);
  114. }
  115.  
  116. function chatBoxSession($chatbox) {
  117.    
  118.     $items = '';
  119.    
  120.     if (isset($_SESSION['chatHistory'][$chatbox])) {
  121.         $items = $_SESSION['chatHistory'][$chatbox];
  122.     }
  123.  
  124.     return $items;
  125. }
  126.  
  127. function startChatSession() {
  128.     $items = '';
  129.     if (!empty($_SESSION['openChatBoxes'])) {
  130.         foreach ($_SESSION['openChatBoxes'] as $chatbox => $void) {
  131.             $items .= chatBoxSession($chatbox);
  132.         }
  133.     }
  134.  
  135.  
  136.     if ($items != '') {
  137.         $items = substr($items, 0, -1);
  138.     }
  139.  
  140. header('Content-type: application/json');
  141. ?>
  142. {
  143.         "username": "<?php echo $_SESSION['logueado_nombre'];?>",
  144.         "items": [
  145.             <?php echo $items;?>
  146.         ]
  147. }
  148.  
  149. <?php
  150.  
  151.  
  152.     exit(0);
  153. }
  154.  
  155. function sendChat() {
  156.     $from = $_SESSION['logueado_nombre'];
  157.     $to = $_POST['to'];
  158.     $message = $_POST['message'];
  159.  
  160.     $_SESSION['openChatBoxes'][$_POST['to']] = date('Y-m-d H:i:s', time());
  161.    
  162.     $messagesan = sanitize($message);
  163.  
  164.     if (!isset($_SESSION['chatHistory'][$_POST['to']])) {
  165.         $_SESSION['chatHistory'][$_POST['to']] = '';
  166.     }
  167.  
  168.     $_SESSION['chatHistory'][$_POST['to']] .= <<<EOD
  169.                        {
  170.             "s": "1",
  171.             "f": "{$to}",
  172.             "m": "{$messagesan}"
  173.        },
  174. EOD;
  175.  
  176.  
  177.     unset($_SESSION['tsChatBoxes'][$_POST['to']]);
  178.  
  179.     $sql = "insert into chat (chat.from,chat.to,message,sent) values ('".mysql_real_escape_string($from)."', '".mysql_real_escape_string($to)."','".mysql_real_escape_string($message)."',NOW())";
  180.     $query = mysql_query($sql);
  181.     echo "1";
  182.     exit(0);
  183. }
  184.  
  185. function closeChat() {
  186.  
  187.     unset($_SESSION['openChatBoxes'][$_POST['chatbox']]);
  188.    
  189.     echo "1";
  190.     exit(0);
  191. }
  192.  
  193. function sanitize($text) {
  194.     $text = htmlspecialchars($text, ENT_QUOTES);
  195.     $text = str_replace("\n\r","\n",$text);
  196.     $text = str_replace("\r\n","\n",$text);
  197.     $text = str_replace("\n","<br>",$text);
  198.     return $text;
  199. }
Consulta_chat.php
Código PHP:
Ver original
  1. <?php
  2. $nombre =$_SESSION['logueado_nombre'];
  3. $id_usuario=$_SESSION['logueado_id'];  
  4.  
  5.  
  6. include("db.php"); ?>
  7. <?php
  8.  
  9. $conexion=mysql_connect("localhost","root","pass")or
  10.   die("Problemas en la conexion");
  11. mysql_select_db("chat",$conexion) or
  12.   die("Problemas en la selección de la base de datos");
  13. $registros=mysql_query("select * from usuarios where id<>'$id_usuario' and online='1'",$conexion) or
  14.   die("Problemas en el select:".mysql_error());
  15.   $online=mysql_query("select * from usuarios where id='$id_usuario'",$conexion);
  16.   $onl=mysql_fetch_array($online);
  17.   if($onl['online']=='1'){
  18.   while ($reg=mysql_fetch_array($registros))
  19.   {
  20.   echo "<a href=\"javascript:void(0)\" onClick=\"chatWith('$reg[nombre]');\" ><img src=\"$reg[imagen]\"style=\"width:30px; border:none;\"></img>$reg[nombre]</a>";
  21.   echo "<br><br>";}
  22.        
  23.   }
  24. ?>
minichat.php
Código PHP:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd" >
  2.  
  3. <html>
  4. <head>
  5. <title>Sample Chat Application</title>
  6. <style>
  7. body {
  8.     padding:0;
  9.     margin:0 auto;
  10.     font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;
  11.     font-size:11px;
  12. }
  13. /*a:visited { color:#33FF33} */
  14. img:visited{color:#660000}
  15. </style>
  16.  
  17. <link type="text/css" rel="stylesheet" media="all" href="css/chat.css" />
  18. <link type="text/css" rel="stylesheet" media="all" href="css/screen.css" />
  19.  
  20. <!--[if lte IE 7]>
  21. <link type="text/css" rel="stylesheet" media="all" href="css/screen_ie.css" />
  22. <![endif]-->
  23.  
  24. </head>
  25. <body>
  26. <div id="formulario" style="float:right; margin-top:-80px; margin-right:30px;" ><?php include('consulta_id.php'); ?></div>
  27. <div id="cajon_chat" style=" border:double;  border:#000000; float:right; width:130px; margin-top::10px;">
  28.  
  29. <div id="main_container" style="overflow:auto;">
  30.  
  31. <!-- YOUR BODY HERE -->
  32. </div>
  33. </div>
  34.  
  35. <script type="text/javascript" src="js/jquery.js"></script>
  36. <script type="text/javascript" src="js/chat.js"></script>
  37. <script type="text/javascript" src="js/funciones_chat.js"></script>
  38. <script type="text/javascript" src="ajax1.js"></script>
  39. </body>
  40. </html>
  #5 (permalink)  
Antiguo 10/08/2012, 04:57
 
Fecha de Ingreso: noviembre-2011
Mensajes: 516
Antigüedad: 12 años, 4 meses
Puntos: 10
Respuesta: Poner sonidos en chat

y por ultimo
consulta_id.php
Código PHP:
Ver original
  1. <?php
  2. $nombre =$_SESSION['logueado_nombre'];
  3. $id_usuario=$_SESSION['logueado_id'];
  4. //Desarrollado por Jesus Liñán
  5. //ribosomatic.com
  6. //Puedes hacer lo que quieras con el código
  7. //pero visita la web cuando te acuerdes
  8.  
  9. //Configuracion de la conexion a base de datos
  10. $bd_host = "localhost";
  11. $bd_usuario = "root";
  12. $bd_password = "pass";
  13. $bd_base = "muroredsocial";
  14. $con = mysql_connect($bd_host, $bd_usuario, $bd_password);
  15. mysql_select_db($bd_base, $con);
  16.  
  17. //consulta los datos del empleado por su id
  18.  
  19. $sql=mysql_query("SELECT * FROM usuarios WHERE id=$id_usuario",$con);
  20.  
  21. $row = mysql_fetch_array($sql);
  22. $con=$row['online'];
  23.  
  24. if($con=='1')
  25. { ?>
  26. <form name="forchat" action=""
  27. onsubmit="enviarDatosEmpleado(); return false">
  28.     <input name="id" type="hidden" value="<?php echo $id_usuario; ?>" />
  29.  
  30.   </p>
  31.    <input type="hidden" name="online" value="0" />
  32.   <p>
  33.     <input type="submit" name="Submit" value="Desconectar" style=" background:#0099FF" />
  34.   </p>
  35. </form>
  36.  
  37. <?php }
  38. else
  39. {
  40. ?>
  41. <form name="forchat" action=""
  42. onsubmit="enviarDatosEmpleado(); return false">
  43.     <input name="id" type="hidden" value="<?php echo $id_usuario; ?>" />
  44.  
  45.   </p>
  46.    <input type="hidden" name="online" value="1" />
  47.   <p>
  48.     <input type="submit" name="Submit" value="Conectar"style=" background:#0099FF"  />
  49.   </p>
  50. </form>
  51. <?php
  52. }
  53.  
  54. ?>
  55.  
  56. <script type="text/javascript" src="Js/jquery.js"></script>
  57. <script type="text/javascript" src="ajax1.js"></script>
Nose si se me olvida algun codigo, espero que no, gracias y un saludo.
  #6 (permalink)  
Antiguo 13/08/2012, 15:47
 
Fecha de Ingreso: noviembre-2011
Mensajes: 516
Antigüedad: 12 años, 4 meses
Puntos: 10
Respuesta: Poner sonidos en chat

Nadie me da alguna idea de como se puede hacer esto si es que se puede?? os agradecería mucho si me dijerais si se puede o no se puede hacer tal cosa. gracias.
  #7 (permalink)  
Antiguo 13/08/2012, 16:22
Avatar de utan  
Fecha de Ingreso: agosto-2012
Mensajes: 126
Antigüedad: 11 años, 8 meses
Puntos: 17
Respuesta: Poner sonidos en chat

Cita:
Iniciado por edie8 Ver Mensaje
Nadie me da alguna idea de como se puede hacer esto si es que se puede?? os agradecería mucho si me dijerais si se puede o no se puede hacer tal cosa. gracias.
Tendrias que conocer bien el script para localizar donde es que el evento de recivir mensajes, cuando un usuario se logeo o cuando el ususario termina la session..

Si estubieras al tanto, pues se puede crear un elemento wrappeado con flash y creas swf archivo con los sonidos..

pero precisamente en conecer el codigo esta el detalle...
__________________
Mis conocimientos son limitado, pero si te puedo ayudar lo are gustoso mi chat particular, visitalo gracias http://rendezvouschat.com
  #8 (permalink)  
Antiguo 14/08/2012, 07:52
3nr1c
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Poner sonidos en chat

Lo de mantener abiertas las pestañas es complicado... Yo lo hice en un chat a imitación del de FB. Tienes que guardar en una base de datos las conversaciones que están activas, y las que están abiertas, y al cargar una página recuperar esa información (con JS).

En cuanto al aviso sonoro... Necesitas un par de archivos con el mismo sonido, en diferentes extensiones. Luego, usar la nueva Audio API de JS:
https://wiki.mozilla.org/Audio_Data_API


Claro que el problema está en los navegadores que soportan el Audio API (aunque esto ya es otra cosa ):
http://caniuse.com/#feat=audio-api

Un saludo!
  #9 (permalink)  
Antiguo 15/08/2012, 15:05
 
Fecha de Ingreso: noviembre-2011
Mensajes: 516
Antigüedad: 12 años, 4 meses
Puntos: 10
Respuesta: Poner sonidos en chat

Cita:
Iniciado por 3nr1c Ver Mensaje
Lo de mantener abiertas las pestañas es complicado... Yo lo hice en un chat a imitación del de FB. Tienes que guardar en una base de datos las conversaciones que están activas, y las que están abiertas, y al cargar una página recuperar esa información (con JS).

En cuanto al aviso sonoro... Necesitas un par de archivos con el mismo sonido, en diferentes extensiones. Luego, usar la nueva Audio API de JS:
https://wiki.mozilla.org/Audio_Data_API


Claro que el problema está en los navegadores que soportan el Audio API (aunque esto ya es otra cosa ):
http://caniuse.com/#feat=audio-api

Un saludo!
Serias tan amable de ponerme el codigo que usaste en lo de las pestañas de tu web?? es para obtener una idea y poder sacar algo en claro. gracias por la ayuda, mirare lo del sonido... gracias.

Etiquetas: chat, funcion, php, sonidos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:09.