All files / node-coap index.js

93.75% Statements 30/32
75% Branches 12/16
100% Functions 1/1
93.75% Lines 30/32

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 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 52 53 54                  1x 1x 1x 1x 1x 1x 1x 1x   1x     303x 98x   303x   303x 28x 275x   275x   275x 4x   271x   303x     1x   1x 1x 1x   1x 1x 1x   1x 1x 1x  
'use strict'
/*
 * Copyright (c) 2013-2021 node-coap contributors.
 *
 * node-coap is licensed under an MIT +no-false-attribs license.
 * All rights not explicitly granted in the MIT license are reserved.
 * See the included LICENSE file for more details.
 */
 
var optionsConv     = require('./lib/option_converter')
  , Server          = require('./lib/server')
  , Agent           = require('./lib/agent')
  , parameters      = require('./lib/parameters')
  , net             = require('net')
  , URL             = require('url')
  , globalAgent     = new Agent({ type: 'udp4' })
  , globalAgentV6   = new Agent({ type: 'udp6' })
 
module.exports.request = function(url) {
  var agent, req, ipv6
 
  if (typeof url === 'string')
    url = URL.parse(url)
 
  ipv6 = net.isIPv6(url.hostname || url.host)
 
  if (url.agent)
    agent = url.agent
  else Iif (url.agent === false && !ipv6)
    agent = new Agent({ type: 'udp4' })
  else Iif (url.agent === false && ipv6)
    agent = new Agent({ type: 'udp6' })
  else if (ipv6)
    agent = exports.globalAgentIPv6
  else
    agent = exports.globalAgent
 
  return agent.request(url)
}
 
module.exports.createServer = Server
 
module.exports.Agent = Agent
module.exports.globalAgent = globalAgent
module.exports.globalAgentIPv6 = globalAgentV6
 
module.exports.registerOption = optionsConv.registerOption
module.exports.registerFormat = optionsConv.registerFormat
module.exports.ignoreOption = optionsConv.ignoreOption
 
module.exports.parameters = parameters
module.exports.updateTiming = parameters.refreshTiming
module.exports.defaultTiming = parameters.defaultTiming