View Full Version : New member in Chat sound problem
sv1cec
03-07-2005, 04:57 AM
Zero,
I did some mods to play a sound, when a new member enters the chat room. Basically, the mod is adding a parameter, $playsound in vBChat.php, which is then checked with an if conditional in chat_row_bot.
Here is the code I used in vBChat.php:
I first changed the bot message code, to accept a new parameter:
function BotMessage($msg = "",$room = 0,$foruser){
global $DB_site;
$DB_site->query("insert into ".TABLE_PREFIX."vbchat_store (s_postby,s_message,s_postime,s_foruser,s_forroom) values (-1,'".trim(addslashes($msg))."',".time().",{$foruser},'{$room}')");
}
Then, when a new user gets in, I set the $foruser to -1.
unset($Rooms); // Free some memory
// Did You Just Join This Room?
if(!$_GET['nojoin'] && $bbuserinfo['userid'] != ""){
BotMessage("{$bbuserinfo['username']} joined {$InRoom}",$bbuserinfo['vbchat_pref_in_room'], -1);
header("Location: vBChat.php?{$session['sessionurl']}&do=main&nojoin=1");
}
Then, when the bot message is created, I check if the s_foruser is -1, in which case the $playsound is set to 1, and then the s_foruser is reset to 0. In that way, only the first time the bot message is show, the sound will be played.
$playsound=0;
if($ThisMSG['s_postby'] == -1)
{
if ($ThisMSG['s_foruser']=='-1')
{
$playsound=1;
$DB_site->query("update ".TABLE_PREFIX."vbchat_store set s_foruser=0 where sid=$ThisMSG[sid]");
}
$BotMsg = $ThisMSG['s_message'];
eval('$chat_page .= "' . fetch_template('chat_row_bot') . '";');
$playsound=0;
}
The s_foruser is set to -1, whenever a new user enters, and then it is restored to 0, so that the sound does not play again and again, every time the bot message appears on the screen.
Here is my chat_row_bot template:
<tr>
<td nowrap="nowrap" valign="top" colspan='2'><font size='2' color='blue'><if condition="$playsound==1"><embed src="sounds/Sound1.wav" autostart="true" loop="0" hidden="true"></embed></if><b><center>>>> {$BotMsg} at {$ThisMSG['time']} <<<</center></b>
</td>
</tr>
My problem is that :
a) the sound is not played consistently
b) when it is played, I hear it as if it is played twice
Any help on that issue? The same code works OK for me, in other areas of the forum, where a sound is played.
As you understand, this is a feature suggestion for next release, LoL
UPDATE
As a matter of fact, it looks as if it works! I have probably done the last edits in the php file, while the twins were around, and never got the chance to upload it. As for the double sound, it comes from the two browsers I had open for testing (Firefox & IE). Crazy things happen.
IF others would like that addition, and if you think the code is OK, you may of course include it in your next release.
Rgds and tnx
Zero Tolerance
03-07-2005, 05:15 PM
Zero,
I did some mods to play a sound, when a new member enters the chat room. Basically, the mod is adding a parameter, $playsound in vBChat.php, which is then checked with an if conditional in chat_row_bot.
Here is the code I used in vBChat.php:
I first changed the bot message code, to accept a new parameter:
function BotMessage($msg = "",$room = 0,$foruser){
global $DB_site;
$DB_site->query("insert into ".TABLE_PREFIX."vbchat_store (s_postby,s_message,s_postime,s_foruser,s_forroom) values (-1,'".trim(addslashes($msg))."',".time().",{$foruser},'{$room}')");
}
Then, when a new user gets in, I set the $foruser to -1.
unset($Rooms); // Free some memory
// Did You Just Join This Room?
if(!$_GET['nojoin'] && $bbuserinfo['userid'] != ""){
BotMessage("{$bbuserinfo['username']} joined {$InRoom}",$bbuserinfo['vbchat_pref_in_room'], -1);
header("Location: vBChat.php?{$session['sessionurl']}&do=main&nojoin=1");
}
Then, when the bot message is created, I check if the s_foruser is -1, in which case the $playsound is set to 1, and then the s_foruser is reset to 0. In that way, only the first time the bot message is show, the sound will be played.
$playsound=0;
if($ThisMSG['s_postby'] == -1)
{
if ($ThisMSG['s_foruser']=='-1')
{
$playsound=1;
$DB_site->query("update ".TABLE_PREFIX."vbchat_store set s_foruser=0 where sid=$ThisMSG[sid]");
}
$BotMsg = $ThisMSG['s_message'];
eval('$chat_page .= "' . fetch_template('chat_row_bot') . '";');
$playsound=0;
}
The s_foruser is set to -1, whenever a new user enters, and then it is restored to 0, so that the sound does not play again and again, every time the bot message appears on the screen.
Here is my chat_row_bot template:
<tr>
<td nowrap="nowrap" valign="top" colspan='2'><font size='2' color='blue'><if condition="$playsound==1"><embed src="sounds/Sound1.wav" autostart="true" loop="0" hidden="true"></embed></if><b><center>>>> {$BotMsg} at {$ThisMSG['time']} <<<</center></b>
</td>
</tr>
My problem is that :
a) the sound is not played consistently
b) when it is played, I hear it as if it is played twice
Any help on that issue? The same code works OK for me, in other areas of the forum, where a sound is played.
As you understand, this is a feature suggestion for next release, LoL
UPDATE
As a matter of fact, it looks as if it works! I have probably done the last edits in the php file, while the twins were around, and never got the chance to upload it. As for the double sound, it comes from the two browsers I had open for testing (Firefox & IE). Crazy things happen.
IF others would like that addition, and if you think the code is OK, you may of course include it in your next release.
Rgds and tnx
Well i have a certain emulation of MSN Messenger planned for v2.4, where if your "not" on the window, then it will flash like it does on windows, and play a minor sound when someone "replies".
Glad to see you got it working though :)
- Zero Tolerance
sv1cec
03-07-2005, 06:13 PM
Well i have a certain emulation of MSN Messenger planned for v2.4, where if your "not" on the window, then it will flash like it does on windows, and play a minor sound when someone "replies".
Glad to see you got it working though :)
- Zero Tolerance
Yeap, it's working all right. How is that for a sound? A bit discrete, but it does let you know that someone is in there.
One remark, if you would allow me. On a relatively busy chat room, a sound and a flashing box in the task bar, whenever someone answers, will be too intruding. I guess that the sound and flash should occur, whenever some new person enters the chat. My idea of course, you are the master coder here, so I am sure you'll make a wise decision.
Sometimes, we have to trust the youngsters!! LoL
Zero Tolerance
03-07-2005, 06:30 PM
Yeap, it's working all right. How is that for a sound? A bit discrete, but it does let you know that someone is in there.
One remark, if you would allow me. On a relatively busy chat room, a sound and a flashing box in the task bar, whenever someone answers, will be too intruding. I guess that the sound and flash should occur, whenever some new person enters the chat. My idea of course, you are the master coder here, so I am sure you'll make a wise decision.
Sometimes, we have to trust the youngsters!! LoL
Good point .. hmm *thinks*, perhaps a user option in the chat preferences?
- Play Sound/Highlight Notification Upon User Posting New Message
- Play Sound/Highlight Notification Upon User Joining
- Don't play Sounds or Highlights
I think that would resolve it, everyone has the choice then :)
- Zero Tolerance
sv1cec
03-08-2005, 01:48 AM
Good point .. hmm *thinks*, perhaps a user option in the chat preferences?
- Play Sound/Highlight Notification Upon User Posting New Message
- Play Sound/Highlight Notification Upon User Joining
- Don't play Sounds or Highlights
I think that would resolve it, everyone has the choice then :)
- Zero Tolerance
Good idea, I agree! Any plans on the ... official release date?
UPDATE ON SOUND
Well, I guess I am not that lucky. The sound is inconsistent. Some times we hear it, some times we do not. And when we hear it, the focus of the chat window is lost, and you have to reload it to continue typing in the Post Message box.
I tried a different approach, which required me to add a column in the vbchat_datastore table. The code is much simpler, and it appears as if it is working much better now. Unfortunatelly, no users are in the chat and I can rely only on my local tests.
I use the number of users in the chat, as a test for playing or not playing the sound.
Here is the code, if you care:
$totalbefore=$DB_site->query_first("select d_numberofusers from ".TABLE_PREFIX."vbchat_datastore where did='1'");
if ($totalbefore['d_numberofusers']==$total_users_in_room)
{
$msg4='';
}
else
{
if ($totalbefore['d_numberofusers']<$total_users_in_room)
{
$msg4="<embed src='sounds/Sound12.wav' autostart='true' loop='0' hidden='true'></embed>";
}
else
{
$msg4='';
}
}
$chat_upage .= "<tr><td>$msg4</td></tr></table>";
$DB_site->query("update ".TABLE_PREFIX."vbchat_datastore set d_numberofusers = '{$total_users_in_room}' where did='1'");
$playsound=0;
eval('print_output("' . fetch_template('chat_iframe') . '");');
exit;
}
// ---------------------------------------------------
// End Main Chat Frame
// ---------------------------------------------------
The column d_numberofusers is where I store the number of users in the chat. Next time a refresh happens, I compare the actual number to the one stored. Unfortunatelly, this adds one more query , not a good thing, so if you can come up with a better approach, I'll follow you.
Rgds
wirewolf
04-08-2005, 12:19 AM
Hi sv1cec, I tried your embed sound in the chat_row template:
<embed src='/forum/sounds/SOUND12.WAV' autostart='true' loop='0' hidden='true'></embed>, it plays when you are in the room but it plays more than once and it seems to "rattle" the whole page when the room refreshes. Had to remove it. Oh well.
John
sv1cec
04-08-2005, 05:12 AM
You can't just add this to the chat_row template, because then it will play for every message that is printed on the screen.
I have managed to have a sound played when new members are added to the chat, but it's a complicated thing. I have to keep track of how many users are currently in chat and every time this number is raised, I play the sound. Nice to have, but the implications make it silly. Let alone, that if a member is going back and forth between the forums and the chat, then the members number keeps going up and down and the sound is played again and again.
Oh well, .....
attroll
04-18-2005, 02:09 AM
Good point .. hmm *thinks*, perhaps a user option in the chat preferences?
- Play Sound/Highlight Notification Upon User Posting New Message
- Play Sound/Highlight Notification Upon User Joining
- Don't play Sounds or Highlights
I think that would resolve it, everyone has the choice then :)
- Zero Tolerance
That would be an awesome option. I have a chat room using this hack and it is not a buisy chat room all the time. But I am always doing things on the computer and keep forgetting to see if someone has replied in the chat room. So I would really like this option? Will it be ready soon or is this a ways off?
sv1cec
04-18-2005, 03:58 AM
I have no idea, it all depends on Zero's availability.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.