This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c3a707
commit 3f58dca
Showing
7 changed files
with
188 additions
and
199 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
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 |
---|---|---|
@@ -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 | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const tests = require('interface-transport') | ||
const multiaddr = require('multiaddr') | ||
const Ws = require('../src') | ||
|
||
describe('compliance', () => { | ||
tests({ | ||
setup (cb) { | ||
let ws = new Ws() | ||
const addrs = [ | ||
multiaddr('/ip4/127.0.0.1/tcp/9091/ws'), | ||
multiaddr('/ip4/127.0.0.1/tcp/9092/ws'), | ||
multiaddr('/ip4/127.0.0.1/tcp/9093/ws') | ||
] | ||
cb(null, ws, addrs) | ||
}, | ||
teardown (cb) { | ||
cb() | ||
} | ||
}) | ||
}) |
Oops, something went wrong.