This repository was archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,13 +1,61 @@ | ||
js-libp2p-websockets | ||
==================== | ||
# js-libp2p-websockets | ||
|
||
[](http://ipn.io) | ||
[](http://ipfs.io/) | ||
[](http://webchat.freenode.net/?channels=%23ipfs) | ||
 | ||
[](https://david-dm.org/libp2p/js-libp2p-websockets) | ||
[](https://github.com/feross/standard) | ||
[](https://coveralls.io/github/libp2p/js-libp2p-websockets?branch=master) | ||
[](https://travis-ci.org/libp2p/js-libp2p-websockets) | ||
[](https://circleci.com/gh/libp2p/js-libp2p-websockets) | ||
[](https://david-dm.org/libp2p/js-libp2p-websockets) [](https://github.com/feross/standard) | ||
|
||
 | ||
 | ||
|
||
> JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport interface | ||
|
||
## Description | ||
|
||
`libp2p-websockets` is the WebSockets implementation compatible with libp2p. | ||
|
||
**Note:** This module uses [pull-streams](https://pull-stream.github.io) for all stream based interfaces. | ||
|
||
## Example | ||
|
||
``` | ||
TODO | ||
``` | ||
|
||
## Installation | ||
|
||
### npm | ||
|
||
```sh | ||
> npm i libp2p-websockets | ||
``` | ||
|
||
## This module uses `pull-streams` | ||
|
||
We expose a streaming interface based on `pull-streams`, rather then on the Node.js core streams implementation (aka Node.js streams). `pull-streams` offers us a better mechanism for error handling and flow control guarantees. If you would like to know more about what took us to make this migration, see the discussion at this [issue](https://github.com/ipfs/js-ipfs/issues/362). | ||
|
||
You can learn more about pull-streams at: | ||
|
||
- [The history of Node.js streams, nodebp April 2014](https://www.youtube.com/watch?v=g5ewQEuXjsQ) | ||
- [The history of streams, 2016](http://dominictarr.com/post/145135293917/history-of-streams) | ||
- [pull-streams, the simple streaming primitive](http://dominictarr.com/post/149248845122/pull-streams-pull-streams-are-a-very-simple) | ||
- [pull-streams documentation](https://pull-stream.github.io/) | ||
|
||
### Converting `pull-streams` to Node.js Streams | ||
|
||
If you are a Node.js streams user, you can convert a pull-stream to Node.js Stream using the module `pull-stream-to-stream`, giving you an instance of a Node.js stream that is linked to the pull-stream. Example: | ||
|
||
``` | ||
const pullToStream = require('pull-stream-to-stream') | ||
|
||
const nodeStreamInstance = pullToStream(pullStreamInstance) | ||
// nodeStreamInstance is an instance of a Node.js Stream | ||
``` | ||
|
||
To learn more about his utility, visit https://pull-stream.github.io/#pull-stream-to-stream | ||
|
||
## API | ||
|
||
[](https://github.com/diasdavid/interface-transport) |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -22,38 +22,38 @@ | |
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/diasdavid/js-libp2p-websockets.git" | ||
"url": "git+https://github.com/libp2p/js-libp2p-websockets.git" | ||
}, | ||
"keywords": [ | ||
"IPFS" | ||
], | ||
"author": "David Dias <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/diasdavid/js-libp2p-websockets/issues" | ||
"url": "https://github.com/libp2p/js-libp2p-websockets/issues" | ||
}, | ||
"homepage": "https://github.com/diasdavid/js-libp2p-websockets#readme", | ||
"homepage": "https://github.com/libp2p/js-libp2p-websockets#readme", | ||
"dependencies": { | ||
"detect-node": "^2.0.3", | ||
"interface-connection": "^0.1.8", | ||
"interface-connection": "^0.2.1", | ||
"lodash.contains": "^2.4.3", | ||
"mafmt": "^2.1.0", | ||
"run-parallel": "^1.1.6", | ||
"simple-websocket": "^4.1.0", | ||
"simple-websocket-server": "^0.1.4" | ||
"mafmt": "^2.1.1", | ||
"pull-ws": "^3.2.3" | ||
}, | ||
"devDependencies": { | ||
"aegir": "^6.0.0", | ||
"multiaddr": "^2.0.2", | ||
"aegir": "^6.0.1", | ||
"chai": "^3.5.0", | ||
"gulp": "^3.9.1", | ||
"interface-transport": "^0.2.0", | ||
"pre-commit": "^1.1.2" | ||
"interface-transport": "^0.3.3", | ||
"multiaddr": "^2.0.2", | ||
"pre-commit": "^1.1.3", | ||
"pull-goodbye": "0.0.1", | ||
"pull-stream": "^3.4.3" | ||
}, | ||
"contributors": [ | ||
"David Dias <[email protected]>", | ||
"Francisco Baio Dias <[email protected]>", | ||
"Friedel Ziegelmayer <[email protected]>", | ||
"greenkeeperio-bot <[email protected]>" | ||
] | ||
} | ||
} |
This file contains hidden or 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 hidden or 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,46 @@ | ||
'use strict' | ||
|
||
const isNode = require('detect-node') | ||
const Connection = require('interface-connection').Connection | ||
const contains = require('lodash.contains') | ||
|
||
// const IPFS_CODE = 421 | ||
|
||
let createServer | ||
|
||
if (isNode) { | ||
createServer = require('pull-ws/server') | ||
} else { | ||
createServer = () => {} | ||
} | ||
|
||
module.exports = (options, handler) => { | ||
const listener = createServer((socket) => { | ||
socket.getObservedAddrs = (cb) => { | ||
// TODO research if we can reuse the address in anyway | ||
return cb(null, []) | ||
} | ||
|
||
handler(new Connection(socket)) | ||
}) | ||
|
||
let listeningMultiaddr | ||
|
||
listener._listen = listener.listen | ||
listener.listen = (ma, cb) => { | ||
cb = cb || (() => {}) | ||
listeningMultiaddr = ma | ||
|
||
if (contains(ma.protoNames(), 'ipfs')) { | ||
ma = ma.decapsulate('ipfs') | ||
} | ||
|
||
listener._listen(ma.toOptions(), cb) | ||
} | ||
|
||
listener.getAddrs = (cb) => { | ||
cb(null, [listeningMultiaddr]) | ||
} | ||
|
||
return listener | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is missing to bubble up the events from the listener:
See interface-transport.
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as https://github.com/libp2p/js-libp2p-tcp/pull/20/files#r75307992