Class CastLink

java.lang.Object
com.iizigo.panel.CastLink

public final class CastLink extends Object
The link of "Show QR code for iiziRun Developer" in the Panel Editor's Cast to Device drop-down, and the addresses of this computer it can carry. Nothing here has a user interface, so that the address filter and the link are tested without a window (CastQRWindow shows them).

The link opens Cast to Device of this iiziGo in iiziRun Developer: iizirundev://ca?addr=<address>&port=<port>, the parameter style of iiziRun's run and define links, the values percent-encoded as JavaScript's encodeURIComponent encodes them, HTTP only (no ssl), no pairing token (rulings QL-D-1, QL-D-8, QL-D-10 of 2026-10-14). The port is the one the Designer's web server really holds, read from the running server.

The address filter (QL-D-2, QL-D-11). Every address of every interface of this computer is offered, IPv4 and IPv6, except:

  • an interface that is down, a loopback interface, a point-to-point interface (a VPN or dial-up link), an interface without a hardware address (tunnels and pseudo interfaces), and an interface whose hardware address belongs to a virtual machine vendor (Hyper-V, VMware, VirtualBox, Parallels, Xen, QEMU, Docker: OSHI's isKnownVmMacAddr, the library HardwareInfo reads its network cards with) - a virtual switch's address is reachable from this computer only - unless that interface carries the default route: then this computer is itself a virtual machine, or its network goes through a virtual switch, and the phone may reach it;
  • a loopback, wildcard or multicast address, and a link-local address: IPv4 169.254.0.0/16 and IPv6 fe80::/10. A link-local IPv6 address needs its zone, which names an interface of this computer and which a WebView cannot use (CL-D-5 of CC-FIX-IIZIRUN-CAST-LINK, measured);
  • when the web server is bound to one address (Preferences > IIZI > Web server, or the -D override), every address but that one.
IPv4 addresses come first, then IPv6, each in the order the system lists the interfaces.
Author:
Christopher Mindus
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    An address offered in the chooser.
    static final class 
    A network interface as the address filter reads it: what the system says about it, and its addresses.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The start of the link, up to and including the '?' of its query.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    buildLink(String host, int port)
    Builds the link: iizirundev://ca?addr=<host>&port=<port>, the host percent-encoded.
    createQRImage(String link, int size)
    Creates the QR code of a link (com.iizix.barcode), black on white.
    static String
    Percent-encodes a value as JavaScript's encodeURIComponent does, which iiziRun's decodeURIComponent reverses: the letters, digits and -_.!~*'() as they are, every other character as the %XX of its UTF-8 bytes (upper-case hexadecimal).
    Enumerates the interfaces of this computer: the flags and addresses from NetworkInterface, the virtual machine test, the kind and the name a user knows from OSHI (the library HardwareInfo uses), and the interface of the default route (getDefaultRouteSources()).
    Gets the addresses this computer sends from on its default routes, IPv4 and IPv6: the local address of a UDP socket connected to a documentation address (192.0.2.1, 2001:db8::1).
    static int
    Gets the HTTP port the Designer's web server really holds, read from the running server.
    static String
    Gets the text of an address as the link carries it: an IPv4 address in dotted form; an IPv6 address in its short form (RFC 5952: lower case, no leading zeros, the longest run of two or more zero groups as ::), without brackets and without a zone.
    static boolean
    Tells whether an address may be offered at all, whatever its interface: not a loopback, wildcard, multicast or link-local address (IPv4 169.254.0.0/16, IPv6 fe80::/10).
    Gets the addresses to offer, by the filter of this class: IPv4 first, then IPv6, each in the order of the interfaces.
    Gets the addresses of this computer to offer: enumerate() through offer(List,Collection), with the bind address of the web server in effect (the preference, or the -D override).
    Gets the addresses the web server is bound to.
  • Field Details

  • Method Details

    • isOfferedAddress

      public static boolean isOfferedAddress(InetAddress address)
      Tells whether an address may be offered at all, whatever its interface: not a loopback, wildcard, multicast or link-local address (IPv4 169.254.0.0/16, IPv6 fe80::/10).
      Parameters:
      address - The address.
      Returns:
      true when a phone on the same network may reach it.
    • offer

      public static List<CastLink.Address> offer(List<CastLink.Interface> interfaces, Collection<InetAddress> bound)
      Gets the addresses to offer, by the filter of this class: IPv4 first, then IPv6, each in the order of the interfaces.
      Parameters:
      interfaces - The interfaces.
      bound - The addresses the web server is bound to, null or empty when it is bound to all of them.
      Returns:
      The addresses, a new list (empty when nothing can be offered).
    • resolveBind

      public static List<InetAddress> resolveBind(String bind)
      Gets the addresses the web server is bound to.
      Parameters:
      bind - The bind address of the web server: null, empty, 0.0.0.0 or :: for all.
      Returns:
      The addresses, empty for all; an address that cannot be resolved gives a list holding nothing that matches, so that nothing is offered.
    • offerOfThisComputer

      public static List<CastLink.Address> offerOfThisComputer()
      Gets the addresses of this computer to offer: enumerate() through offer(List,Collection), with the bind address of the web server in effect (the preference, or the -D override).
      Returns:
      The addresses, a new list (empty when nothing can be offered).
    • enumerate

      public static List<CastLink.Interface> enumerate()
      Enumerates the interfaces of this computer: the flags and addresses from NetworkInterface, the virtual machine test, the kind and the name a user knows from OSHI (the library HardwareInfo uses), and the interface of the default route (getDefaultRouteSources()). When OSHI cannot be used, an interface has no kind and is not taken for a virtual machine's.
      Returns:
      The interfaces, a new list.
    • getDefaultRouteSources

      public static List<InetAddress> getDefaultRouteSources()
      Gets the addresses this computer sends from on its default routes, IPv4 and IPv6: the local address of a UDP socket connected to a documentation address (192.0.2.1, 2001:db8::1). Connecting a UDP socket only chooses the route; nothing is sent.
      Returns:
      The addresses, none when there is no default route.
    • getServerPort

      public static int getServerPort()
      Gets the HTTP port the Designer's web server really holds, read from the running server.
      Returns:
      The port, 0 when the web server is not running.
    • hostOf

      public static String hostOf(InetAddress address)
      Gets the text of an address as the link carries it: an IPv4 address in dotted form; an IPv6 address in its short form (RFC 5952: lower case, no leading zeros, the longest run of two or more zero groups as ::), without brackets and without a zone.
      Parameters:
      address - The address.
      Returns:
      The text.
    • buildLink

      public static String buildLink(String host, int port)
      Builds the link: iizirundev://ca?addr=<host>&port=<port>, the host percent-encoded.
      Parameters:
      host - The address as hostOf(InetAddress) gives it, or a host name.
      port - The HTTP port.
      Returns:
      The link.
    • encodeComponent

      public static String encodeComponent(String value)
      Percent-encodes a value as JavaScript's encodeURIComponent does, which iiziRun's decodeURIComponent reverses: the letters, digits and -_.!~*'() as they are, every other character as the %XX of its UTF-8 bytes (upper-case hexadecimal).
      Parameters:
      value - The value.
      Returns:
      The encoded value.
    • createQRImage

      public static BufferedImage createQRImage(String link, int size) throws BarcodeException
      Creates the QR code of a link (com.iizix.barcode), black on white.
      Parameters:
      link - The link.
      size - The width and height in pixels (the code may be made larger to fit).
      Returns:
      The image.
      Throws:
      BarcodeException - If the code cannot be made.