-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.coffee
58 lines (49 loc) · 1.51 KB
/
server.coffee
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
io = require('socket.io').listen(7000)
nano = require('nano')('http://127.0.0.1:5984')
db_name = "signifier"
db = nano.use db_name
io.sockets.on 'connection', (socket) ->
address = socket.handshake.address
console.log "here is the address!: "
console.log address
class Signifier
constructor: ->
@socket: socket
@scoutHood: (imAt) ->
console.log "querying db with [host,path] = "
console.log [imAt.host, imAt.path]
db.view('signifier', 'neighborhood', {key: [imAt.host, imAt.path]}, (err, signs) ->
console.log (signs)
Signifier.socket.emit("heresYourHood", signs))
@sendSigns: (signs) ->
Signifier.socket.emit("heresYourHood", signs)
@deleteAllDocs: ->
db.view('signifier', 'neighborhood', (err, body) ->
if err
console.log err
return
for a in body.rows
doc = a.value
db.destroy(doc._id, doc._rev, (err, body) ->
console.log err or body
)
console.log "database purged successfully!"
)
socket.emit('whereYat', {header: null})
console.log 'whereYat just sent'
socket.on 'chillinAt', (imAt) ->
Signifier.scoutHood(imAt)
socket.on "heresASign", (sign) ->
sign.creator = {
ip: socket.handshake.address.address
}
db.insert sign, (err, body, headers) ->
if err is false
console.log headers, body
socket.on "delete", (sig) ->
db.destroy sig.id, sig.rev, (err, body) ->
console.log err
console.log body
if !err then console.log "sig successfully deleted"
socket.on "deleteTheWholeShebang", ->
Signifier.deleteAllDocs()