All files / server ping.js

53.85% Statements 7/13
100% Branches 0/0
0% Functions 0/4
53.85% Lines 7/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 271x 1x 1x 1x 1x 1x     39x                                    
import { expose } from 'postmsg-rpc'
import { pre, post } from 'prepost'
import pull from 'pull-stream'
import PMS from 'pull-postmsg-stream'
import shortid from 'shortid'
import { functionToJson } from '../serialization/function'
 
export default function (getIpfs, opts) {
  return {
    ping: expose('ipfs.ping', pre(
      opts.pre('ping'),
      (...args) => getIpfs().ping(...args)
    ), opts),
    pingPullStream: expose('ipfs.pingPullStream', pre(
      opts.pre('pingPullStream'),
      post(
        (...args) => getIpfs().pingPullStream(...args),
        (res) => new Promise((resolve) => {
          const readFnName = shortid()
          pull(res, PMS.sink(readFnName, opts))
          resolve(functionToJson(readFnName))
        })
      )
    ), opts)
  }
}