-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
107 lines (73 loc) · 1.68 KB
/
index.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
100
101
102
103
104
105
106
107
/* GoblinDB WebSockets interface ^^ */
var project = require('pillars'),
io = require('socket.io')(project.services.get('http').server);
var GDB = require("./node_modules/goblindb/goblin");
var http = require("http");
var goblinDB = GDB();
// Starting the project
project.services.get('http').configure({
port: process.env.PORT || 3000
}).start();
// Static Files, like index.html in this case
var staticRoute = new Route({
id: 'staticRoute',
path: '/*:path',
directory: {
path: './public',
listing: true
}
});
// Listen input channels
io.on('connection', function(socket){
socket.on('get', function(msg){
console.log('Get: ');
var get;
if(msg === '_all') {
get = goblinDB.get();
} else {
get = goblinDB.get(msg);
}
var res = {
_id: socket.client.conn.id,
db: get
}
console.log(res);
console.log('------------');
io.emit('get_resp', res);
});
socket.on('set', function(msg){
console.log('Set: ');
console.log(msg);
goblinDB.set(msg);
console.log('------------');
});
socket.on('update', function(msg){
console.log('Update: ');
console.log(msg);
goblinDB.update(msg)
console.log('------------');
});
socket.on('push', function(msg){
console.log('Push: ');
console.log(msg);
goblinDB.push(msg);
console.log('------------');
});
});
// Send output data
goblinDB.on('add', function(db) {
io.emit('add', db);
});
goblinDB.on('update', function(db) {
io.emit('update', db);
});
goblinDB.on('delete', function(db) {
io.emit('delete', db);
});
goblinDB.on('reconfigure', function(db) {
io.emit('reconfigure', db);
});
goblinDB.on('change', function(db) {
io.emit('change', db);
});
project.routes.add(staticRoute);