-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket-angular-server.js
99 lines (92 loc) · 2.58 KB
/
socket-angular-server.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var express = require('express');
var app = express().use(express.static(__dirname))
, server = require('http').createServer(app)
, io = require('socket.io').listen(server);
//app.use(express.static(__dirname));
server.listen(3000);
io.sockets.on('connection', function (socket) {
var user = '';
socket.emit('login');
socket.on('new user', function (name) {
user = name;
users.push(user);
console.log(users);
});
socket.emit('initialize contacts', contacts);
socket.on('modify contact', function (contact) {
contacts.forEach(function (h,i) {
if (h.id == contact.id) {
contacts[i] = contact;
}
});
console.log(contacts);
socket.broadcast.emit('update contact', contact);
});
socket.on('select contact', function (contactId) {
selectedContactIds[user] = contactId;
socket.broadcast.emit('selected contact', {user: user, contactId: contactId});
});
});
var users = [];
var selectedContactIds = {};
var contacts = [{
id: 1,
first_name: "Sylvain",
last_name: "Kieffer",
email: "[email protected]"
}, {
id: 2,
first_name: "Laurent",
last_name: "Mernier",
email: "[email protected]"
}, {
id: 3,
first_name: "Michel",
last_name: "Renauld",
email: "[email protected]"
}, {
id: 4,
first_name: "Sylvain",
last_name: "Kieffer",
email: "[email protected]"
}, {
id: 5,
first_name: "Laurent",
last_name: "Mernier",
email: "[email protected]"
}, {
id: 6,
first_name: "Michel",
last_name: "Renauld",
email: "[email protected]"
}, {
id: 7,
first_name: "Sylvain",
last_name: "Kieffer",
email: "[email protected]"
}, {
id: 8,
first_name: "Laurent",
last_name: "Mernier",
email: "[email protected]"
}, {
id: 9,
first_name: "Michel",
last_name: "Renauld",
email: "[email protected]"
}, {
id: 10,
first_name: "Sylvain",
last_name: "Kieffer",
email: "[email protected]"
}, {
id: 11,
first_name: "Laurent",
last_name: "Mernier",
email: "[email protected]"
}, {
id: 12,
first_name: "Michel",
last_name: "Renauld",
email: "[email protected]"
}];