mirror of
https://github.com/fluencelabs/js-libp2p-websockets
synced 2025-04-05 07:21:26 +00:00
23 lines
434 B
JavaScript
23 lines
434 B
JavaScript
|
'use strict'
|
||
|
|
||
|
const multiaddr = require('multiaddr')
|
||
|
|
||
|
function maToUrl (ma) {
|
||
|
const maStrSplit = ma.toString().split('/')
|
||
|
const proto = ma.protos()[2].name
|
||
|
|
||
|
if (!(proto === 'ws' || proto === 'wss')) {
|
||
|
throw new Error('invalid multiaddr' + ma.toString())
|
||
|
}
|
||
|
|
||
|
let url = ma.protos()[2].name + '://' + maStrSplit[2]
|
||
|
|
||
|
if (!multiaddr.isName(ma)) {
|
||
|
url += ':' + maStrSplit[4]
|
||
|
}
|
||
|
|
||
|
return url
|
||
|
}
|
||
|
|
||
|
module.exports = maToUrl
|