Skip to content

Commit

Permalink
Cleaned up websocket example code
Browse files Browse the repository at this point in the history
  • Loading branch information
josephg committed Aug 1, 2014
1 parent 663ac30 commit 9792343
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions examples/ws.coffee
Expand Up @@ -6,9 +6,6 @@ livedb = require 'livedb'
livedbMongo = require 'livedb-mongo'
http = require 'http'

try
require 'heapdump'

sharejs = require '../lib'

app = connect(
Expand All @@ -20,27 +17,12 @@ app = connect(

# app.use '/doc', share.rest()

#backend = livedb.client livedb.memory()
backend = livedb.client livedbMongo('localhost:27017/test?auto_reconnect', safe:false)

backend.addProjection '_users', 'users', 'json0', {x:true}
backend = livedb.client livedb.memory()
#backend = livedb.client livedbMongo('localhost:27017/test?auto_reconnect', safe:false)

share = sharejs.server.createClient {backend}


###
share.use 'validate', (req, callback) ->
err = 'noooo' if req.snapshot.data?.match /x/
callback err
share.use 'connect', (req, callback) ->
console.log req.agent
callback()
###

numClients = 0


server = http.createServer app

WebSocketServer = require('ws').Server
Expand Down Expand Up @@ -68,8 +50,7 @@ wss.on 'connection', (client) ->
stream.push null
stream.emit 'close'

numClients--
console.log 'client went away', numClients
console.log 'client went away'
client.close reason

stream.on 'end', ->
Expand Down

0 comments on commit 9792343

Please sign in to comment.