Help class to manipulate and parse a net address. The Address can be only the domain field, or a URL format with protocol and path part (http://)domain(:port/path)

Example

const address = new Address('nl-ams-42.live.ceeblue.tv:80');
console.log(address.domain) // 'nl-ams-42.live.ceeblue.tv'
console.log(address.port) // '80'
console.log(address) // 'nl-ams-42.live.ceeblue.tv:80'

Hierarchy

  • NetAddress

Constructors

  • Build a NetAddress object and parse address

    Parameters

    • address: string

      string address to parse, accept an url format with protocol and path (http://)domain(:port/path)

    • Optional defaultPort: number

      set a default port to use if there is no port in the string address parsed

    Returns NetAddress

Properties

_address: any
_domain: any
_host: any
_port?: any

Accessors

  • get domain(): string
  • The domain part from address (http://)domain(:port/path)

    Returns string

  • get host(): string
  • The host part from address (http://)domain:port/path)

    Returns string

  • get port(): undefined | number
  • The port part from address (http://)domain(:port/path), or defaultPort if passed in NetAddress constructor

    Returns undefined | number

Methods

  • Returns string

  • Returns string

    the string address as passed in the constructor

  • Static help function to build an end point from an address (proto://)domain(:port/path)

    Mainly it fix the protocol, in addition if:

    • the address passed is securized (TLS) and protocol is not => it tries to fix protocol to get its securize version
    • the address passed is non securized and protocol is (TLS) => it tries to fix protocol to get its unsecurized version

    Parameters

    • protocol: string

      protocol to set in the end point returned

    • address: string

      string address to fix with protocol as indicated

    Returns string

    the end point built

    Example

    console.log(NetAddress.fixProtocol('ws','http://domain/path')) // 'ws://domain/path'
    console.log(NetAddress.fixProtocol('ws','https://domain/path')) // 'wss://domain/path'
    console.log(NetAddress.fixProtocol('wss','http://domain/path')) // 'ws://domain/path'

Generated using TypeDoc