Skip to content

Commit

Permalink
add better examples with local echo server
Browse files Browse the repository at this point in the history
  • Loading branch information
skepticfx committed Sep 5, 2017
1 parent 71d2d5c commit 5b1dd51
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion examples/server.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const WebSocket = require('ws')

console.log('open the file ' + process.cwd() + '/examples/example.html in a browser')
const wss = new WebSocket.Server({ port: 8080 })

wss.on('connection', function connection (ws) {
console.log('connection')
ws.on('message', function incoming (message) {
console.log('received: %s', message)
ws.send(message)
console.log('echoed back...')
})

ws.send('something')
})
4 changes: 2 additions & 2 deletions examples/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Define the 'before' and 'after' hooks as you wish.

wsHook.before = function (data, url) {
data = 'modified data'
data = 'modified data while sending'
return data
}

wsHook.after = function (messageEvent, url) {
messageEvent.data = '-- data modified -- ' + messageEvent.data + ' --'
messageEvent.data = messageEvent.data + ' and receiving'
return messageEvent
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"standard": "^10.0.3"
},
"scripts": {
"test": "node examples/server.js"
"example": "node examples/server.js"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 5b1dd51

Please sign in to comment.