<NME> websocket.js
<BEF> const WebSocket = require('ws')
const WebSocketServer = WebSocket.Server
const rocky = require('..')

// Create a WebSocket proxy
const proxy = rocky({ ws: true })
// Or alternatively...
// proxy.protocol('ws')

// Enable replay after forward mode
proxy
  .replayAfterForward()

// Note the URI protocol: 'ws://'
proxy
  .forward('ws://localhost:8989')

// Use a WebSocket traffic middleware
proxy
  .useWs(function (req, socket, head, next) {
    // Do whatever you need here...
    next()
  })

// Finally, listen on network
proxy.listen(3000)

// Target server
const wss = new WebSocketServer({ port: 8989 })
wss.on('connection', function connection (ws) {
  ws.on('message', function incoming (message) {
    console.log('server received: %s', message)
  })
  ws.send('something')
})

// Test client
const ws = new WebSocket('ws://localhost:3000')
ws.on('open', function () {
  ws.send('foo')

  setTimeout(function () {
    ws.send('bar')
  }, 250)

  setTimeout(function () {
    ws.send('far')
  }, 500)
})
ws.on('message', function (data, flags) {
  console.log('client received: %s', data)
})

console.log('Web socket server listening on port: 3000')

<MSG> fix(example): websocke
<DFF> @@ -7,10 +7,6 @@ const proxy = rocky({ ws: true })
 // Or alternatively...
 // proxy.protocol('ws')
 
-// Enable replay after forward mode
-proxy
-  .replayAfterForward()
-
 // Note the URI protocol: 'ws://'
 proxy
   .forward('ws://localhost:8989')

{'commit': "diff --git a/examples/websocket.js b/examples/websocket.js\nindex 42fe722..6f09891 100644\n--- a/examples/websocket.js\n+++ b/examples/websocket.js\n@@ -7,10 +7,6 @@ const proxy = rocky({ ws: true })\n // Or alternatively...\n // proxy.protocol('ws')\n \n-// Enable replay after forward mode\n-proxy\n-  .replayAfterForward()\n-\n // Note the URI protocol: 'ws://'\n proxy\n   .forward('ws://localhost:8989')\n", 'commit_subject': 'fix(example): websocke', 'repo_name': 'h2non/rocky', 'committer': {'name': 'Tomás Aparicio', 'email': '2bc6038c3dfca09b2da23c8b6da8ba884dc2dcc2@aparicio.me', 'time_sec': '1443806472', 'tz_offset': '60', 'date': {'seconds': '1443806472'}}, 'commit_tree': '0a243c242f37a35b7f5e8a379f512d217b2c8bc2', 'commit_message': 'fix(example): websocke', 'language_name': 'JavaScript', 'license': 'mit', 'hunks': "@@ -7,10 +7,6 @@ const proxy = rocky({ ws: true })\n // Or alternatively...\n // proxy.protocol('ws')\n \n-// Enable replay after forward mode\n-proxy\n-  .replayAfterForward()\n-\n // Note the URI protocol: 'ws://'\n proxy\n   .forward('ws://localhost:8989')\n", 'addition_count': 0, 'deletion_count': 4, 'src_file': 'a/examples/websocket.js', 'tgt_file': 'b/examples/websocket.js', 'file_extension': '.js', 'before_file': "const WebSocket = require('ws')\nconst WebSocketServer = WebSocket.Server\nconst rocky = require('..')\n\n// Create a WebSocket proxy\nconst proxy = rocky({ ws: true })\n// Or alternatively...\n// proxy.protocol('ws')\n\n// Enable replay after forward mode\nproxy\n  .replayAfterForward()\n\n// Note the URI protocol: 'ws://'\nproxy\n  .forward('ws://localhost:8989')\n\n// Use a WebSocket traffic middleware\nproxy\n  .useWs(function (req, socket, head, next) {\n    // Do whatever you need here...\n    next()\n  })\n\n// Finally, listen on network\nproxy.listen(3000)\n\n// Target server\nconst wss = new WebSocketServer({ port: 8989 })\nwss.on('connection', function connection (ws) {\n  ws.on('message', function incoming (message) {\n    console.log('server received: %s', message)\n  })\n  ws.send('something')\n})\n\n// Test client\nconst ws = new WebSocket('ws://localhost:3000')\nws.on('open', function () {\n  ws.send('foo')\n\n  setTimeout(function () {\n    ws.send('bar')\n  }, 250)\n\n  setTimeout(function () {\n    ws.send('far')\n  }, 500)\n})\nws.on('message', function (data, flags) {\n  console.log('client received: %s', data)\n})\n\nconsole.log('Web socket server listening on port: 3000')\n", 'message': 'fix(example): websocke', 'author_name': 'Tomás Aparicio', 'lang': 'js'}