# All files / client swarm.js

50% Statements 7/14
100% Branches 0/0
0% Functions 0/5
50% Lines 7/14

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    521x
    1x
    1x
    1x
    1x
    1x

    1x

     import { caller } from 'postmsg-rpc'
    import callbackify from 'callbackify'
    import { pre, post } from 'prepost'
    import { peerInfoFromJson } from '../serialization/peer'
    import { preMultiaddrToJson, multiaddrFromJson } from '../serialization/multiaddr'
    import { preBufferToJson } from '../serialization/buffer'

    export default function (opts) {
      return {
        peers: callbackify.variadic(
          post(
            caller('ipfs.swarm.peers', opts),
            (res) => Promise.all(
              res.map((item) => (
                peerInfoFromJson(item.peer)
                  .then((peerInfo) => {
                    item.addr = multiaddrFromJson(item.addr)
                    item.peer = peerInfo
                    return item
                  })
              ))
            )
          )
        ),
        addrs: callbackify(
          post(
            caller('ipfs.swarm.addrs', opts),
            (res) => Promise.all(res.map(peerInfoFromJson))
          )
        ),
        localAddrs: callbackify(
          post(
            caller('ipfs.swarm.localAddrs', opts),
            (res) => res.map(multiaddrFromJson)
          )),
        connect: callbackify.variadic(
          pre(
            preBufferToJson(0),
            preMultiaddrToJson(0),
            caller('ipfs.swarm.connect', opts)
          )
        ),
        disconnect: callbackify.variadic(
          pre(
            preBufferToJson(0),
            preMultiaddrToJson(0),
            caller('ipfs.swarm.disconnect', opts)
          )
        )
      }
    }