-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move client conn handler to separate file
Users of this package may wish to build their own clients that connect to a tcp-over-websockets server. This change makes the TCP tunnelling handler available to package users, while still keeping the module.exports conventions used here. - Create `tunnel`, a new module - Move handler that tunnels an incoming TCP connection from `client` to `tunnel`, naming the function `tunnelTo` - Add `tunnel.js`to manifest of files to be exported by package.json
- Loading branch information
Showing
3 changed files
with
20 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 10,7 @@ | |
"files": [ | ||
"client.js", | ||
"server.js", | ||
"tunnel.js", | ||
"cli" | ||
], | ||
"keywords": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,17 @@ | ||
'use strict' | ||
|
||
const ws = require('websocket-stream') | ||
const pipe = require('pump') | ||
const debug = require('debug')('tcp-over-websockets:client') | ||
|
||
const tunnelTo = (tunnel, target) => (local) => { | ||
const remote = ws(tunnel (tunnel.slice(-1) === '/' ? '' : '/') target) | ||
|
||
const onError = (err) => { | ||
if (err) debug(err) | ||
} | ||
pipe(remote, local, onError) | ||
pipe(local, remote, onError) | ||
} | ||
|
||
module.exports = {tunnelTo} |