-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket.js
60 lines (49 loc) · 1.94 KB
/
socket.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var socket = io();
let form = document.getElementById('form');
let input = document.getElementById('input');
let messages = document.getElementById('mensajes');
let body = document.getElementById('body');
let introName = document.getElementsByClassName('Box_suscriptio');
let name = document.getElementsByClassName('.name');
let yourName =document.getElementById('yourName');
body.addEventListener('onload', function(){
if (Notification.permission !== "granted")
Notification.requestPermission();
});
function getNotification(msg) {
if (Notification.permission !== "granted")
Notification.requestPermission();
else{
const options = {
body: msg,
dir: "ltr"
}
const notification = new Notification("notification",options);
notification.onclick = function() {
window.open("https://www.google.es/");
};
}
};
form.addEventListener('submit', function(e){
e.preventDefault();
socket.emit('chat message', input.value);
input.value = '';
});
socket.on("profil", (name, count) => {
console.log(`${name}, ${count}`)
for(let i in profiles){
if (profiles[i] === null ){
profiles[count] = name;
place = count;
console.log(profiles[place]);
};
break;
};
});
socket.on('chat message', function(msg) {
let item = document.createElement('li');
item.textContent = `${hal}: ${msg}`;
messages.appendChild(item);
window.scrollTo(0,document.body.scrollHeight);
getNotification(msg);
});