mirror of
https://github.com/fluencelabs/js-libp2p-websockets
synced 2025-06-18 19:01:41 +00:00
22
src/ma-to-url.js
Normal file
22
src/ma-to-url.js
Normal file
@ -0,0 +1,22 @@
|
||||
'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
|
Reference in New Issue
Block a user