[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Звуковое оповещение при получении сообщения
Damel
Добрый день. Есть такой код. Это код чата.
chat.php
<?php
session_start();
if (!$_SESSION['user']) {
header('Location: /');
}
?>
<!DOCTYPE html>
<
html>
<
head>
<
meta charset="utf-8">
</
head>
<
body>
<
p><img src="logo2.png" alt="Письма мастера дзен"></p>
</
body>
</
html>

<!
DOCTYPE html>
<
html>
<
head>
<
meta charset="utf-8">
</
head>
<
body>
<
audio autoplay>
<
source src="audio/music.ogg" type='audio/ogg; codecs=vorbis'>
<
source src="7.mp3" type="audio/mpeg">
Тег audio не поддерживается вашим браузером. <a href="audio/music.mp3">Скачайте музыку</a>.
</
audio>
</
body>
</
html>

<!
DOCTYPE html>
<
head>
<
meta charset="utf-8">
<
title>Чат</title>
<
style>
body {
padding: 500px;
}
.qwer {
border: 5px double #fffff;
margin: 0 auto;
width: 500px;
}
h2 {
text-align: center;
}
#chat, table {
margin: 0 auto;
}
#chat {
border: 3px solid black;
height: 350px;
margin: 0 auto;
overflow-x: none;
overflow-y: auto;
width: 300px;
}
p {
margin: 0;
}
img {
width: 250px;
}

</style>
<
script src="script_chat.js">

</
script>

</
head>
<
body onload="chat();">
<
a href="profile.php" class="logout1">На главную</a>
<
div class="qwer">
<
h2>Чат</h2>
<
div id="chat" class="chat" name="chat">
</
div>
<
br>
<
table>
<
tr>
<
td>Имя:</td>
<
td><input id="name" value=<?= $_SESSION['user']['full_name'] ?> disabled></td>
</
div>
</
tr>
<
tr>
<
td>Cообщение:</td>
<
td><input type="text" name="message" id="message"></td>
</
tr>
<
tr>

<
td colspan="2">
<
input type="button" value="Отправить!" onclick="addMessage();">
</
td>
</
tr>
</
table>
<
style>
a.logout1 {
font-weight: 700;
color: white;
text-decoration: none;
padding: .8em 1em calc(.8em + 3px);
border-radius: 3px;
background: rgb(64,199,129);
box-shadow: 0 -3px rgb(53,167,110) inset;
transition: 0.2s;
}
a.logout1:hover { background: rgb(53, 167, 110); }
a.logout1:active {
background: rgb(33,147,90);
box-shadow: 0 3px rgb(33,147,90) inset;
}
</body>
</
html>


functions.php:
<?php
session_start();
if (!$_SESSION['user']) {
header('Location: /');
}
?>
<?php

if(isset($_POST["name"])) {
$name = $_POST["name"];
$message = $_POST["message"];
file_put_contents("messages.txt", file_get_contents("messages.txt")."\n$name;$message" );
require_once '1.php';


}
elseif(isset($_POST["update"])) {
$string = file_get_contents("messages.txt");
$array = explode("\n", $string);
$result = array();
for ($i = 0; $i < count($array); $i++) {
$temp = explode(";", $array[$i]);
$result[$i]["name"] = $temp[0];
$result[$i]["message"] = $temp[1];
}
echo json_encode($result);
}
?>


script_chat.js:

var array = new Array();
function getXmlHttp() {
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}

if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function chat() {
var xmlhttp = getXmlHttp();
xmlhttp.open("POST", "functions.php", true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send("update=1");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var response = xmlhttp.responseText;
response = JSON.parse(response);
//alert(response);
if (array.length == response.length) return;
var start = array.length;
array = response;
var messages = document.getElementById("chat").innerHTML;
for (i = start; i < array.length; i++) {
messages = messages + "<p><b>" + array[i].name + ":</b> " + array[i].message + "</p>";
}
document.getElementById("chat").innerHTML = messages;
document.getElementById("chat").scrollTop = 1000000;
}
}
}

setTimeout("chat()", 1000);
}
function addMessage () {
var xmlhttp = getXmlHttp();
var name = document.getElementById("name").value;
var message = document.getElementById("message").value;
xmlhttp.open("POST", "functions.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("name=" + encodeURIComponent(name) + "&message=" + encodeURIComponent(message));
alert("Сообщение отправлено!")
}

Notification.requestPermission(function(permission) {
alert(permission);
});

var notification = new Notification(title,
{
body: 'Господи, дай мне соурс-код Вселенной, час времени и хороший дебаггер!',
icon: 'img.png',
dir: 'auto',
tag: 'quote'
});

function sendNotify(title, options) {
// Проверка прав
if (Notification.permission === "granted") {
// Отправляем уведомление
var notification = new Notification(title, options);
} else if (Notification.permission === 'default') {
// Если прав нет, пытаемся их получить
Notification.requestPermission(function(permission) {
// Если права успешно получены, отправляем уведомление
if (permission === "granted") {
var notification = new Notification(title, options);
}
}
);
}
}

Подскажите как сделать чтобы на других компьютерах пр появлении нового смс происходило звуковое сообщение
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.