diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 4970021e3..97a7e30cc 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -10,13 +10,14 @@ This is a bug and feature tracker, please only use it to report bugs or request features within OctoPrint (not OctoPi, not any OctoPrint plugins and not unofficial OctoPrint versions). -Do not seek support here ("I need help with ..."), that belongs on -the mailing list or the G+ community (both linked in the "guidelines -for contributing" linked above, read it!), NOT here. +Do not seek support here ("I need help with ...", "I have a +question ..."), that belongs on the mailing list or the G+ community +(both linked in the "guidelines for contributing" linked above, read +them!), NOT here. -Mark requests with a "[Request]" prefix in the title please. Fully fill -out the bug reporting template for bug reports (if you don't know where -to find some information - it's all described in the Contribution +Mark requests with a "[Request]" prefix in the title please. For bug +reports fully fill out the bug reporting template (if you don't know +where to find some information - it's all described in the Contribution Guidelines linked up there in the big yellow box). When reporting a bug do NOT delete ANY lines from the template but @@ -91,7 +92,7 @@ reporting communication issues. Never truncate. serial.log is usually not written due to performance reasons and must be enabled explicitly. Provide at the very least the FULL contents of your terminal tab at the time of the bug occurrence, even if you do not have -a serial.log.] +a serial.log (which the Contribution Guidelines tell you where to find).] #### Link to contents of Javascript console in the browser diff --git a/.versioneer-lookup b/.versioneer-lookup index 342b9dec1..ed09d1585 100644 --- a/.versioneer-lookup +++ b/.versioneer-lookup @@ -16,11 +16,14 @@ prerelease HEAD \(detached.* -# maintenance is currently the branch for preparation of maintenance release 1.3.3 +# maintenance is currently the branch for preparation of maintenance release 1.3.5 # so are any fix/... and improve/... branches -maintenance 1.3.3 0a69dbeddb301d5a32827a3f0d561f875df24234 pep440-dev -fix/.* 1.3.3 0a69dbeddb301d5a32827a3f0d561f875df24234 pep440-dev -improve/.* 1.3.3 0a69dbeddb301d5a32827a3f0d561f875df24234 pep440-dev +maintenance 1.3.5 fe481e12b3c50a2def3b41515200e13a8c6a5c72 pep440-dev +fix/.* 1.3.5 fe481e12b3c50a2def3b41515200e13a8c6a5c72 pep440-dev +improve/.* 1.3.5 fe481e12b3c50a2def3b41515200e13a8c6a5c72 pep440-dev + +# staging/maintenance is currently the branch for preparation of 1.3.5rc1 +staging/maintenance 1.3.5rc1 fe481e12b3c50a2def3b41515200e13a8c6a5c72 pep440-dev # every other branch is a development branch and thus gets resolved to 1.4.0-dev for now .* 1.4.0 7f5d03d0549bcbd26f40e7e4a3297ea5204fb1cc pep440-dev diff --git a/AUTHORS.md b/AUTHORS.md index 87c28789c..21add4213 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -81,6 +81,7 @@ date of first contribution): * [Andreas Werner](https://github.com/gallore) * [Shawn Bruce](https://github.com/kantlivelong) * [Claudiu Ceia] (https://github.com/ClaudiuCeia) + * [Goswin von Brederlow](https://github.com/mrvn) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by [Daid Braam](https://github.com/daid). Parts of its communication layer and diff --git a/CHANGELOG.md b/CHANGELOG.md index 07abd8dba..3a36cf58f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,124 @@ # OctoPrint Changelog +## 1.3.4 (2017-06-01) + +### Note for owners of Malyan M200/Monoprice Select Mini + +OctoPrint's firmware autodetection is now able to detect this printer. Currently when this printer is detected, the following firmware specific features will be enabled automatically: + + * Always assume SD card is present (`feature.sdAlwaysAvailable`) + * Send a checksum with the command: Always (`feature.alwaysSendChecksum`) + +Since the firmware is a very special kind of beast and its sources are so far unavailable, only tests with a real printer will show if those are sufficient settings for communication with this printer to fully function correctly. Thus, if you run into any issues with enabled firmware autodetection on this printer model, please add a comment in [#1762](https://github.com/foosel/OctoPrint/issues/1762) and explain what kind of communication problem you are seeing. Also make sure to include a [`serial.log`](https://github.com/foosel/OctoPrint/blob/master/CONTRIBUTING.md#where-can-i-find-those-log-files-you-keep-talking-about)! + +### Bug fixes + + * [#1942](https://github.com/foosel/OctoPrint/issues/1942) - Fixed crash on startup in case of an invalid default printer profile combined with "auto-connect on startup" being selected and the printer available to connect to. + +### More information + + * [Commits](https://github.com/foosel/OctoPrint/compare/1.3.1...1.3.2) + * Release Candidates: + * None since this constitutes a hotfix release to fix an apparently very rare bug introduced with 1.3.3 that seems to be affecting a small number of users. + +## 1.3.3 (2017-05-31) + +### Note for owners of Malyan M200/Monoprice Select Mini + +OctoPrint's firmware autodetection is now able to detect this printer. Currently when this printer is detected, the following firmware specific features will be enabled automatically: + + * Always assume SD card is present (`feature.sdAlwaysAvailable`) + * Send a checksum with the command: Always (`feature.alwaysSendChecksum`) + +Since the firmware is a very special kind of beast and its sources are so far unavailable, only tests with a real printer will show if those are sufficient settings for communication with this printer to fully function correctly. Thus, if you run into any issues with enabled firmware autodetection on this printer model, please add a comment in [#1762](https://github.com/foosel/OctoPrint/issues/1762) and explain what kind of communication problem you are seeing. Also make sure to include a [`serial.log`](https://github.com/foosel/OctoPrint/blob/master/CONTRIBUTING.md#where-can-i-find-those-log-files-you-keep-talking-about)! + +### Improvements + + * [#478](https://github.com/foosel/OctoPrint/issues/478) - Made webcam stream container fixed height (with selectable aspect ratio) to prevent jumps of the controls beneath it on load. + * [#748](https://github.com/foosel/OctoPrint/issues/748) - Added delete confirmation and bulk delete for timelapses. See also the discussion in brainstorming ticket [#1807](https://github.com/foosel/OctoPrint/issues/1807). + * [#1092](https://github.com/foosel/OctoPrint/issues/1092) - Added new events to the file manager: `FileAdded`, `FileRemoved`, `FolderAdded`, `FolderRemoved`. Contrary to the `Upload` event, `FileAdded` will always fire when a file was added to storage through the file manager, not only when added through the web interface. Extended documentation accordingly. + * [#1521](https://github.com/foosel/OctoPrint/issues/1521) - Software update plugin: Display timestamp of last version cache refresh in "Advanced options" area. + * [#1734](https://github.com/foosel/OctoPrint/issues/1734) - Treat default/initial printer profile like all other printer profiles, persisting it to disk instead of `config.yaml` and allowing deletion. OctoPrint will migrate the existing default profile to the new location on first start. + * [#1734](https://github.com/foosel/OctoPrint/issues/1734) - Better communication of what actions are available for printer profiles. + * [#1739](https://github.com/foosel/OctoPrint/issues/1739) - Software update plugin: Added option to hide update notification from users without admin rights, added "ignore" button and note to get in touch with an admit to update notifications for non admin users. + * [#1762](https://github.com/foosel/OctoPrint/issues/1762) - Added Malyan M200/Monoprice Select Mini to firmware autodetection. + * [#1811](https://github.com/foosel/OctoPrint/issues/1811) - Slight rewording and rearrangement in timelapse configuration, better feedback if settings have been saved. + * [#1818](https://github.com/foosel/OctoPrint/issues/1818) - Support both Marlin/Repetier and Smoothieware interpretations of `G90` after an `M83` in GCODE viewer and analysis. Select "G90/G91 overrides relative extruder mode" in Settings > Features for the Smoothieware interpretation. + * [#1858](https://github.com/foosel/OctoPrint/issues/1858) - Announcement plugin: Images from registered feeds now are lazy loading. + * [#1862](https://github.com/foosel/OctoPrint/issues/1862) - Automatically re-enable fancy terminal functionality when performance recovers. + * [#1875](https://github.com/foosel/OctoPrint/issues/1875) - Marked the command input field in the Terminal tab as not supporting autocomplete to work around an issue in Safari. Note that this is probably only a temporary workaround due to browser vendors [working on deprecating `autocomplete="off"` support](https://bugs.chromium.org/p/chromium/issues/detail?id=468153#c164) and a different solution will need to be found in the future. + * Added link to [`SerialException` FAQ entry](https://github.com/foosel/OctoPrint/wiki/FAQ#octoprint-randomly-loses-connection-to-the-printer-with-a-serialexception) to terminal output when such an error is encountered, as suggested in [#1876](https://github.com/foosel/OctoPrint/issues/1876). + * Force refresh of settings on login/logout. + * Made system wide API key management mirror user API key management. + * Make sure to always migrate and merge saved printer profiles with default profile to ensure all parameters are set. Should avoid issues with plugins trying to save outdated/incomplete profiles. + * Added note on lack of language pack repository & to use the wiki for now. + * Earlier validation of file to select for printing. + * Limit verbosity of failed system event handlers. + * Made bundled python client `octoprint_client` support multiple client instances. + * Disable "Reload" button in the "Please reload" overlay once clicked, added spinner. + * Updated pnotify to 2.1.0. + * Get rid of ridiculous float precision in temperature commands. + * Detect invalid settings data to persist (not a dict), send 400 status in such a case. + * More logging for preemptive caching, to help narrow down any performance issues that might be related to this. + * Further decoupling of some startup tasks from initial server startup thread for better parallelization and improved startup times. + * Announcement plugin: Added combined OctoBlog feed, replacing news and spotlight feed, added corresponding config migration. + * Announcement plugin: Subscribe to all registered feeds by default to ensure better communication flow (all subscriptions but the "Important" channel can however be unsubscribed easily, added corresponding note to the notifications and also a configuration button to the announcement reader). + * Announcement plugin: Auto-hide announcements on logout. + * Announcement plugin: Order channels server-side based on new order config setting. + * Plugin manager: Show warning when disabling a bundled plugin that is not recommended to be disabled, including a reason why disabling it is not recommended. Applies to the bundled announcement, core wizard, discovery and software update plugins. + * Plugin manager: Support for plugin notices for specific plugins from the plugin repository, e.g. to inform users of specific plugins about known issues with the plugin or instruct to update when the software update mechanism of the current plugin version turns out to be misconfigured. Supports matching installed plugin versions and OctoPrint versions to target only affected users. + * Plugin manager: Better visualization of plugins disabled on the repository, no longer shown as "incompatible" but "disabled", with link to the plugin repository page that contains more information. + * Plugin manager: Detect necessity to reinstall a plugin provided through archive URL or upload and immediately do that instead of reporting an "unknown error" without further information. + * Plugin manager: Added `freebsd` for compatibility check. + * Plugin manager: More general flexibility for OS compatibility check: + * Support for arbitrary values to match against + * Allow 1:1 check again `sys.platform` values (with `startswith`). + * Support black listing (`!windows`) additionally to white listing. A detected OS must match all provided white list elements (if the white list is empty that is considered to be always the case) and none of the black list elements (if the black list is empty that is also considered to be always the case). + * Software update plugin: New check type `bitbucket_commit` (see also [#1898](https://github.com/foosel/OctoPrint/pull/1898)) + * Docs: Now referring to dedicated Jinja 2.8 documentation as hosted at [jinja.octoprint.org](http://jinja.octoprint.org) for all template needs, to avoid confusion when consulting current Jinja documentation as available on its project page (2.9+, which OctoPrint can't upgrade to due to backwards incompatible changes). + * Docs: Better documentation of what kind of input the `FileManager` accepts for `select_file`. + * Docs: Specified OctoPrint version required for plugin tutorial. + +### Bug fixes + + * [#202](https://github.com/foosel/OctoPrint/issues/202) - Fixed an issue with the drag-n-drop area flickering if the mouse was moved too slow while dragging (see also [#1867](https://github.com/foosel/OctoPrint/pull/1867)). + * [#1671](https://github.com/foosel/OctoPrint/issues/1671) - Removed obsolete entry of no longer available filter for empty folders from file list options. + * [#1821](https://github.com/foosel/OctoPrint/issues/1821) - Properly reset "Capture post roll images" setting in timelapse configuration when switching from "off" to "timed" timelapse mode. + * [#1822](https://github.com/foosel/OctoPrint/issues/1822) - Properly reset file metadata when a file is overwritten with a new version. + * [#1836](https://github.com/foosel/OctoPrint/issues/1836) - Fixed order of `PrintCancelled` and `PrintFailed` events on print cancel. + * [#1837](https://github.com/foosel/OctoPrint/issues/1837) - Fixed a race condition causing OctoPrint trying to read data from the current job on job cancel that was no longer there. + * [#1838](https://github.com/foosel/OctoPrint/issues/1838) - Fixed a rare race condition causing an error right at the very start of a print. + * [#1863](https://github.com/foosel/OctoPrint/issues/1863) - Fixed an issue in the analysis of GCODE files containing coordinate offsets for X, Y or Z via `G92`, leading to a wrong calculation of the model size thanks to accumulating offsets. + * [#1882](https://github.com/foosel/OctoPrint/issues/1882) - Fixed a rare race condition occurring at the start of streaming a file to the printer's SD card, leading to endless line number mismatches. + * [#1884](https://github.com/foosel/OctoPrint/issues/1884) - CuraEngine plugin: Fixed a potential encoding issue when logging non-ASCII parameters supplied to CuraEngine + * [#1891](https://github.com/foosel/OctoPrint/issues/1891) - Fixed error when handling unicode passwords. + * [#1893](https://github.com/foosel/OctoPrint/issues/1893) - CuraEngine plugin: Fixed handling of multiple consecutive uploads of slicing profiles (see also [#1894](https://github.com/foosel/OctoPrint/issues/1894)) + * [#1897](https://github.com/foosel/OctoPrint/issues/1897) - Removed possibility to concurrently try to perform multiple tests of the configured snapshot URL. + * [#1906](https://github.com/foosel/OctoPrint/issues/1906) - Fixed interpretation of `G92` in GCODE analysis. + * [#1907](https://github.com/foosel/OctoPrint/issues/1907) - Don't send temperature commands with tool parameter when a shared nozzle is defined. + * [#1917](https://github.com/foosel/OctoPrint/issues/1917) (regression) - Fix job data resetting on print job completion. + * [#1918](https://github.com/foosel/OctoPrint/issues/1918) (regression) - Fix "save as default" checkbox not being disabled when other controls are disabled. + * [#1919](https://github.com/foosel/OctoPrint/issues/1919) (regression) - Fix call to no longer existing function in Plugin Manager UI. + * [#1934](https://github.com/foosel/OctoPrint/issues/1934) (regression) - Fix consecutive timed timelapse captures without configured post roll. + * Fixed API key QR Code being shown (for "n/a" value) when no API key was set. + * Fixed timelapse configuration API not returning 400 status code on some bad parameters. + * Fixed a typo (see also [#1826](https://github.com/foosel/OctoPrint/pull/1826)). + * Fixed `filter` and `force` parameters on `/api/files/`. + * Fixed message catchall `*` not working in the socket client library. + * Fixed analysis backlog calculation for sub folders. + * Fixed `PrinterInterface.is_ready` to behave as documented. + * Use black listing instead of white listing again to detect if the `daemon` sub command is supported or not. Should resolve issues users of FreeBSD and the like where having with `octoprint daemon`. + * Use `pip` instead of `python setup.py develop` in `octoprint dev plugin:install` command to avoid issues on Windows. + * Docs: Fixed a wrong command in the plugin tutorial (see also [#1860](https://github.com/foosel/OctoPrint/pull/1860)). + +### More information + +- [Commits](https://github.com/foosel/OctoPrint/compare/1.3.2...1.3.3) +- Release Candidates: + - [1.3.3rc1](https://github.com/foosel/OctoPrint/releases/tag/1.3.3rc1) + - [1.3.3rc2](https://github.com/foosel/OctoPrint/releases/tag/1.3.3rc2) + - [1.3.3rc3](https://github.com/foosel/OctoPrint/releases/tag/1.3.3rc3) + ## 1.3.2 (2017-03-16) ### Note for plugin authors diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4e3a47439..b8ba81c03 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -365,10 +365,16 @@ There are three main branches in OctoPrint: the `maintenance` branch and are now being pushed on the "Maintenance" pre release channel for further testing. Version number follows the scheme `..rc` (e.g. `1.2.9rc1`). + * `staging/maintenance`: Any preparation for potential follow-up RCs takes place here. + Version number follows the scheme `..rc.dev` (e.g. + `1.2.9rc1.dev3`) for a current Maintenance RC of `..rc`. * `rc/devel`: This branch is reserved for future releases that have graduated from the `devel` branch and are now being pushed on the "Devel" pre release channel for further testing. Version number follows the scheme `..0rc` (e.g. `1.3.0rc1`) for a current stable OctoPrint version of `..`. + * `staging/devel`: Any preparation for potential follow-up Devel RCs takes place + here. Version number follows the scheme `..0rc.dev` (e.g. + `1.3.0rc1.dev12`) for a current Devel RC of `..0rc`. Additionally, from time to time you might see other branches pop up in the repository. Those usually have one of the following prefixes: @@ -380,7 +386,7 @@ Those usually have one of the following prefixes: * `dev/...` or `feature/...`: New functionality under development that is to be merged into the `devel` branch. -There is also the `gh-pages` branch, which holds OctoPrint's web page, and a couple of +There is also the `gh-pages` branch, which holds OctoPrint's web page, and a few older development branches that are slowly being migrated or deleted. ## How OctoPrint is versioned diff --git a/README.md b/README.md index dfe174be2..817884a57 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ and at its settings. ## Dependencies -OctoPrint depends on a couple of python modules to do its job. Those are automatically installed when installing +OctoPrint depends on a few python modules to do its job. Those are automatically installed when installing OctoPrint via `setup.py`: python setup.py install diff --git a/SUPPORTERS.md b/SUPPORTERS.md index 8fd085416..2909b8101 100644 --- a/SUPPORTERS.md +++ b/SUPPORTERS.md @@ -1,4 +1,4 @@ -# Supporters +# Supporters Development of this version of OctoPrint wouldn't have been possible without [financial support by the community](http://octoprint.org/support-octoprint/) - @@ -10,11 +10,11 @@ thanks to everyone who contributed! * Aleph Objects, Inc. * Andrew Moorby * Arnljot Arntsen + * BEEVERYCREATIVE * Boris Hussein * Brad Jackson - * Brent Fiegle * Brian E. Tyler - * Christopher Day + * Chris Day * Christian Petropolis * CreativeTools * D Brian Kimmel @@ -23,13 +23,15 @@ thanks to everyone who contributed! * E3D BigBox * Ernesto Martinez * Exovite + * F. Kunsmann * Frank Sander * Gary Deen * Gary N McKinney * George Robles + * günter weber + * Ivan Krasin * James Seigel * Jamie R McGuigan - * Jamie van Dyke * Jeff Moe * Josh Daniels * Kaile Riser @@ -59,9 +61,8 @@ thanks to everyone who contributed! * Stefan Krister * Stephane Schittly * Sven Mueller - * Terrance Shaw * Thomas Hatley * Timeshell.ca * Trent Shumay -and 1041 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel)! +and 1098 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel)! \ No newline at end of file diff --git a/docs/api/datamodel.rst b/docs/api/datamodel.rst index 076e7dbe4..768e420b0 100644 --- a/docs/api/datamodel.rst +++ b/docs/api/datamodel.rst @@ -31,7 +31,7 @@ Printer State * - ``flags`` - 1 - Printer state flags - - A couple of boolean printer state flags + - A few boolean printer state flags * - ``flags.operational`` - 1 - Boolean diff --git a/docs/bundledplugins/softwareupdate.rst b/docs/bundledplugins/softwareupdate.rst index a4e1213ee..17efc535c 100644 --- a/docs/bundledplugins/softwareupdate.rst +++ b/docs/bundledplugins/softwareupdate.rst @@ -188,6 +188,16 @@ Version checks * ``repo``: (mandatory) Github repository to check * ``branch``: Branch of the Github repository to check, defaults to ``master`` if not set. + * ``current``: Current commit hash. Will be updated automatically. + + * ``bitbucket_commit``: Checks against commits pushed to Bitbucket. Additional + config parameters: + + * ``user``: (mandatory) Bitbucket user the repository to check belongs to + * ``repo``: (mandatory) Bitbucket repository to check + * ``branch``: Branch of the Bitbucket repository to check, defaults to + ``master`` if not set. + * ``current``: Current commit hash. Will be updated automatically. * ``git_commit``: Checks a local git repository for new commits on its configured remote. Additional config parameters: diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index c48389ae8..debb35d16 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -943,8 +943,8 @@ Use the following settings to configure the server: * ``X-Scheme``: should contain your custom URL scheme to use (if different from ``http``), e.g. ``https`` If you use these headers OctoPrint will work both via the reverse proxy as well as when called directly. Take a look - `into OctoPrint's wiki `_ for a couple - of examples on how to configure this. + `into OctoPrint's wiki `_ for some + examples on how to configure this. .. _sec-configuration-config_yaml-slicing: diff --git a/docs/features/gcode_scripts.rst b/docs/features/gcode_scripts.rst index e58cfdbc5..ee3136da8 100644 --- a/docs/features/gcode_scripts.rst +++ b/docs/features/gcode_scripts.rst @@ -13,11 +13,19 @@ Unless :ref:`configured otherwise `, OctoP the ``scripts/gcode`` folder in OctoPrint configuration directory (per default ``~/.octoprint`` on Linux, ``%APPDATA%\OctoPrint`` on Windows and ``~/Library/Application Support/OctoPrint`` on MacOS). -These GCODE scripts are backed by the templating engine `Jinja2 `_, allowing more than just +These GCODE scripts are backed by the templating engine Jinja2, allowing more than just simple "send-as-is" scripts but making use of a full blown templating language in order to create your scripts. To -this end, OctoPrint injects a couple of variables into the :ref:`template rendering context ` +this end, OctoPrint injects some variables into the :ref:`template rendering context ` as described below. +You can find the docs on the Jinja templating engine as used in OctoPrint at `jinja.octoprint.org `_. + +.. note:: + + Due to backwards compatibility issues with Jinja versions 2.9+, OctoPrint currently only supports Jinja 2.8. For this + reason use the template documentation at `jinja.octoprint.org `_ instead of the + documentation of current stable Jinja versions. + .. _sec-features-gcode_scripts-predefined: Predefined Scripts @@ -64,19 +72,21 @@ All GCODE scripts have access to the following template variables through the te * ``script``: An object wrapping the script's type (``gcode``) and name (e.g. ``afterPrintCancelled``) as ``script.type`` and ``script.name`` respectively. -There are a couple of additional template variables available for the following specific scripts: +There are a few additional template variables available for the following specific scripts: * ``afterPrintPaused`` and ``beforePrintResumed`` * ``pause_position``: Position reported by the printer via ``M114`` immediately before the print was paused. Consists of ``x``, ``y``, ``z`` and ``e`` coordinates as received by the printer and tracked values for ``f`` and current tool - ``t`` taken from commands sent through OctoPrint. + ``t`` taken from commands sent through OctoPrint. All of these coordinates might be ``None`` if no position could be + retrieved from the printer or the values could not be tracked (in case of ``f`` and ``t``)! * ``afterPrintCancelled`` * ``cancel_position``: Position reported by the printer via ``M114`` immediately before the print was cancelled. Consists of ``x``, ``y``, ``z`` and ``e`` coordinates as received by the printer and tracked values for ``f`` and - current tool ``t`` taken from commands sent through OctoPrint. + current tool ``t`` taken from commands sent through OctoPrint. All of these coordinates might be ``None`` if no + position could be retrieved from the printer or the values could not be tracked (in case of ``f`` and ``t``)! .. warning:: @@ -150,6 +160,7 @@ to 0 if a heated bed is configured. .. seealso:: - `Jinja Template Designer Documentation `_ + `Jinja Template Designer Documentation `_ Jinja's Template Designer Documentation describes the syntax and semantics of the template language used - also by OctoPrint's GCODE scripts. + also by OctoPrint's GCODE scripts. Linked here are the docs for Jinja 2.8.1, which OctoPrint still + relies on for backwards compatibility reasons. diff --git a/docs/plugins/gettingstarted.rst b/docs/plugins/gettingstarted.rst index 6bb554921..ca4f3935d 100644 --- a/docs/plugins/gettingstarted.rst +++ b/docs/plugins/gettingstarted.rst @@ -20,7 +20,7 @@ development environment:: $ virtualenv venv [...] $ source venv/bin/activate - (venv) $ pip install -e[develop] + (venv) $ pip install -e .[develop] [...] (venv) $ octoprint --help Usage: octoprint [OPTIONS] COMMAND [ARGS]... @@ -41,7 +41,15 @@ development environment:: [...] -We'll start at the most basic form a plugin can take - just a couple of simple lines of Python code: +.. important:: + + This tutorial assumes you are running OctoPrint 1.3.0 and up. Please make sure your version of + OctoPrint is up to date before proceeding. If you did a fresh checkout, that should already + be the case but if not you might have to update first. You can check your version of OctoPrint + by running ``octoprint --version`` or by taking a look into the lower left corner in OctoPrint's + web interface. + +We'll start at the most basic form a plugin can take - just a few simple lines of Python code: .. code-block:: python :linenos: @@ -108,7 +116,7 @@ used :func:`~octoprint.plugin.StartupPlugin.on_startup` instead, in which case o up and ready to serve requests. You'll also note that we are using ``self._logger`` for logging. Where did that one come from? OctoPrint's plugin system -injects :ref:`a couple of useful objects ` into our plugin implementation classes, +injects :ref:`a some useful objects ` into our plugin implementation classes, one of those being a fully instantiated `python logger `_ ready to be used by your plugin. As you can see in the log output above, that logger uses the namespace ``octoprint.plugins.helloworld`` for our little plugin here, or more generally ``octoprint.plugins.``. @@ -482,7 +490,7 @@ Also adjust your plugin's ``templates/helloworld_navbar.jinja2`` like this: OctoPrint injects the template variables that your plugin defines prefixed with ``plugin__`` into the template renderer, so your ``url`` got turned into ``plugin_helloworld_url`` which you can now use as a simple -`Jinja2 Variable `_ in your plugin's template. +`Jinja2 Variable `_ in your plugin's template. Restart OctoPrint and shift-reload the page in your browser (to make sure you really get a fresh copy). The link should still work and point to the URL we defined as default. @@ -1070,8 +1078,14 @@ For some insight on how to create plugins that react to various events within Oc add support for a slicer, OctoPrint's own bundled `CuraEngine plugin `_ might give some hints. For extending OctoPrint's interface, the `NavbarTemp plugin `_ might show what's possible with a few lines of code already. Finally, just take a look at the -`list of available plugins `_ on the OctoPrint wiki if you are -looking for examples. +`official Plugin Repository `_ if you are looking for examples. + +.. seealso:: + + `Jinja Template Designer Documentation `_ + Jinja's Template Designer Documentation describes the syntax and semantics of the template language used + by OctoPrint's frontend. Linked here are the docs for Jinja 2.8.1, which OctoPrint still + relies on for backwards compatibility reasons [#f3]_. .. rubric:: Footnotes @@ -1084,3 +1098,7 @@ looking for examples. .. [#f2] Refer to the `LESS documentation `_ on how to do that. If you are developing your plugin under Windows you might also want to give `WinLESS `_ a look which will run in the background and keep your CSS files up to date with your various project's LESS files automatically. +.. [#f3] Please always consult the Jinja documentation at `jinja.octoprint.org `_ instead of + the current stable documentation available at Jinja's project page. The reason for that is that for backwards + compatibility reasons OctoPrint currently sadly has to rely on an older version of Jinja. The documentation + available at `jinja.octoprint.org `_ matches that older version. diff --git a/docs/plugins/helpers.rst b/docs/plugins/helpers.rst index 047811d8b..17cd18289 100644 --- a/docs/plugins/helpers.rst +++ b/docs/plugins/helpers.rst @@ -6,7 +6,7 @@ Helpers Helpers are methods that plugin can exposed to other plugins in order to make common functionality available on the system. They are registered with the OctoPrint plugin system through the use of the control property ``__plugin_helpers__``. -An example for providing a couple of helper functions to the system can be found in the +An example for providing some helper functions to the system can be found in the `Discovery Plugin `_, which provides it's SSDP browsing and Zeroconf browsing and publishing functions as helper methods. diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index 0d9172285..93bd3f108 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -396,7 +396,8 @@ This describes actually four hooks: * ``queuing``: This phase is triggered just before the command is added to the send queue of the communication layer. This corresponds to the moment a command is being read from a file that is currently being printed. Handlers - may suppress or change commands or their command type here. + may suppress or change commands or their command type here. This is the only phase that supports multi command + expansion by having the handler return a list, see below for details. * ``queued``: This phase is triggered just after the command was added to the send queue of the communication layer. No manipulation is possible here anymore (returned values will be ignored). * ``sending``: This phase is triggered just before the command is actually being sent to the printer. Right afterwards @@ -450,6 +451,21 @@ This describes actually four hooks: should use this option. * A 2-tuple consisting of a rewritten version of the ``cmd`` and the ``cmd_type``, e.g. ``return "M105", "temperature_poll"``. Handlers which wish to rewrite both the command and the command type should use this option. + * **``queuing`` phase only**: A list of any of the above to allow for expanding one command into + many. The following example shows how any queued command could be turned into a sequence of a temperature query, + line number reset, display of the ``gcode`` on the printer's display and finally the actual command (this example + does not make a lot of sense to be quiet honest): + + .. code-block:: python + + def multi_expansion(*args, **kwargs): + return [("M105", "temperature_poll"), + ("M110",), + "M117 GCODE: {}".format(gcode), + (command, command_type)] + + Note: Only one command of a given ``cmd_type`` (other than None) may be queued at a time. Trying to rewrite the ``cmd_type`` + to one already in the queue will give an error. **Example** diff --git a/setup.cfg b/setup.cfg index cbda2efbf..9be46c443 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,7 @@ description-file = README.md [versioneer] VCS = git -style = pep440-post +style = pep440-tag versionfile_source = src/octoprint/_version.py versionfile_build = octoprint/_version.py tag_prefix = diff --git a/src/octoprint/cli/__init__.py b/src/octoprint/cli/__init__.py index 8ea8db7f1..7a4133ce9 100644 --- a/src/octoprint/cli/__init__.py +++ b/src/octoprint/cli/__init__.py @@ -160,11 +160,11 @@ def octo(ctx, **kwargs): "start|stop|restart\" is deprecated, please use " "\"octoprint daemon start|stop|restart\" from now on") - if sys.platform.startswith("linux") or sys.platform.startswith("freebsd"): + if sys.platform == "win32" or sys.platform == "darwin": + click.echo("Sorry, daemon mode is not supported under your operating system right now") + else: from octoprint.cli.server import daemon_command ctx.invoke(daemon_command, command=daemon, **kwargs) - else: - click.echo("Sorry, daemon mode is not supported under your operating system right now") else: click.echo("Starting the server via \"octoprint\" is deprecated, " "please use \"octoprint serve\" from now on.") diff --git a/src/octoprint/cli/client.py b/src/octoprint/cli/client.py index 070806ad6..97fcce652 100644 --- a/src/octoprint/cli/client.py +++ b/src/octoprint/cli/client.py @@ -79,30 +79,33 @@ def log_response(response, status_code=True, body=True, headers=False): @client.command("get") @click.argument("path") +@click.option("--timeout", type=float, default=None) @click.pass_context -def get(ctx, path): +def get(ctx, path, timeout): """Performs a GET request against the specified server path.""" - r = ctx.obj.client.get(path) + r = ctx.obj.client.get(path, timeout=timeout) log_response(r) @client.command("post_json") @click.argument("path") @click.argument("data", type=JsonStringParamType()) +@click.option("--timeout", type=float, default=None) @click.pass_context -def post_json(ctx, path, data): +def post_json(ctx, path, data, timeout): """POSTs JSON data to the specified server path.""" - r = ctx.obj.client.post_json(path, data) + r = ctx.obj.client.post_json(path, data, timeout=timeout) log_response(r) @client.command("patch_json") @click.argument("path") @click.argument("data", type=JsonStringParamType()) +@click.option("--timeout", type=float, default=None, help="Request timeout in seconds") @click.pass_context -def patch_json(ctx, path, data): +def patch_json(ctx, path, data, timeout): """PATCHes JSON data to the specified server path.""" - r = ctx.obj.client.patch(path, data, encoding="json") + r = ctx.obj.client.patch(path, data, encoding="json", timeout=timeout) log_response(r) @@ -111,9 +114,10 @@ def patch_json(ctx, path, data): @click.argument("file_path", type=click.Path(exists=True, dir_okay=False, resolve_path=True)) @click.option("--json", is_flag=True) @click.option("--yaml", is_flag=True) +@click.option("--timeout", type=float, default=None, help="Request timeout in seconds") @click.pass_context -def post_from_file(ctx, path, file_path, json_flag, yaml_flag): - """POSTs JSON data to the specified server path.""" +def post_from_file(ctx, path, file_path, json_flag, yaml_flag, timeout): + """POSTs JSON data to the specified server path, taking the data from the specified file.""" if json_flag or yaml_flag: if json_flag: with open(file_path, "rb") as fp: @@ -123,12 +127,12 @@ def post_from_file(ctx, path, file_path, json_flag, yaml_flag): with open(file_path, "rb") as fp: data = yaml.safe_load(fp) - r = ctx.obj.client.post_json(path, data) + r = ctx.obj.client.post_json(path, data, timeout=timeout) else: with open(file_path, "rb") as fp: data = fp.read() - r = ctx.obj.client.post(path, data) + r = ctx.obj.client.post(path, data, timeout=timeout) log_response(r) @@ -140,14 +144,15 @@ def post_from_file(ctx, path, file_path, json_flag, yaml_flag): @click.option("--int", "-i", "int_params", multiple=True, nargs=2, type=click.Tuple([unicode, int])) @click.option("--float", "-f", "float_params", multiple=True, nargs=2, type=click.Tuple([unicode, float])) @click.option("--bool", "-b", "bool_params", multiple=True, nargs=2, type=click.Tuple([unicode, bool])) +@click.option("--timeout", type=float, default=None, help="Request timeout in seconds") @click.pass_context -def command(ctx, path, command, str_params, int_params, float_params, bool_params): +def command(ctx, path, command, str_params, int_params, float_params, bool_params, timeout): """Sends a JSON command to the specified server path.""" data = dict() params = str_params + int_params + float_params + bool_params for param in params: data[param[0]] = param[1] - r = ctx.obj.client.post_command(path, command, additional=data) + r = ctx.obj.client.post_command(path, command, additional=data, timeout=timeout) log_response(r, body=False) @@ -157,23 +162,26 @@ def command(ctx, path, command, str_params, int_params, float_params, bool_param @click.option("--parameter", "-P", "params", multiple=True, nargs=2, type=click.Tuple([unicode, unicode])) @click.option("--file-name", type=click.STRING) @click.option("--content-type", type=click.STRING) +@click.option("--timeout", type=float, default=None, help="Request timeout in seconds") @click.pass_context -def upload(ctx, path, file_path, params, file_name, content_type): +def upload(ctx, path, file_path, params, file_name, content_type, timeout): """Uploads the specified file to the specified server path.""" data = dict() for param in params: data[param[0]] = param[1] - r = ctx.obj.client.upload(path, file_path, additional=data, file_name=file_name, content_type=content_type) + r = ctx.obj.client.upload(path, file_path, + additional=data, file_name=file_name, content_type=content_type, timeout=timeout) log_response(r) @client.command("delete") @click.argument("path") +@click.option("--timeout", type=float, default=None, help="Request timeout in seconds") @click.pass_context -def delete(ctx, path): +def delete(ctx, path, timeout): """Sends a DELETE request to the specified server path.""" - r = ctx.obj.client.delete(path) + r = ctx.obj.client.delete(path, timeout=timeout) log_response(r) diff --git a/src/octoprint/cli/dev.py b/src/octoprint/cli/dev.py index baf678bcc..0d8dd57a1 100644 --- a/src/octoprint/cli/dev.py +++ b/src/octoprint/cli/dev.py @@ -8,6 +8,8 @@ __copyright__ = "Copyright (C) 2015 The OctoPrint Project - Released under terms import click +from past.builtins import basestring + class OctoPrintDevelCommands(click.MultiCommand): """ Custom `click.MultiCommand `_ @@ -204,7 +206,7 @@ class OctoPrintDevelCommands(click.MultiCommand): click.echo("This doesn't look like an OctoPrint plugin folder") sys.exit(1) - self.command_caller.call([sys.executable, "setup.py", "develop"], cwd=path) + self.command_caller.call([sys.executable, "-m", "pip", "install", "-e", "."], cwd=path) return command diff --git a/src/octoprint/cli/server.py b/src/octoprint/cli/server.py index f7539d0a0..cfadc559b 100644 --- a/src/octoprint/cli/server.py +++ b/src/octoprint/cli/server.py @@ -150,8 +150,8 @@ def serve_command(ctx, **kwargs): allow_root, logging, verbosity, safe_mode) -if sys.platform.startswith("linux") or sys.platform.startswith("freebsd"): - # we only support daemon mode under Linux and FreeBSD for now +if sys.platform != "win32" and sys.platform != "darwin": + # we do not support daemon mode under windows or macosx @server_commands.command(name="daemon") @server_options diff --git a/src/octoprint/events.py b/src/octoprint/events.py index 367fd9851..c8630e59a 100644 --- a/src/octoprint/events.py +++ b/src/octoprint/events.py @@ -376,7 +376,7 @@ class CommandTrigger(GenericEventListener): def _processCommand(self, command, payload): """ - Performs string substitutions in the command string based on a couple of current parameters. + Performs string substitutions in the command string based on a few current parameters. The following substitutions are currently supported: diff --git a/src/octoprint/filemanager/__init__.py b/src/octoprint/filemanager/__init__.py index f6907699e..856acc8ef 100644 --- a/src/octoprint/filemanager/__init__.py +++ b/src/octoprint/filemanager/__init__.py @@ -20,6 +20,8 @@ from .util import AbstractFileWrapper, StreamWrapper, DiskFileWrapper from collections import namedtuple +from past.builtins import basestring + ContentTypeMapping = namedtuple("ContentTypeMapping", "extensions, content_type") ContentTypeDetector = namedtuple("ContentTypeDetector", "extensions, detector") diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index 399108dfd..e63e49a81 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -20,6 +20,8 @@ from octoprint.util import atomic_write from contextlib import contextmanager from copy import deepcopy +from past.builtins import basestring + import octoprint.filemanager from octoprint.util import is_hidden_path @@ -676,16 +678,9 @@ class LocalFileStorage(StorageInterface): # save the file's hash to the metadata of the folder file_hash = self._create_hash(file_path) metadata = self._get_metadata_entry(path, name, default=dict()) - metadata_dirty = False if not "hash" in metadata or metadata["hash"] != file_hash: - metadata["hash"] = file_hash - metadata_dirty = True - if "analysis" in metadata: - del metadata["analysis"] - metadata_dirty = True - - if metadata_dirty: - self._update_metadata_entry(path, name, metadata) + # hash changed -> throw away old metadata + self._update_metadata_entry(path, name, dict(hash=file_hash)) # process any links that were also provided for adding to the file if not links: diff --git a/src/octoprint/job/__init__.py b/src/octoprint/job/__init__.py index ddeefff00..ca8bf0168 100644 --- a/src/octoprint/job/__init__.py +++ b/src/octoprint/job/__init__.py @@ -151,6 +151,11 @@ class LocalFilePrintjob(Printjob): def path(self): return self._path + def event_payload(self): + event_data = Printjob.event_payload(self) + event_data["size"] = self.size + return event_data + def process(self, protocol, position=0): Printjob.process(self, protocol, position=position) @@ -280,6 +285,11 @@ class SDFilePrintjob(Printjob, FileAwareProtocolListener): def status_interval(self): return self._status_interval + def event_payload(self): + event_data = Printjob.event_payload(self) + event_data["size"] = self.size + return event_data + def can_process(self, protocol): from octoprint.comm.protocol import FileAwareProtocolMixin return SDFilePrintjob in protocol.supported_jobs and isinstance(protocol, FileAwareProtocolMixin) diff --git a/src/octoprint/plugin/__init__.py b/src/octoprint/plugin/__init__.py index 31367e542..57adfb2ed 100644 --- a/src/octoprint/plugin/__init__.py +++ b/src/octoprint/plugin/__init__.py @@ -239,7 +239,7 @@ class PluginSettings(object): """ The :class:`PluginSettings` class is the interface for plugins to their own or globally defined settings. - It provides a couple of convenience methods for directly accessing plugin settings via the regular + It provides some convenience methods for directly accessing plugin settings via the regular :class:`octoprint.settings.Settings` interfaces as well as means to access plugin specific folder locations. All getter and setter methods will ensure that plugin settings are stored in their correct location within the diff --git a/src/octoprint/plugin/core.py b/src/octoprint/plugin/core.py index f8a168f5d..4f98a29ab 100644 --- a/src/octoprint/plugin/core.py +++ b/src/octoprint/plugin/core.py @@ -571,6 +571,10 @@ class PluginManager(object): key = entry.name elif entry.is_file() and entry.name.endswith(".py"): key = entry.name[:-3] # strip off the .py extension + if key.startswith("__"): + # might be an __init__.py in our plugins folder, or something else we don't want + # to handle + continue else: continue diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index 2886fb208..8edfdf20c 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -23,6 +23,7 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms from .core import (Plugin, RestartNeedingPlugin, SortablePlugin) +from past.builtins import basestring class OctoPrintPlugin(Plugin): """ @@ -531,7 +532,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): provided request by calling :meth:`~octoprint.plugin.UiPlugin.will_handle_ui` with the Flask `Request `_ object as parameter. If you plugin returns `True` here, OctoPrint will next call - :meth:`~octoprint.plugin.UiPlugin.on_ui_render` with a couple of parameters like + :meth:`~octoprint.plugin.UiPlugin.on_ui_render` with a few parameters like - again - the Flask Request object and the render keyword arguments as used by the default OctoPrint web interface. For more information see below. @@ -582,7 +583,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): it only gets re-rendered if the request demands that (by having no-cache headers set) or if the cache gets invalidated otherwise. - In order to be able to do that, the ``UiPlugin`` offers overriding a couple of cache specific + In order to be able to do that, the ``UiPlugin`` offers overriding some cache specific methods used for figuring out the source files whose modification time to use for cache invalidation as well as override possibilities for ETag and LastModified calculation. Additionally there are methods to allow persisting call parameters to allow for preemptively caching your UI during @@ -1038,7 +1039,7 @@ class SimpleApiPlugin(OctoPrintPlugin): mixin offers. Use this mixin if all you need to do is return some kind of dynamic data to your plugin from the backend - and/or want to react to simple commands which boil down to a type of command and a couple of flat parameters + and/or want to react to simple commands which boil down to a type of command and a few flat parameters supplied with it. The simple API constructed by OctoPrint for you will be made available under ``/api/plugin//``. @@ -1377,6 +1378,14 @@ class SettingsPlugin(OctoPrintPlugin): Of course, you are always free to completely override both :func:`on_settings_load` and :func:`on_settings_save` if the default implementations do not fit your requirements. + + .. warning:: + + Make sure to protect sensitive information stored by your plugin that only logged in administrators (or users) + should have access to via :meth:`~octoprint.plugin.SettingsPlugin.get_settings_restricted_paths`. OctoPrint will + return its settings on the REST API even to anonymous clients, but will filter out fields it know are restricted, + therefore you **must** make sure that you specify sensitive information accordingly to limit access as required! + .. attribute:: _settings The :class:`~octoprint.plugin.PluginSettings` instance to use for accessing the plugin's settings. Injected by @@ -1548,8 +1557,8 @@ class SettingsPlugin(OctoPrintPlugin): field="field"), path=dict(to=dict(never=dict(return="return")))) - def get_settings_restricted_path(self): - return dict(admin=[["some", "admin_only", "path"], ["another", "admin_only", "path"], + def get_settings_restricted_paths(self): + return dict(admin=[["some", "admin_only", "path"], ["another", "admin_only", "path"],], user=[["some", "user_only", "path"],], never=[["path", "to", "never", "return"],]) diff --git a/src/octoprint/plugins/__init__.py b/src/octoprint/plugins/__init__.py new file mode 100644 index 000000000..1b0510c60 --- /dev/null +++ b/src/octoprint/plugins/__init__.py @@ -0,0 +1 @@ +# make our plugins testable diff --git a/src/octoprint/plugins/announcements/__init__.py b/src/octoprint/plugins/announcements/__init__.py index 00a2664a9..7f73efb20 100644 --- a/src/octoprint/plugins/announcements/__init__.py +++ b/src/octoprint/plugins/announcements/__init__.py @@ -41,7 +41,13 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin, # StartupPlugin def on_after_startup(self): - self._fetch_all_channels() + # decouple channel fetching from server startup + def fetch_data(): + self._fetch_all_channels() + + thread = threading.Thread(target=fetch_data) + thread.daemon = True + thread.start() # SettingsPlugin @@ -324,7 +330,8 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin, url = config["url"] try: start = time.time() - r = requests.get(url) + r = requests.get(url, timeout=30) + r.raise_for_status() self._logger.info(u"Loaded channel {} from {} in {:.2}s".format(key, config["url"], time.time() - start)) except Exception as e: self._logger.exception( @@ -359,7 +366,7 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin, return dict(title=entry["title"], title_without_tags=_strip_tags(entry["title"]), - summary=entry["summary"], + summary=_lazy_images(entry["summary"]), summary_without_images=_strip_images(entry["summary"]), published=published, link=entry["link"], @@ -374,8 +381,57 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin, _image_tag_re = re.compile(r'') def _strip_images(text): + """ + >>> _strip_images(u"I'm a link and this is an image: foo") + u"I'm a link and this is an image: " + >>> _strip_images(u"One and two and three and four \\"four\\"") + u'One and two and three and four ' + >>> _strip_images(u"No images here") + u'No images here' + """ return _image_tag_re.sub('', text) +def _replace_images(text, callback): + """ + >>> callback = lambda img: "foobar" + >>> _replace_images(u"I'm a link and this is an image: foo", callback) + u"I'm a link and this is an image: foobar" + >>> _replace_images(u"One and two and three and four \\"four\\"", callback) + u'One foobar and two foobar and three foobar and four foobar' + """ + result = text + for match in _image_tag_re.finditer(text): + tag = match.group(0) + replaced = callback(tag) + result = result.replace(tag, replaced) + return result + +_image_src_re = re.compile(r'src=(?P[\'"]*)(?P.*?)(?P=quote)(?=\s+|>)') +def _lazy_images(text, placeholder=None): + """ + >>> _lazy_images(u"I'm a link and this is an image: foo") + u'I\\'m a link and this is an image: \\'foo\\'' + >>> _lazy_images(u"I'm a link and this is an image: foo", placeholder="ph.png") + u'I\\'m a link and this is an image: \\'foo\\'' + >>> _lazy_images(u"One and two and three and four \\"four\\"", placeholder="ph.png") + u'One and two and three and four four' + >>> _lazy_images(u"No images here") + u'No images here' + """ + if placeholder is None: + # 1px transparent gif + placeholder = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" + + def callback(img_tag): + match = _image_src_re.search(img_tag) + if match is not None: + src = match.group("src") + quote = match.group("quote") + quoted_src = quote + src + quote + img_tag = img_tag.replace(match.group(0), 'src="{}" data-src={}'.format(placeholder, quoted_src)) + return img_tag + + return _replace_images(text, callback) def _strip_tags(text): """ diff --git a/src/octoprint/plugins/announcements/static/js/announcements.js b/src/octoprint/plugins/announcements/static/js/announcements.js index dfd6d7d9a..a5af767d0 100644 --- a/src/octoprint/plugins/announcements/static/js/announcements.js +++ b/src/octoprint/plugins/announcements/static/js/announcements.js @@ -40,7 +40,7 @@ $(function() { }; self.toggleButtonCss = function(data) { - var icon = data.enabled ? "icon-circle" : "icon-circle-blank"; + var icon = data.enabled ? "fa fa-circle" : "fa fa-circle-o"; var disabled = (self.enableToggle(data)) ? "" : " disabled"; return icon + disabled; @@ -143,6 +143,9 @@ $(function() { self.showAnnouncementDialog = function(channel) { if (!self.loginState.isAdmin()) return; + // lazy load images that still need lazy-loading + $("#plugin_announcements_dialog_content article img").lazyload(); + self.announcementDialogContent.scrollTop(0); if (!self.announcementDialog.hasClass("in")) { @@ -255,22 +258,22 @@ $(function() { buttons: [{ text: gettext("Later"), click: function(notice) { - self.hiddenChannels.push(key); notice.remove(); + self.hiddenChannels.push(key); } }, { text: gettext("Mark read"), click: function(notice) { - self.markRead(key, value.last); notice.remove(); + self.markRead(key, value.last); } }, { text: gettext("Read..."), addClass: "btn-primary", click: function(notice) { + notice.remove(); self.showAnnouncementDialog(key); self.markRead(key, value.last); - notice.remove(); } }] }, diff --git a/src/octoprint/plugins/announcements/templates/announcements.jinja2 b/src/octoprint/plugins/announcements/templates/announcements.jinja2 index 24fbe551f..0560c8ebc 100644 --- a/src/octoprint/plugins/announcements/templates/announcements.jinja2 +++ b/src/octoprint/plugins/announcements/templates/announcements.jinja2 @@ -28,7 +28,7 @@
@@ -40,7 +40,7 @@ diff --git a/src/octoprint/plugins/announcements/templates/announcements_navbar.jinja2 b/src/octoprint/plugins/announcements/templates/announcements_navbar.jinja2 index 8f91e47eb..933cc5521 100644 --- a/src/octoprint/plugins/announcements/templates/announcements_navbar.jinja2 +++ b/src/octoprint/plugins/announcements/templates/announcements_navbar.jinja2 @@ -1,3 +1,3 @@ - + diff --git a/src/octoprint/plugins/announcements/templates/announcements_settings.jinja2 b/src/octoprint/plugins/announcements/templates/announcements_settings.jinja2 index 0d76029c1..b3d42996d 100644 --- a/src/octoprint/plugins/announcements/templates/announcements_settings.jinja2 +++ b/src/octoprint/plugins/announcements/templates/announcements_settings.jinja2 @@ -32,4 +32,4 @@ - + diff --git a/src/octoprint/plugins/corewizard/__init__.py b/src/octoprint/plugins/corewizard/__init__.py index 64525a1a4..6b7a5cd8b 100644 --- a/src/octoprint/plugins/corewizard/__init__.py +++ b/src/octoprint/plugins/corewizard/__init__.py @@ -49,9 +49,12 @@ class CoreWizardPlugin(octoprint.plugin.AssetPlugin, #~~ AssetPlugin API def get_assets(self): - return dict( - js=["js/corewizard.js"] - ) + if self.is_wizard_required(): + return dict( + js=["js/corewizard.js"] + ) + else: + return dict() #~~ WizardPlugin API @@ -74,7 +77,7 @@ class CoreWizardPlugin(octoprint.plugin.AssetPlugin, return self._user_manager.enabled and not self._user_manager.hasBeenCustomized() def _get_acl_wizard_details(self): - return dict() + return dict(required=self._is_acl_wizard_required()) def _get_acl_wizard_name(self): return gettext("Access Control") @@ -119,7 +122,7 @@ class CoreWizardPlugin(octoprint.plugin.AssetPlugin, return not (webcam_snapshot_url and webcam_stream_url and ffmpeg_path) def _get_webcam_wizard_details(self): - return dict() + return dict(required=self._is_webcam_wizard_required()) def _get_webcam_wizard_name(self): return gettext("Webcam & Timelapse") @@ -134,7 +137,7 @@ class CoreWizardPlugin(octoprint.plugin.AssetPlugin, return not (system_shutdown_command and system_restart_command and server_restart_command) def _get_servercommands_wizard_details(self): - return dict() + return dict(required=self._is_servercommands_wizard_required()) def _get_servercommands_wizard_name(self): return gettext("Server Commands") @@ -145,7 +148,7 @@ class CoreWizardPlugin(octoprint.plugin.AssetPlugin, return self._printer_profile_manager.is_default_unmodified() and self._printer_profile_manager.profile_count == 1 def _get_printerprofile_wizard_details(self): - return dict() + return dict(required=self._is_printerprofile_wizard_required()) def _get_printerprofile_wizard_name(self): return gettext("Default Printer Profile") diff --git a/src/octoprint/plugins/corewizard/static/js/corewizard.js b/src/octoprint/plugins/corewizard/static/js/corewizard.js index 1c37e2666..b59b676b2 100644 --- a/src/octoprint/plugins/corewizard/static/js/corewizard.js +++ b/src/octoprint/plugins/corewizard/static/js/corewizard.js @@ -11,6 +11,8 @@ $(function() { self.setup = ko.observable(false); self.decision = ko.observable(); + self.required = false; + self.passwordMismatch = ko.pureComputed(function() { return self.password() != self.confirmedPassword(); }); @@ -72,6 +74,8 @@ $(function() { }; self.onBeforeWizardTabChange = function(next, current) { + if (!self.required) return true; + if (!current || !_.startsWith(current, "wizard_plugin_corewizard_acl_") || self.setup()) { return true; } @@ -82,7 +86,13 @@ $(function() { return false; }; + self.onWizardDetails = function(response) { + self.required = response && response.corewizard && response.corewizard.details && response.corewizard.details.acl && response.corewizard.details.acl.required; + }; + self.onWizardFinish = function() { + if (!self.required) return; + if (!self.decision()) { return "reload"; } @@ -94,7 +104,14 @@ $(function() { self.settingsViewModel = parameters[0]; + self.required = false; + + self.onWizardDetails = function(response) { + self.required = response && response.corewizard && response.corewizard.details && response.corewizard.details.webcam && response.corewizard.details.webcam.required; + }; + self.onWizardFinish = function() { + if (!self.required) return; if (self.settingsViewModel.webcam_streamUrl() || (self.settingsViewModel.webcam_snapshotUrl() && self.settingsViewModel.webcam_ffmpegPath())) { return "reload"; @@ -113,18 +130,29 @@ $(function() { self.printerProfiles = parameters[0]; + self.required = false; + self.editor = self.printerProfiles.createProfileEditor(); self.editorLoaded = ko.observable(false); - self.onStartup = function() { + self.onWizardDetails = function(response) { + self.required = response && response.corewizard && response.corewizard.details && response.corewizard.details.printerprofile && response.corewizard.details.printerprofile.required; + if (!self.required) return; + OctoPrint.printerprofiles.get("_default") .done(function(data) { self.editor.fromProfileData(data); self.editorLoaded(true); + }) + .fail(function() { + self.editor.fromProfileData(); + self.editorLoaded(true); }); }; self.onWizardFinish = function() { + if (!self.required) return; + OctoPrint.printerprofiles.update("_default", self.editor.toProfileData()) .done(function() { self.printerProfiles.requestData(); diff --git a/src/octoprint/plugins/cura/__init__.py b/src/octoprint/plugins/cura/__init__.py index 5fd933fb0..8713c3778 100644 --- a/src/octoprint/plugins/cura/__init__.py +++ b/src/octoprint/plugins/cura/__init__.py @@ -17,6 +17,7 @@ import octoprint.slicing import octoprint.settings from octoprint.util.paths import normalize as normalize_path +from octoprint.util import to_unicode from .profile import Profile from .profile import GcodeFlavors @@ -236,7 +237,8 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin, self._save_profile(path, new_profile, allow_overwrite=allow_overwrite) - def do_slice(self, model_path, printer_profile, machinecode_path=None, profile_path=None, position=None, on_progress=None, on_progress_args=None, on_progress_kwargs=None): + def do_slice(self, model_path, printer_profile, machinecode_path=None, profile_path=None, position=None, + on_progress=None, on_progress_args=None, on_progress_kwargs=None): try: with self._job_mutex: if not profile_path: @@ -258,7 +260,10 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin, if not on_progress_kwargs: on_progress_kwargs = dict() - self._cura_logger.info(u"### Slicing %s to %s using profile stored at %s" % (model_path, machinecode_path, profile_path)) + self._cura_logger.info(u"### Slicing {} to {} using profile stored at {}" + .format(to_unicode(model_path, errors="replace"), + to_unicode(machinecode_path, errors="replace"), + to_unicode(profile_path, errors="replace"))) executable = normalize_path(self._settings.get(["cura_engine"])) if not executable: @@ -293,7 +298,9 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin, args += ["-s", "%s=%s" % (k, str(v))] args += ["-o", machinecode_path, model_path] - self._logger.info(u"Running %r in %s" % (" ".join(args), working_dir)) + self._logger.info(u"Running {!r} in {}".format(u" ".join(map(lambda x: to_unicode(x, errors="replace"), + args)), + working_dir)) import sarge p = sarge.run(args, cwd=working_dir, async=True, stdout=sarge.Capture(), stderr=sarge.Capture()) @@ -314,7 +321,7 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin, p.commands[0].poll() continue - line = octoprint.util.to_unicode(line, errors="replace") + line = to_unicode(line, errors="replace") self._cura_logger.debug(line.strip()) if on_progress is not None: @@ -437,7 +444,8 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin, command = self._slicing_commands[machinecode_path] if command is not None: command.terminate() - self._logger.info(u"Cancelled slicing of %s" % machinecode_path) + self._logger.info(u"Cancelled slicing of {}" + .format(to_unicode(machinecode_path, errors="replace"))) def _load_profile(self, path): import yaml diff --git a/src/octoprint/plugins/cura/profile.py b/src/octoprint/plugins/cura/profile.py index 2f8792d09..c8dd13772 100644 --- a/src/octoprint/plugins/cura/profile.py +++ b/src/octoprint/plugins/cura/profile.py @@ -7,7 +7,9 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms import re + from builtins import range +from past.builtins import basestring class SupportLocationTypes(object): NONE = "none" diff --git a/src/octoprint/plugins/cura/static/js/cura.js b/src/octoprint/plugins/cura/static/js/cura.js index 4b57e623b..87f9d5f64 100644 --- a/src/octoprint/plugins/cura/static/js/cura.js +++ b/src/octoprint/plugins/cura/static/js/cura.js @@ -25,11 +25,35 @@ $(function() { self.profileAllowOverwrite = ko.observable(true); self.profileMakeDefault = ko.observable(false); + // make sure to update form data if any of the metadata changes + self.profileName.subscribe(function() { self.copyProfileMetadata(); }); + self.profileDisplayName.subscribe(function() { + if (self.profileDisplayName()) { + self.placeholderName(self._sanitize(self.profileDisplayName()).toLowerCase()); + } + self.copyProfileMetadata(); + }); + self.profileDescription.subscribe(function() { self.copyProfileMetadata(); }); + self.profileAllowOverwrite.subscribe(function() { self.copyProfileMetadata(); }); + self.profileMakeDefault.subscribe(function() { self.copyProfileMetadata(); }); + self.unconfiguredCuraEngine = ko.observable(); self.unconfiguredSlicingProfile = ko.observable(); + self.uploadDialog = $("#settings_plugin_cura_import"); self.uploadElement = $("#settings-cura-import"); - self.uploadButton = $("#settings-cura-import-start"); + self.uploadData = ko.observable(undefined); + self.uploadBusy = ko.observable(false); + + self.uploadEnabled = ko.pureComputed(function() { + return self.fieldsEnabled(); + }); + self.fieldsEnabled = ko.pureComputed(function() { + return self.uploadData() && !self.uploadBusy() + && (self.profileName() || self.placeholderName()) + && (self.profileDisplayName() || self.placeholderDisplayName()) + && (self.profileDescription() || self.placeholderDescription()); + }); self.profiles = new ItemListHelper( "plugin_cura_profiles", @@ -66,6 +90,53 @@ $(function() { return name.replace(/[^a-zA-Z0-9\-_\.\(\) ]/g, "").replace(/ /g, "_"); }; + self.performUpload = function() { + if (self.uploadData()) { + self.uploadData().submit(); + } + }; + + self.copyProfileMetadata = function(form) { + form = form || (self.uploadData() ? self.uploadData().formData : {}); + + if (self.profileName() !== undefined) { + form["name"] = self.profileName(); + } else if (self.placeholderName() !== undefined) { + form["name"] = self.placeholderName(); + } + + if (self.profileDisplayName() !== undefined) { + form["displayName"] = self.profileDisplayName(); + } else if (self.placeholderDisplayName() !== undefined) { + form["displayName"] = self.placeholderDisplayName(); + } + + if (self.profileDescription() !== undefined) { + form["description"] = self.profileDescription(); + } else if (self.placeholderDescription() !== undefined) { + form["description"] = self.placeholderDescription(); + } + + if (self.profileMakeDefault()) { + form["default"] = true; + } + + return form; + }; + + self.clearUpload = function() { + self.uploadData(undefined); + self.fileName(undefined); + self.placeholderName(undefined); + self.placeholderDisplayName(undefined); + self.placeholderDescription(undefined); + self.profileName(undefined); + self.profileDisplayName(undefined); + self.profileDescription(undefined); + self.profileAllowOverwrite(true); + self.profileMakeDefault(false); + }; + self.uploadElement.fileupload({ dataType: "json", maxNumberOfFiles: 1, @@ -73,6 +144,11 @@ $(function() { headers: OctoPrint.getRequestHeaders(), add: function(e, data) { if (data.files.length == 0) { + // no files? ignore + return false; + } + if (self.uploadData()) { + // data already defined? ignore (should never happen) return false; } @@ -83,41 +159,22 @@ $(function() { self.placeholderDisplayName(name); self.placeholderDescription("Imported from " + self.fileName() + " on " + formatDate(new Date().getTime() / 1000)); - self.uploadButton.unbind("click"); - self.uploadButton.on("click", function() { - var form = { - allowOverwrite: self.profileAllowOverwrite() - }; + var form = { + allowOverwrite: self.profileAllowOverwrite() + }; + data.formData = self.copyProfileMetadata(form); - if (self.profileName() !== undefined) { - form["name"] = self.profileName(); - } - if (self.profileDisplayName() !== undefined) { - form["displayName"] = self.profileDisplayName(); - } - if (self.profileDescription() !== undefined) { - form["description"] = self.profileDescription(); - } - if (self.profileMakeDefault()) { - form["default"] = true; - } - - data.formData = form; - data.submit(); - }); + self.uploadData(data); + }, + submit: function(e, data) { + self.copyProfileMetadata(); + self.uploadBusy(true); }, done: function(e, data) { - self.fileName(undefined); - self.placeholderName(undefined); - self.placeholderDisplayName(undefined); - self.placeholderDescription(undefined); - self.profileName(undefined); - self.profileDisplayName(undefined); - self.profileDescription(undefined); - self.profileAllowOverwrite(true); - self.profileMakeDefault(false); + self.uploadBusy(false); + self.clearUpload(); - $("#settings_plugin_cura_import").modal("hide"); + self.uploadDialog.modal("hide"); self.requestData(); self.slicingViewModel.requestData(); } @@ -160,12 +217,9 @@ $(function() { }); }; - self.showImportProfileDialog = function(makeDefault) { - if (makeDefault == undefined) { - makeDefault = _.filter(self.profiles.items(), function(profile) { profile.isdefault() }).length == 0; - } - self.profileMakeDefault(makeDefault); - $("#settings_plugin_cura_import").modal("show"); + self.showImportProfileDialog = function() { + self.clearUpload(); + self.uploadDialog.modal("show"); }; self.testEnginePath = function() { @@ -207,7 +261,18 @@ $(function() { self.onBeforeBinding = function () { self.settings = self.settingsViewModel.settings; - //self.requestData(); + }; + + self.onAllBound = function() { + self.uploadDialog.on("hidden", function(event) { + if (event.target.id == "settings_plugin_cura_import") { + self.clearUpload(); + } + }); + }; + + self.onSettingsShown = function() { + self.requestData(); }; self.onSettingsHidden = function() { diff --git a/src/octoprint/plugins/cura/templates/snippets/settings/cura/profileImporter.jinja2 b/src/octoprint/plugins/cura/templates/snippets/settings/cura/profileImporter.jinja2 index 063fd5b7c..71ff14659 100644 --- a/src/octoprint/plugins/cura/templates/snippets/settings/cura/profileImporter.jinja2 +++ b/src/octoprint/plugins/cura/templates/snippets/settings/cura/profileImporter.jinja2 @@ -20,31 +20,31 @@
- +
- +
- +
-
-
@@ -59,6 +59,6 @@
diff --git a/src/octoprint/plugins/cura/templates/snippets/settings/cura/profiles.jinja2 b/src/octoprint/plugins/cura/templates/snippets/settings/cura/profiles.jinja2 index 454c97065..f5d85ea3e 100644 --- a/src/octoprint/plugins/cura/templates/snippets/settings/cura/profiles.jinja2 +++ b/src/octoprint/plugins/cura/templates/snippets/settings/cura/profiles.jinja2 @@ -12,10 +12,10 @@ - + -  |  +  |  diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index 8dfabd050..03b81a40c 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -28,6 +28,7 @@ import pkg_resources import copy import dateutil.parser import time +import threading class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, octoprint.plugin.TemplatePlugin, @@ -39,8 +40,9 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, ARCHIVE_EXTENSIONS = (".zip", ".tar.gz", ".tgz", ".tar") OPERATING_SYSTEMS = dict(windows=["win32"], - linux=["linux2"], - macos=["darwin"]) + linux=lambda x: x.startswith("linux"), + macos=["darwin"], + freebsd=lambda x: x.startswith("freebsd")) pip_inapplicable_arguments = dict(uninstall=["--user"]) @@ -84,7 +86,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, ##~~ StartupPlugin - def on_startup(self, host, port): + def on_after_startup(self): from octoprint.logging.handlers import CleaningTimedRotatingFileHandler console_logging_handler = CleaningTimedRotatingFileHandler(self._settings.get_plugin_logfile_path(postfix="console"), when="D", backupCount=3) console_logging_handler.setFormatter(logging.Formatter("%(asctime)s %(message)s")) @@ -94,8 +96,14 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, self._console_logger.setLevel(logging.DEBUG) self._console_logger.propagate = False - self._repository_available = self._fetch_repository_from_disk() - self._notices_available = self._fetch_notices_from_disk() + # decouple repository fetching from server startup + def fetch_data(): + self._repository_available = self._fetch_repository_from_disk() + self._notices_available = self._fetch_notices_from_disk() + + thread = threading.Thread(target=fetch_data) + thread.daemon = True + thread.start() ##~~ SettingsPlugin @@ -675,7 +683,8 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, def _fetch_repository_from_url(self): repository_url = self._settings.get(["repository"]) try: - r = requests.get(repository_url) + r = requests.get(repository_url, timeout=30) + r.raise_for_status() self._logger.info("Loaded plugin repository data from {}".format(repository_url)) except Exception as e: self._logger.exception("Could not fetch plugins from repository at {repository_url}: {message}".format(repository_url=repository_url, message=str(e))) @@ -743,7 +752,8 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, def _fetch_notices_from_url(self): notices_url = self._settings.get(["notices"]) try: - r = requests.get(notices_url) + r = requests.get(notices_url, timeout=30) + r.raise_for_status() self._logger.info("Loaded plugin notices data from {}".format(notices_url)) except Exception as e: self._logger.exception("Could not fetch notices from {notices_url}: {message}".format(notices_url=notices_url, message=str(e))) @@ -807,18 +817,37 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, return True - def _is_os_compatible(self, current_os, compatibility_entries): + @staticmethod + def _is_os_compatible(current_os, compatibility_entries): """ - Tests if the ``current_os`` matches any of the provided ``compatibility_entries``. + Tests if the ``current_os`` or ``sys.platform`` are blacklisted or whitelisted in ``compatibility_entries`` """ - return current_os in filter(lambda x: x in self.__class__.OPERATING_SYSTEMS.keys(), compatibility_entries) + if len(compatibility_entries) == 0: + # shortcut - no compatibility info means we are compatible + return True - def _get_os(self): - for identifier, platforms in self.__class__.OPERATING_SYSTEMS.items(): - if sys.platform in platforms: + negative_entries = map(lambda x: x[1:], filter(lambda x: x.startswith("!"), compatibility_entries)) + positive_entries = filter(lambda x: not x.startswith("!"), compatibility_entries) + + negative_match = False + if negative_entries: + # check if we are blacklisted + negative_match = current_os in negative_entries or any(map(lambda x: sys.platform.startswith(x), negative_entries)) + + positive_match = True + if positive_entries: + # check if we are whitelisted + positive_match = current_os in positive_entries or any(map(lambda x: sys.platform.startswith(x), positive_entries)) + + return positive_match and not negative_match + + @classmethod + def _get_os(cls): + for identifier, platforms in cls.OPERATING_SYSTEMS.items(): + if (callable(platforms) and platforms(sys.platform)) or (isinstance(platforms, list) and sys.platform in platforms): return identifier else: - return "unknown" + return "unmapped" def _get_octoprint_version_string(self): return VERSION diff --git a/src/octoprint/plugins/pluginmanager/static/css/pluginmanager.css b/src/octoprint/plugins/pluginmanager/static/css/pluginmanager.css index 91383181e..65ae4796c 100644 --- a/src/octoprint/plugins/pluginmanager/static/css/pluginmanager.css +++ b/src/octoprint/plugins/pluginmanager/static/css/pluginmanager.css @@ -1 +1 @@ -table td.settings_plugin_plugin_manager_plugins_name,table th.settings_plugin_plugin_manager_plugins_name{text-overflow:ellipsis;text-align:left}table td.settings_plugin_plugin_manager_plugins_actions,table th.settings_plugin_plugin_manager_plugins_actions{text-align:center;width:80px}table td.settings_plugin_plugin_manager_plugins_actions a,table th.settings_plugin_plugin_manager_plugins_actions a{text-decoration:none;color:#000}table td.settings_plugin_plugin_manager_plugins_actions a.disabled,table th.settings_plugin_plugin_manager_plugins_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_repositorydialog .slimScrollDiv{margin-bottom:20px}#settings_plugin_pluginmanager_repositorydialog h4{position:relative}#settings_plugin_pluginmanager_repositorydialog h4 a.dropdown-toggle{color:inherit;text-decoration:none;font-size:14px}#settings_plugin_pluginmanager_repositorydialog h4 ul.dropdown-menu{font-size:14px}#settings_plugin_pluginmanager_repositorydialog .form-search{text-align:center;margin-bottom:5px!important}#settings_plugin_pluginmanager_repositorydialog .form-inline{padding:5px 10px 5px 5px;margin-bottom:0}#settings_plugin_pluginmanager_repositorydialog .form-inline .help-block{margin-bottom:0;font-size:85%}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable{overflow:hidden;width:100%;height:300px;background-image:url(../img/repo_unavailable.png);text-align:center;display:table}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable div{display:table-cell;vertical-align:middle}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list{overflow:hidden;width:auto;height:300px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry{border-bottom:1px solid #ddd;padding:5px 10px 5px 5px}#settings_plugin_pluginmanager_workingdialog_output .message{font-weight:700}#settings_plugin_pluginmanager_workingdialog_output .error{font-weight:700;color:#900}#settings_plugin_pluginmanager_workingdialog_output .stdout{color:#333}#settings_plugin_pluginmanager_workingdialog_output .stderr{color:#900}#settings_plugin_pluginmanager_workingdialog_output .call{color:#009} \ No newline at end of file +table td.settings_plugin_plugin_manager_plugins_name,table th.settings_plugin_plugin_manager_plugins_name{text-overflow:ellipsis;text-align:left}table td.settings_plugin_plugin_manager_plugins_actions,table th.settings_plugin_plugin_manager_plugins_actions{text-align:center;width:80px}table td.settings_plugin_plugin_manager_plugins_actions a,table th.settings_plugin_plugin_manager_plugins_actions a{text-decoration:none;color:#000}table td.settings_plugin_plugin_manager_plugins_actions a.disabled,table th.settings_plugin_plugin_manager_plugins_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_repositorydialog .slimScrollDiv{margin-bottom:20px}#settings_plugin_pluginmanager_repositorydialog h4{position:relative}#settings_plugin_pluginmanager_repositorydialog h4 a.dropdown-toggle{color:inherit;text-decoration:none;font-size:14px}#settings_plugin_pluginmanager_repositorydialog h4 ul.dropdown-menu{font-size:14px}#settings_plugin_pluginmanager_repositorydialog .form-search{text-align:center;margin-bottom:5px!important}#settings_plugin_pluginmanager_repositorydialog .form-inline{padding:5px 10px 5px 5px;margin-bottom:0}#settings_plugin_pluginmanager_repositorydialog .form-inline .help-block{margin-bottom:0;font-size:85%}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable{overflow:hidden;width:100%;height:300px;background-image:url(../img/repo_unavailable.png);text-align:center;display:table}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable div{display:table-cell;vertical-align:middle}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list{overflow:hidden;width:auto;height:300px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry{border-bottom:1px solid #ddd;padding:5px 10px 5px 5px}#settings_plugin_pluginmanager_workingdialog_output span{display:block}#settings_plugin_pluginmanager_workingdialog_output .message{font-weight:700}#settings_plugin_pluginmanager_workingdialog_output .error{font-weight:700;color:#900}#settings_plugin_pluginmanager_workingdialog_output .stdout{color:#333}#settings_plugin_pluginmanager_workingdialog_output .stderr{color:#900}#settings_plugin_pluginmanager_workingdialog_output .call{color:#009} \ No newline at end of file diff --git a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js index 57b1b92d0..d234e2ad3 100644 --- a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js +++ b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js @@ -526,13 +526,11 @@ $(function() { if (reinstall) { OctoPrint.plugins.pluginmanager.reinstall(reinstall, url, followDependencyLinks) .done(onSuccess) - .fail(onError) - .always(onAlways); + .fail(onError); } else { OctoPrint.plugins.pluginmanager.install(url, followDependencyLinks) .done(onSuccess) - .fail(onError) - .always(onAlways); + .fail(onError); } }; @@ -687,17 +685,21 @@ $(function() { hide: false }; + var restartClicked = false; if (self.restartCommandSpec) { options.confirm = { confirm: true, buttons: [{ text: gettext("Restart now"), - click: function () { + click: function (notice) { + if (restartClicked) return; + restartClicked = true; showConfirmationDialog({ message: gettext("This will restart your OctoPrint server."), onproceed: function() { OctoPrint.system.executeCommand("core", "restart") .done(function() { + notice.remove(); new PNotify({ title: gettext("Restart in progress"), text: gettext("The server is now being restarted in the background") @@ -709,6 +711,9 @@ $(function() { text: gettext("Trying to restart the server produced an error, please check octoprint.log for details. You'll have to restart manually.") }) }); + }, + onclose: function() { + restartClicked = false; } }); } @@ -718,6 +723,7 @@ $(function() { notification = PNotify.singleButtonNotify(options); } else if (response.needs_refresh) { + var refreshClicked = false; notification = PNotify.singleButtonNotify({ title: titleSuccess, text: textReload, @@ -726,6 +732,8 @@ $(function() { buttons: [{ text: gettext("Reload now"), click: function () { + if (refreshClicked) return; + refreshClicked = true; location.reload(true); } }] @@ -797,7 +805,7 @@ $(function() { }; self.toggleButtonCss = function(data) { - var icon = self._getToggleCommand(data) == "enable" ? "icon-circle-blank" : "icon-circle"; + var icon = self._getToggleCommand(data) == "enable" ? "fa fa-circle-o" : "fa fa-circle"; var disabled = (self.enableToggle(data)) ? "" : " disabled"; return icon + disabled; diff --git a/src/octoprint/plugins/pluginmanager/static/less/pluginmanager.less b/src/octoprint/plugins/pluginmanager/static/less/pluginmanager.less index 2b591e9cb..cd49e51db 100644 --- a/src/octoprint/plugins/pluginmanager/static/less/pluginmanager.less +++ b/src/octoprint/plugins/pluginmanager/static/less/pluginmanager.less @@ -85,6 +85,10 @@ table { } #settings_plugin_pluginmanager_workingdialog_output { + span { + display: block; + } + .message { font-weight: bold; } diff --git a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 index 93b65dfd3..61323ddeb 100644 --- a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 +++ b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 @@ -25,7 +25,7 @@ {{ pluginmanager_safemode() }}
- +

{{ _('Installed Plugins') }}

@@ -40,18 +40,18 @@ -
()
+
()
 
-  |  +  |  @@ -73,8 +73,8 @@ @@ -209,7 +209,7 @@
- +
diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 58b1e8636..6ce2a0fed 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -35,6 +35,9 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, octoprint.plugin.TemplatePlugin, octoprint.plugin.StartupPlugin, octoprint.plugin.WizardPlugin): + + COMMIT_TRACKING_TYPES = ("github_commit", "bitbucket_commit") + def __init__(self): self._update_in_progress = False self._configured_checks_mutex = threading.Lock() @@ -47,6 +50,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._version_cache_ttl = 0 self._version_cache_path = None self._version_cache_dirty = False + self._version_cache_timestamp = None self._console_logger = None @@ -74,8 +78,14 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._console_logger.propagate = False def on_after_startup(self): - # refresh cache now if necessary so it's faster once the user connects to the instance - self.get_current_versions() + # refresh cache now if necessary so it's faster once the user connects to the instance - but decouple it from + # the server startup + def fetch_data(): + self.get_current_versions() + + thread = threading.Thread(target=fetch_data) + thread.daemon = True + thread.start() def _get_configured_checks(self): with self._configured_checks_mutex: @@ -114,7 +124,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, # This used to be part of the settings migration (version 2) due to a bug - it can't # stay there though since it interferes with manual entries to the checks not # originating from within a plugin. Hence we do that step now here. - if "type" not in effective_config or effective_config["type"] != "github_commit": + if "type" not in effective_config or effective_config["type"] not in self.COMMIT_TRACKING_TYPES: deletables = ["current", "displayVersion"] else: deletables = [] @@ -153,6 +163,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, try: with open(self._version_cache_path) as f: data = yaml.safe_load(f) + timestamp = os.stat(self._version_cache_path).st_mtime except: self._logger.exception("Error while loading version cache from disk") else: @@ -175,6 +186,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._version_cache = data self._version_cache_dirty = False + self._version_cache_timestamp = timestamp self._logger.info("Loaded version cache from disk") except: self._logger.exception("Error parsing in version cache data") @@ -191,6 +203,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, yaml.safe_dump(self._version_cache, stream=file_obj, default_flow_style=False, indent=" ", allow_unicode=True) self._version_cache_dirty = False + self._version_cache_timestamp = time.time() self._logger.info("Saved version cache to disk") #~~ SettingsPlugin API @@ -384,7 +397,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, configured_checks = self._settings.get(["checks"], incl_defaults=False) if configured_checks is not None and "octoprint" in configured_checks: octoprint_check = dict(configured_checks["octoprint"]) - if "type" not in octoprint_check or octoprint_check["type"] != "github_commit": + if "type" not in octoprint_check or octoprint_check["type"] not in self.COMMIT_TRACKING_TYPES: deletables=["current", "displayName", "displayVersion"] else: deletables=[] @@ -460,7 +473,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, data["check"]["python_updater"] = True return flask.jsonify(dict(status="updatePossible" if update_available and update_possible else "updateAvailable" if update_available else "current", - information=information)) + information=information, + timestamp=self._version_cache_timestamp)) except exceptions.ConfigurationInvalid as e: return flask.make_response("Update not properly configured, can't proceed: %s" % e.message, 500) @@ -486,6 +500,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, hash.update(str(data["possible"])) hash.update(",".join(targets)) + hash.update(str(self._version_cache_timestamp)) return hash.hexdigest() def condition(): @@ -833,7 +848,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._settings.load() # persist the new version if necessary for check type - if check["type"] == "github_commit": + if check["type"] in self.COMMIT_TRACKING_TYPES: dummy_default = dict(plugins=dict()) dummy_default["plugins"][self._identifier] = dict(checks=dict()) dummy_default["plugins"][self._identifier]["checks"][target] = dict(current=None) @@ -855,7 +870,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._logger.info("Restarting...") try: - util.execute(restart_command) + util.execute(restart_command, evaluate_returncode=False, async=True) except exceptions.ScriptError as e: self._logger.exception("Error while restarting via command {}".format(restart_command)) self._logger.warn("Restart stdout:\n{}".format(e.stdout)) @@ -890,7 +905,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, release_branches += [x["branch"] for x in check["prerelease_branches"]] result["released_version"] = not release_branches or BRANCH in release_branches - if check["type"] == "github_commit": + if check["type"] in self.COMMIT_TRACKING_TYPES: result["current"] = REVISION if REVISION else "unknown" else: result["current"] = VERSION @@ -904,8 +919,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, result["force_base"] = False if check.get("update_script", None): - # if we are using the update_script, we need to set our update_branch and force - # to install the exact version we requested + # if we are using the update_script, we need to set our update_branch if check.get("prerelease", None): # we are tracking prereleases => we want to be on the correct prerelease channel/branch @@ -915,14 +929,13 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, # in case it's not already set result["update_branch"] = check.get("update_branch", channel) - # we also force our target version in the update - result["force_exact_version"] = True - else: # we are not tracking prereleases, but aren't on the stable branch either => switch back # to stable branch on update result["update_branch"] = check.get("update_branch", stable_branch) + # we also force an exact version + result["force_exact_version"] = True if BRANCH != result.get("prerelease_channel"): # we force python unequality check here because that will also allow us to @@ -944,7 +957,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, # displayVersion AND current missing or None result["displayVersion"] = u"unknown" - if check["type"] in ("github_commit",): + if check["type"] in self.COMMIT_TRACKING_TYPES: result["current"] = check.get("current", None) else: result["current"] = check.get("current", check.get("displayVersion", None)) @@ -976,18 +989,11 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, raise exceptions.ConfigurationInvalid("no check type defined") check_type = check["type"] - if check_type == "github_release": - return version_checks.github_release - elif check_type == "github_commit": - return version_checks.github_commit - elif check_type == "git_commit": - return version_checks.git_commit - elif check_type == "commandline": - return version_checks.commandline - elif check_type == "python_checker": - return version_checks.python_checker - else: + method = getattr(version_checks, check_type) + if method is None: raise exceptions.UnknownCheckType() + else: + return method def _get_update_method(self, target, check, valid_methods=None): """ diff --git a/src/octoprint/plugins/softwareupdate/static/css/softwareupdate.css b/src/octoprint/plugins/softwareupdate/static/css/softwareupdate.css index cace183b3..42c433cbb 100644 --- a/src/octoprint/plugins/softwareupdate/static/css/softwareupdate.css +++ b/src/octoprint/plugins/softwareupdate/static/css/softwareupdate.css @@ -1 +1 @@ -td.settings_plugin_softwareupdate_column_update{width:16px}#settings_plugin_softwareupdate_workingdialog_output{font-size:.8em}#settings_plugin_softwareupdate_workingdialog_output .message{font-weight:bold}#settings_plugin_softwareupdate_workingdialog_output .separator{font-weight:bold;color:#666}#settings_plugin_softwareupdate_workingdialog_output .stdout{color:#333}#settings_plugin_softwareupdate_workingdialog_output .stderr{color:#900}#settings_plugin_softwareupdate_workingdialog_output .call{color:#009}#settings_plugin_softwareupdate_workingdialog_output .message_error{font-weight:bold;color:#900}.softwareupdate_notification ul{margin:10px 0 10px 25px}.softwareupdate_notification ul .name{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;display:block} \ No newline at end of file +td.settings_plugin_softwareupdate_column_update{width:16px}#settings_plugin_softwareupdate_workingdialog_output{font-size:.8em}#settings_plugin_softwareupdate_workingdialog_output .message{font-weight:700}#settings_plugin_softwareupdate_workingdialog_output .separator{font-weight:700;color:#666}#settings_plugin_softwareupdate_workingdialog_output .stdout{color:#333}#settings_plugin_softwareupdate_workingdialog_output .stderr{color:#900}#settings_plugin_softwareupdate_workingdialog_output .call{color:#009}#settings_plugin_softwareupdate_workingdialog_output .message_error{font-weight:700;color:#900}.softwareupdate_notification ul{margin:10px 0 10px 25px}.softwareupdate_notification ul .name{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;display:block} \ No newline at end of file diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index 62bd0003a..6d857aac4 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -111,6 +111,11 @@ $(function() { self.octoprintUnconfigured = ko.observable(); self.octoprintUnreleased = ko.observable(); + self.cacheTimestamp = ko.observable(); + self.cacheTimestampText = ko.pureComputed(function() { + return formatDate(self.cacheTimestamp()); + }); + self.config_cacheTtl = ko.observable(); self.config_notifyUsers = ko.observable(); self.config_checkoutFolder = ko.observable(); @@ -118,8 +123,9 @@ $(function() { self.config_updateMethod = ko.observable(); self.config_releaseChannel = ko.observable(); - self.configurationDialog = $("#settings_plugin_softwareupdate_configurationdialog"); - self.confirmationDialog = $("#softwareupdate_confirmation_dialog"); + self.configurationDialog = undefined; + self.confirmationDialog = undefined; + self._updateClicked = false; self.config_availableCheckTypes = ko.observableArray([]); self.config_availableReleaseChannels = ko.observableArray([]); @@ -198,7 +204,7 @@ $(function() { self.savePluginSettings = function(viewModel, event) { var target = $(event.target); - target.prepend(' '); + target.prepend(' '); var data = { plugins: { @@ -218,7 +224,7 @@ $(function() { self.performCheck(); }, complete: function() { - $("i.icon-spinner", target).remove(); + $("i.fa-spinner", target).remove(); }, sending: true }); @@ -256,6 +262,8 @@ $(function() { }; self.fromCheckResponse = function(data, ignoreSeen, showIfNothingNew) { + self.cacheTimestamp(data.timestamp); + var versions = []; _.each(data.information, function(value, key) { value["key"] = key; @@ -307,11 +315,11 @@ $(function() { if (data.status == "updateAvailable" || data.status == "updatePossible") { var text = "
" + gettext("There are updates available for the following components:"); - text += "
    "; + text += "
      "; _.each(self.versions.items(), function(update_info) { if (update_info.updateAvailable) { text += "
    • " - + "" + + "" + "" + update_info.fullNameRemote + "" + (update_info.releaseNotes ? "" + gettext("Release Notes") + "" : "") + "
    • "; @@ -319,7 +327,7 @@ $(function() { }); text += "
    "; - text += "

    " + gettext("Those components marked with can be updated directly.") + "

    "; + text += "

    " + gettext("Those components marked with can be updated directly.") + "

    "; if (!self.loginState.isAdmin()) { text += "

    " + gettext("To have updates applied, get in touch with an administrator of this OctoPrint instance.") + "

    "; @@ -350,7 +358,11 @@ $(function() { }, { text: gettext("Update now"), addClass: "btn-primary", - click: self.update + click: function() { + if (self._updateClicked) return; + self._updateClicked = true; + self.update(); + } }] }; options["buttons"] = { @@ -465,7 +477,7 @@ $(function() { var options = { title: gettext("Updating..."), text: gettext("Now updating, please wait."), - icon: "icon-cog icon-spin", + icon: "fa fa-cog fa-spin", hide: false, buttons: { closer: false, @@ -494,8 +506,14 @@ $(function() { }; self.update = function(force) { - if (self.updateInProgress) return; - if (!self.loginState.isAdmin()) return; + if (self.updateInProgress) { + self._updateClicked = false; + return; + } + if (!self.loginState.isAdmin()) { + self._updateClicked = false; + return; + } if (self.printerState.isPrinting()) { self._showPopup({ @@ -503,6 +521,7 @@ $(function() { text: gettext("A print job is currently in progress. Updating will be prevented until it is done."), type: "error" }); + self._updateClicked = false; } else { self.forceUpdate = (force == true); self.confirmationDialog.modal("show"); @@ -511,9 +530,13 @@ $(function() { }; self.confirmUpdate = function() { - self.confirmationDialog.modal("hide"); self.performUpdate(self.forceUpdate, _.map(self.availableAndPossible(), function(info) { return info.key })); + self.confirmationDialog.modal("hide"); + }; + + self.confirmationHidden = function() { + self._updateClicked = false; }; self._showWorkingDialog = function(title) { @@ -571,6 +594,10 @@ $(function() { self.onStartup = function() { self.workingDialog = $("#settings_plugin_softwareupdate_workingdialog"); self.workingOutput = $("#settings_plugin_softwareupdate_workingdialog_output"); + self.configurationDialog = $("#settings_plugin_softwareupdate_configurationdialog"); + self.confirmationDialog = $("#softwareupdate_confirmation_dialog"); + + self.confirmationDialog.on("hidden", self.confirmationHidden); }; self.onServerDisconnect = function() { diff --git a/src/octoprint/plugins/softwareupdate/static/less/softwareupdate.less b/src/octoprint/plugins/softwareupdate/static/less/softwareupdate.less index 0065ed958..aeb84d1e8 100644 --- a/src/octoprint/plugins/softwareupdate/static/less/softwareupdate.less +++ b/src/octoprint/plugins/softwareupdate/static/less/softwareupdate.less @@ -5,6 +5,10 @@ td.settings_plugin_softwareupdate_column_update { #settings_plugin_softwareupdate_workingdialog_output { font-size: 0.8em; + span { + display: block; + } + .message { font-weight: bold; } diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 index 857630909..d6ab7289f 100644 --- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 +++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 @@ -1,6 +1,6 @@
    {% trans %} Please configure the checkout folder of OctoPrint, otherwise - this plugin won't be able to update it. Click on the button + this plugin won't be able to update it. Click on the button to do this. Also refer to the Documentation. {% endtrans %}
    {% trans %} @@ -17,7 +17,7 @@ {% endtrans %}
    - +

    {{ _('Current versions') }}

    @@ -26,10 +26,10 @@ - + - :
    + :
    {{ _('Installed:') }}
    {{ _('Available:') }}
    @@ -57,13 +57,14 @@
- +
- +
- - + {{ _('Last cache refresh:') }} + +
@@ -107,7 +108,7 @@

diff --git a/src/octoprint/static/js/app/bindings/togglecontent.js b/src/octoprint/static/js/app/bindings/togglecontent.js index db5ce5785..939a68bec 100644 --- a/src/octoprint/static/js/app/bindings/togglecontent.js +++ b/src/octoprint/static/js/app/bindings/togglecontent.js @@ -14,6 +14,7 @@ ko.bindingHandlers.toggleContent = { e.preventDefault(); if(options.class) { $elm.children('[class^="icon-"]').toggleClass(options.class); + $elm.children('[class^="fa"]').toggleClass(options.class); } if(options.container) { if(options.parent) { diff --git a/src/octoprint/static/js/app/dataupdater.js b/src/octoprint/static/js/app/dataupdater.js index ca25b8101..3c9dfbf44 100644 --- a/src/octoprint/static/js/app/dataupdater.js +++ b/src/octoprint/static/js/app/dataupdater.js @@ -198,12 +198,14 @@ function DataUpdater(allViewModels) { }); } } else if (type == "Error") { - new PNotify({ - title: gettext("Unhandled communication error"), - text: _.sprintf(gettext("The was an unhandled error while talking to the printer. Due to that OctoPrint disconnected. Error: %(error)s"), payload), - type: "error", - hide: false - }); + if (payload.error && payload.error.indexOf("autodetect") == -1) { // ignore "failed to autodetect" + new PNotify({ + title: gettext("Unhandled communication error"), + text: _.sprintf(gettext("The was an unhandled error while talking to the printer. Due to that OctoPrint disconnected. Error: %(error)s"), payload), + type: "error", + hide: false + }); + } } var legacyEventHandlers = { diff --git a/src/octoprint/static/js/app/helpers.js b/src/octoprint/static/js/app/helpers.js index 4e127d8bb..d7248db6d 100644 --- a/src/octoprint/static/js/app/helpers.js +++ b/src/octoprint/static/js/app/helpers.js @@ -398,7 +398,7 @@ function formatFuzzyPrintTime(totalSeconds) { * * Accuracy decreases the higher the estimation is: * - * * less than 30s: "a couple of seconds" + * * less than 30s: "a few seconds" * * 30s to a minute: "less than a minute" * * 1 to 30min: rounded to full minutes, above 30s is minute + 1 ("27 minutes", "2 minutes") * * 30min to 40min: "40 minutes" @@ -495,7 +495,7 @@ function formatFuzzyPrintTime(totalSeconds) { } else { // only seconds if (seconds < 30) { - text = gettext("a couple of seconds"); + text = gettext("a few seconds"); } else { text = gettext("less than a minute"); } @@ -646,6 +646,7 @@ function showConfirmationDialog(msg, onacknowledge, options) { var proceed = options.proceed || gettext("Proceed"); var proceedClass = options.proceedClass || "danger"; var onproceed = options.onproceed || undefined; + var onclose = options.onclose || undefined; var dialogClass = options.dialogClass || ""; var modalHeader = $('

' + title + '

'); @@ -663,14 +664,19 @@ function showConfirmationDialog(msg, onacknowledge, options) { .append($('
').addClass('modal-header').append(modalHeader)) .append($('
').addClass('modal-body').append(modalBody)) .append($('
').addClass('modal-footer').append(cancelButton).append(proceedButton)); + modal.on('hidden', function(event) { + if (onclose && _.isFunction(onclose)) { + onclose(event); + } + }); modal.modal("show"); proceedButton.click(function(e) { e.preventDefault(); - modal.modal("hide"); if (onproceed && _.isFunction(onproceed)) { onproceed(e); } + modal.modal("hide"); }); return modal; @@ -1048,8 +1054,9 @@ var getQueryParameterByName = function(name, url) { * * E.g. turns a null byte in the string into "\x00". * - * Only characters 0 to 31, 127 and 255 will be escaped, that - * should leave printable characters and unicode alone. + * Characters 0 to 31 excluding 9, 10 and 13 will be escaped, as will + * 127 and 255. That should leave printable characters and unicode + * alone. * * Originally based on * https://gist.github.com/mathiasbynens/1243213#gistcomment-53590 @@ -1063,7 +1070,7 @@ var escapeUnprintableCharacters = function(str) { var charCode; while (!isNaN(charCode = str.charCodeAt(index))) { - if (charCode < 32 || charCode == 127 || charCode == 255) { + if ((charCode < 32 && charCode != 9 && charCode != 10 && charCode != 13) || charCode == 127 || charCode == 255) { // special hex chars result += "\\x" + (charCode > 15 ? "" : "0") + charCode.toString(16) } else { diff --git a/src/octoprint/static/js/app/main.js b/src/octoprint/static/js/app/main.js index 072de84ae..e62db2b21 100644 --- a/src/octoprint/static/js/app/main.js +++ b/src/octoprint/static/js/app/main.js @@ -7,7 +7,36 @@ $(function() { //~~ Logging setup - log.setLevel(CONFIG_DEBUG ? "debug" : "info"); + var logFormats = { + trace: "color: grey", + debug: "color: blue", + warn: "color: red", + error: "color: red; font-weight: bold" + }; + + var origLogFactory = log.methodFactory; + log.methodFactory = function(methodName, logLevel, loggerName) { + var rawMethod = origLogFactory(methodName, logLevel, loggerName); + var format = logFormats[methodName]; + var level = _.padRight(methodName.toUpperCase(), 5, " "); + + return function() { + var newArgs; + if (format && (OctoPrint.coreui.browser.chrome || OctoPrint.coreui.browser.firefox)) { + newArgs = ["%c[" + level + "]", format]; + } else { + newArgs = ["[" + level + "]"]; + } + + for (var i = 0; i < arguments.length; i++) { + newArgs.push(arguments[i]); + } + + return rawMethod.apply(null, newArgs); + } + }; + + log.setLevel(CONFIG_DEBUG ? log.levels.DEBUG : log.levels.INFO); //~~ OctoPrint client setup OctoPrint.options.baseurl = BASEURL; @@ -38,7 +67,18 @@ $(function() { browserTabVisibility: undefined, selectedTab: undefined, settingsOpen: false, - wizardOpen: false + wizardOpen: false, + browser: { + chrome: false, + firefox: false, + safari: false, + ie: false, + edge: false, + opera: false, + + mobile: false, + desktop: false + } }; var browserVisibilityCallbacks = []; @@ -88,6 +128,22 @@ $(function() { updateBrowserVisibility(); } + // determine browser - loosely based on is.js + + var navigator = window.navigator; + var userAgent = (navigator && navigator.userAgent || "").toLowerCase(); + var vendor = (navigator && navigator.vendor || "").toLowerCase(); + + exports.browser.opera = userAgent.match(/opera|opr/) != null; + exports.browser.chrome = !exports.browser.opera && /google inc/.test(vendor) && userAgent.match(/chrome|crios/) != null; + exports.browser.firefox = userAgent.match(/firefox|fxios/) != null; + exports.browser.ie = userAgent.match(/msie|trident/) != null; + exports.browser.edge = userAgent.match(/edge/) != null; + exports.browser.safari = !exports.browser.chrome && !exports.browser.edge && !exports.browser.opera && userAgent.match(/safari/) != null; + + exports.browser.mobile = $.browser.mobile; + exports.browser.desktop = !exports.browser.mobile; + // exports exports.isVisible = function() { return !isHidden() }; @@ -98,6 +154,8 @@ $(function() { return exports; })(); + log.debug("Browser enviroment:", OctoPrint.coreui.browser); + //~~ AJAX setup // work around a stupid iOS6 bug where ajax requests get cached and only work once, as described at @@ -444,6 +502,18 @@ $(function() { } }; + $.fn.lazyload = function() { + return this.each(function() { + if (this.tagName.toLowerCase() != "img") return; + + var src = this.getAttribute("data-src"); + if (src) { + this.setAttribute("src", src); + this.removeAttribute("data-src"); + } + }); + }; + // Use bootstrap tabdrop for tabs and pills $('.nav-pills, .nav-tabs').tabdrop(); diff --git a/src/octoprint/static/js/app/viewmodels/control.js b/src/octoprint/static/js/app/viewmodels/control.js index d878eef56..3e5d24b89 100644 --- a/src/octoprint/static/js/app/viewmodels/control.js +++ b/src/octoprint/static/js/app/viewmodels/control.js @@ -37,6 +37,8 @@ $(function() { self.additionalControls = []; self.webcamDisableTimeout = undefined; + self.webcamLoaded = ko.observable(false); + self.webcamError = ko.observable(false); self.keycontrolActive = ko.observable(false); self.keycontrolHelpActive = ko.observable(false); @@ -47,6 +49,14 @@ $(function() { return self.keycontrolActive() && self.keycontrolPossible(); }); + self.webcamRatioClass = ko.pureComputed(function() { + if (self.settings.webcam_streamRatio() == "4:3") { + return "ratio43"; + } else { + return "ratio169"; + } + }); + self.settings.printerProfiles.currentProfileData.subscribe(function () { self._updateExtruderCount(); self.settings.printerProfiles.currentProfileData().extruder.count.subscribe(self._updateExtruderCount); @@ -343,43 +353,21 @@ $(function() { self.requestData(); }; - self.updateRotatorWidth = function() { - var webcamImage = $("#webcam_image"); - if (self.settings.webcam_rotate90()) { - if (webcamImage.width() > 0) { - $("#webcam_rotator").css("height", webcamImage.width()); - } else { - webcamImage.off("load.rotator"); - webcamImage.on("load.rotator", function() { - $("#webcam_rotator").css("height", webcamImage.width()); - webcamImage.off("load.rotator"); - }); - } - } else { - $("#webcam_rotator").css("height", ""); - } - }; - - self.onSettingsBeforeSave = self.updateRotatorWidth; - - self._isSafari = function() { - var is_chrome = navigator.userAgent.indexOf('Chrome') > -1; - var is_safari = navigator.userAgent.indexOf("Safari") > -1; - return is_safari && !is_chrome; - } - self._disableWebcam = function() { // only disable webcam stream if tab is out of focus for more than 5s, otherwise we might cause // more load by the constant connection creation than by the actual webcam stream - + // safari bug doesn't release the mjpeg stream, so we just disable this for safari. - if (self._isSafari()) { + if (OctoPrint.coreui.browser.safari) { return; } - + + var timeout = self.settings.webcam_streamTimeout() || 5; self.webcamDisableTimeout = setTimeout(function () { + log.debug("Unloading webcam stream"); $("#webcam_image").attr("src", ""); - }, 5000); + self.webcamLoaded(false); + }, timeout * 1000); }; self._enableWebcam = function() { @@ -392,12 +380,12 @@ $(function() { } var webcamImage = $("#webcam_image"); var currentSrc = webcamImage.attr("src"); - + // safari bug doesn't release the mjpeg stream, so we just set it up the once - if (self._isSafari() && currentSrc != undefined) { + if (OctoPrint.coreui.browser.safari && currentSrc != undefined) { return; } - + var newSrc = self.settings.webcam_streamUrl(); if (currentSrc != newSrc) { if (newSrc.lastIndexOf("?") > -1) { @@ -407,11 +395,24 @@ $(function() { } newSrc += new Date().getTime(); - self.updateRotatorWidth(); + self.webcamLoaded(false); + self.webcamError(false); webcamImage.attr("src", newSrc); } }; + self.onWebcamLoaded = function() { + log.debug("Webcam stream loaded"); + self.webcamLoaded(true); + self.webcamError(false); + }; + + self.onWebcamErrored = function() { + log.debug("Webcam stream failed to load/disabled"); + self.webcamLoaded(false); + self.webcamError(true); + }; + self.onTabChange = function (current, previous) { if (current == "#control") { self._enableWebcam(); @@ -437,6 +438,7 @@ $(function() { self.additionalControls = additionalControls; self.rerenderControls(); } + self._enableWebcam(); }; self.onFocus = function (data, event) { diff --git a/src/octoprint/static/js/app/viewmodels/files.js b/src/octoprint/static/js/app/viewmodels/files.js index 75bb00926..8f3634976 100644 --- a/src/octoprint/static/js/app/viewmodels/files.js +++ b/src/octoprint/static/js/app/viewmodels/files.js @@ -59,6 +59,14 @@ $(function() { self.localTarget = undefined; self.sdTarget = undefined; + self.dropOverlay = undefined; + self.dropZone = undefined; + self.dropZoneLocal = undefined; + self.dropZoneSd = undefined; + self.dropZoneBackground = undefined; + self.dropZoneLocalBackground = undefined; + self.dropZoneSdBackground = undefined; + self.ignoreUpdatedFilesEvent = false; self.addingFolder = ko.observable(false); @@ -395,14 +403,21 @@ $(function() { } }; - self.loadFile = function(file, printAfterLoad) { - if (!file) { + self.loadFile = function(data, printAfterLoad) { + if (!data) { return; } - var withinPrintDimensions = self.evaluatePrintDimensions(file, true); - var print = printAfterLoad && withinPrintDimensions; - OctoPrint.files.select(file.origin, file.path, print); + if (printAfterLoad && self.listHelper.isSelected(data) && self.enablePrint(data)) { + // file was already selected, just start the print job + OctoPrint.job.start(); + } else { + // select file, start print job (if requested and within dimensions) + var withinPrintDimensions = self.evaluatePrintDimensions(data, true); + var print = printAfterLoad && withinPrintDimensions; + + OctoPrint.files.select(data.origin, data.path, print); + } }; self.removeFile = function(file, event) { @@ -451,13 +466,13 @@ $(function() { if (event) { var element = $(event.currentTarget); if (element.length) { - var icon = $("i.icon-trash", element); + var icon = $("i.fa-trash-o", element); if (icon.length) { activateSpinner = function() { - icon.removeClass("icon-trash").addClass("icon-spinner icon-spin"); + icon.removeClass("fa-trash-o").addClass("fa-spinner fa-spin"); }; finishSpinner = function() { - icon.removeClass("icon-spinner icon-spin").addClass("icon-trash"); + icon.removeClass("fa-spinner fa-spin").addClass("fa-trash-o"); }; } } @@ -545,8 +560,11 @@ $(function() { }; self.enableSelect = function(data, printAfterSelect) { - var isLoadActionPossible = self.loginState.isUser() && self.isOperational() && !(self.isPrinting() || self.isPaused() || self.isLoading()); - return isLoadActionPossible && !self.listHelper.isSelected(data); + return self.enablePrint(data) && !self.listHelper.isSelected(data); + }; + + self.enablePrint = function(data) { + return self.loginState.isUser() && self.isOperational() && !(self.isPrinting() || self.isPaused() || self.isLoading()); }; self.enableSlicing = function(data) { @@ -811,15 +829,26 @@ $(function() { } self.sdTarget = $("#drop_sd"); + self.dropOverlay = $("#drop_overlay"); + self.dropZone = $("#drop"); + self.dropZoneLocal = $("#drop_locally"); + self.dropZoneSd = $("#drop_sd"); + self.dropZoneBackground = $("#drop_background"); + self.dropZoneLocalBackground = $("#drop_locally_background"); + self.dropZoneSdBackground = $("#drop_sd_background"); + + self.dropOverlay.on('drop', self._forceEndDragNDrop); + function evaluateDropzones() { var enableLocal = self.loginState.isUser(); - var enableSd = enableLocal && CONFIG_SD_SUPPORT && self.printerState.isSdReady(); + var enableSd = enableLocal && CONFIG_SD_SUPPORT && self.printerState.isSdReady() && !self.isPrinting(); self._setDropzone("local", enableLocal); self._setDropzone("sdcard", enableSd); } self.loginState.isUser.subscribe(evaluateDropzones); self.printerState.isSdReady.subscribe(evaluateDropzones); + self.isPrinting.subscribe(evaluateDropzones); evaluateDropzones(); self.requestData(); @@ -962,10 +991,12 @@ $(function() { self._enableDragNDrop = function(enable) { if (enable) { - $(document).bind("dragover", self._handleDragNDrop); + $(document).bind("dragenter", self._handleDragNDrop); + $(document).bind("dragleave", self._endDragNDrop); log.debug("Enabled drag-n-drop"); } else { - $(document).unbind("dragover", self._handleDragNDrop); + $(document).unbind("dragenter", self._handleDragNDrop); + $(document).unbind("dragleave", self._endDragNDrop); log.debug("Disabled drag-n-drop"); } }; @@ -1038,34 +1069,35 @@ $(function() { self._setProgressBar(progress, uploaded ? gettext("Saving ...") : gettext("Uploading ..."), uploaded); }; - self._handleDragNDrop = function (e) { - var dropOverlay = $("#drop_overlay"); - var dropZone = $("#drop"); - var dropZoneLocal = $("#drop_locally"); - var dropZoneSd = $("#drop_sd"); - var dropZoneBackground = $("#drop_background"); - var dropZoneLocalBackground = $("#drop_locally_background"); - var dropZoneSdBackground = $("#drop_sd_background"); - var timeout = window.dropZoneTimeout; + self._dragNDropTarget = null; + self._forceEndDragNDrop = function () { + self.dropOverlay.removeClass("in"); + if (self.dropZoneLocal) self.dropZoneLocalBackground.removeClass("hover"); + if (self.dropZoneSd) self.dropZoneSdBackground.removeClass("hover"); + if (self.dropZone) self.dropZoneBackground.removeClass("hover"); + self._dragNDropTarget = null; + }; - if (!timeout) { - dropOverlay.addClass('in'); - } else { - clearTimeout(timeout); - } + self._endDragNDrop = function (e) { + if (e.target != self._dragNDropTarget) return; + self._forceEndDragNDrop(); + }; + + self._handleDragNDrop = function (e) { + self.dropOverlay.addClass('in'); var foundLocal = false; var foundSd = false; var found = false; var node = e.target; do { - if (dropZoneLocal && node === dropZoneLocal[0]) { + if (self.dropZoneLocal && node === self.dropZoneLocal[0]) { foundLocal = true; break; - } else if (dropZoneSd && node === dropZoneSd[0]) { + } else if (self.dropZoneSd && node === self.dropZoneSd[0]) { foundSd = true; break; - } else if (dropZone && node === dropZone[0]) { + } else if (self.dropZone && node === self.dropZone[0]) { found = true; break; } @@ -1073,26 +1105,19 @@ $(function() { } while (node != null); if (foundLocal) { - dropZoneLocalBackground.addClass("hover"); - dropZoneSdBackground.removeClass("hover"); - } else if (foundSd && self.printerState.isSdReady()) { - dropZoneSdBackground.addClass("hover"); - dropZoneLocalBackground.removeClass("hover"); + self.dropZoneLocalBackground.addClass("hover"); + self.dropZoneSdBackground.removeClass("hover"); + } else if (foundSd && self.printerState.isSdReady() && !self.isPrinting()) { + self.dropZoneSdBackground.addClass("hover"); + self.dropZoneLocalBackground.removeClass("hover"); } else if (found) { - dropZoneBackground.addClass("hover"); + self.dropZoneBackground.addClass("hover"); } else { - if (dropZoneLocalBackground) dropZoneLocalBackground.removeClass("hover"); - if (dropZoneSdBackground) dropZoneSdBackground.removeClass("hover"); - if (dropZoneBackground) dropZoneBackground.removeClass("hover"); + if (self.dropZoneLocalBackground) self.dropZoneLocalBackground.removeClass("hover"); + if (self.dropZoneSdBackground) self.dropZoneSdBackground.removeClass("hover"); + if (self.dropZoneBackground) self.dropZoneBackground.removeClass("hover"); } - - window.dropZoneTimeout = setTimeout(function () { - window.dropZoneTimeout = null; - dropOverlay.removeClass("in"); - if (dropZoneLocal) dropZoneLocalBackground.removeClass("hover"); - if (dropZoneSd) dropZoneSdBackground.removeClass("hover"); - if (dropZone) dropZoneBackground.removeClass("hover"); - }, 100); + self._dragNDropTarget = e.target; } } diff --git a/src/octoprint/static/js/app/viewmodels/gcode.js b/src/octoprint/static/js/app/viewmodels/gcode.js index ea8b4c6ea..f96ac908b 100644 --- a/src/octoprint/static/js/app/viewmodels/gcode.js +++ b/src/octoprint/static/js/app/viewmodels/gcode.js @@ -46,6 +46,8 @@ $(function() { self.renderer_zoomOnModel = ko.observable(false); self.renderer_showMoves = ko.observable(true); self.renderer_showRetracts = ko.observable(true); + self.renderer_showBoundingBox = ko.observable(false); + self.renderer_showFullSize = ko.observable(false); self.renderer_extrusionWidthEnabled = ko.observable(false); self.renderer_extrusionWidth = ko.observable(2); self.renderer_showNext = ko.observable(false); @@ -65,6 +67,8 @@ $(function() { centerViewport: self.renderer_centerViewport(), showMoves: self.renderer_showMoves(), showRetracts: self.renderer_showRetracts(), + showBoundingBox: self.renderer_showBoundingBox(), + showFullSize: self.renderer_showFullSize(), extrusionWidth: self.renderer_extrusionWidthEnabled() ? self.renderer_extrusionWidth() : 1, showNextLayer: self.renderer_showNext(), showPreviousLayer: self.renderer_showPrevious(), @@ -77,7 +81,8 @@ $(function() { var reader = { sortLayers: self.reader_sortLayers(), - purgeEmptyLayers: self.reader_hideEmptyLayers() + purgeEmptyLayers: self.reader_hideEmptyLayers(), + ignoreOutsideBed: true }; if (additionalReaderOptions) { _.extend(reader, additionalReaderOptions); @@ -95,6 +100,8 @@ $(function() { self.renderer_zoomOnModel.subscribe(self.synchronizeOptions); self.renderer_showMoves.subscribe(self.synchronizeOptions); self.renderer_showRetracts.subscribe(self.synchronizeOptions); + self.renderer_showBoundingBox.subscribe(self.synchronizeOptions); + self.renderer_showFullSize.subscribe(self.synchronizeOptions); self.renderer_extrusionWidthEnabled.subscribe(self.synchronizeOptions); self.renderer_extrusionWidth.subscribe(self.synchronizeOptions); self.renderer_showNext.subscribe(self.synchronizeOptions); @@ -120,10 +127,13 @@ $(function() { } var bedDimensions = self._retrieveBedDimensions(currentProfileData); - if (toolOffsets) { + if (bedDimensions) { GCODE.ui.updateOptions({ renderer: { bed: bedDimensions + }, + reader: { + bed: bedDimensions } }); } @@ -138,6 +148,14 @@ $(function() { } }); + self.settings.feature_g90InfluencesExtruder.subscribe(function() { + GCODE.ui.updateOptions({ + reader: { + g90InfluencesExtruder: self.settings.feature_g90InfluencesExtruder() + } + }); + }); + self._retrieveBedDimensions = function(currentProfileData) { if (currentProfileData == undefined) { currentProfileData = self.settings.printerProfiles.currentProfileData(); @@ -328,6 +346,7 @@ $(function() { result: response } }; + GCODE.renderer.clear(); GCODE.gCodeReader.loadFile(par); if (self.layerSlider != undefined) { @@ -398,7 +417,7 @@ $(function() { self.selectedFile.date(data.job.file.date); self.selectedFile.size(data.job.file.size); - if (data.job.file.size > CONFIG_GCODE_SIZE_THRESHOLD || ($.browser.mobile && data.job.file.size > CONFIG_GCODE_MOBILE_SIZE_THRESHOLD)) { + if (data.job.file.size > CONFIG_GCODE_SIZE_THRESHOLD || (OctoPrint.coreui.browser.mobile && data.job.file.size > CONFIG_GCODE_MOBILE_SIZE_THRESHOLD)) { self.waitForApproval(true); self.loadedFilepath = undefined; self.loadedFileDate = undefined; diff --git a/src/octoprint/static/js/app/viewmodels/printerprofiles.js b/src/octoprint/static/js/app/viewmodels/printerprofiles.js index 717d10038..368f80ce1 100644 --- a/src/octoprint/static/js/app/viewmodels/printerprofiles.js +++ b/src/octoprint/static/js/app/viewmodels/printerprofiles.js @@ -453,7 +453,7 @@ $(function() { }; self.requestData = function() { - OctoPrint.printerprofiles.list() + return OctoPrint.printerprofiles.list() .done(self.fromResponse); }; @@ -476,8 +476,16 @@ $(function() { }); self.profiles.updateItems(items); self.defaultProfile(defaultProfile); - self.currentProfile(currentProfile); - self.currentProfileData(currentProfileData); + + if (currentProfile && currentProfileData) { + self.currentProfile(currentProfile); + self.currentProfileData(currentProfileData); + } else { + // shouldn't normally happen, but just to not have anything else crash... + log.warn("Current printer profile could not be detected, using default values"); + self.currentProfile(""); + self.currentProfileData(ko.mapping.fromJS(cleanProfile(), self.currentProfileData)); + } }; self.addProfile = function(callback) { @@ -504,7 +512,10 @@ $(function() { self.requestInProgress(true); OctoPrint.printerprofiles.delete(data.id, {url: data.resource}) .done(function() { - self.requestData(); + self.requestData() + .always(function() { + self.requestInProgress(false); + }); }) .fail(function(xhr) { var text; @@ -514,8 +525,6 @@ $(function() { text = gettext("There was unexpected error while removing the printer profile, please consult the logs."); } new PNotify({title: gettext("Could not delete profile"), text: text, type: "error", hide: false}); - }) - .always(function() { self.requestInProgress(false); }); }; @@ -535,13 +544,14 @@ $(function() { if (callback !== undefined) { callback(); } - self.requestData(); + self.requestData() + .always(function() { + self.requestInProgress(false); + }); }) .fail(function() { var text = gettext("There was unexpected error while updating the printer profile, please consult the logs."); new PNotify({title: gettext("Could not update profile"), text: text, type: "error", hide: false}); - }) - .always(function() { self.requestInProgress(false); }); }; diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index 785abf971..e481f38df 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -91,6 +91,8 @@ $(function() { } }; + self.webcam_available_ratios = ["16:9", "4:3"]; + var auto_locale = {language: "_default", display: gettext("Autodetect from browser"), english: undefined}; self.locales = ko.observableArray([auto_locale].concat(_.sortBy(_.values(AVAILABLE_LOCALES), function(n) { return n.display; @@ -110,6 +112,8 @@ $(function() { self.printer_defaultExtrusionLength = ko.observable(undefined); self.webcam_streamUrl = ko.observable(undefined); + self.webcam_streamRatio = ko.observable(undefined); + self.webcam_streamTimeout = ko.observable(undefined); self.webcam_snapshotUrl = ko.observable(undefined); self.webcam_ffmpegPath = ko.observable(undefined); self.webcam_bitrate = ko.observable(undefined); @@ -140,6 +144,7 @@ $(function() { self.feature_firmwareDetection = ko.observable(undefined); self.feature_printCancelConfirmation = ko.observable(undefined); self.feature_blockWhileDwelling = ko.observable(undefined); + self.feature_g90InfluencesExtruder = ko.observable(undefined); self.serial_port = ko.observable(); self.serial_baudrate = ko.observable(); @@ -151,6 +156,7 @@ $(function() { self.serial_timeoutCommunication = ko.observable(undefined); self.serial_timeoutTemperature = ko.observable(undefined); self.serial_timeoutTemperatureTargetSet = ko.observable(undefined); + self.serial_timeoutTemperatureAutoreport = ko.observable(undefined); self.serial_timeoutSdStatus = ko.observable(undefined); self.serial_log = ko.observable(undefined); self.serial_additionalPorts = ko.observable(undefined); @@ -224,37 +230,48 @@ $(function() { self.terminalFilters.remove(filter); }; + self.testWebcamStreamUrlBusy = ko.observable(false); self.testWebcamStreamUrl = function() { if (!self.webcam_streamUrl()) { return; } + if (self.testWebcamStreamUrlBusy()) { + return; + } + var text = gettext("If you see your webcam stream below, the entered stream URL is ok."); var image = $(''); var message = $("

") .append(text) .append(image); + + self.testWebcamStreamUrlBusy(true); showMessageDialog({ title: gettext("Stream test"), - message: message + message: message, + onclose: function() { + self.testWebcamStreamUrlBusy(false); + } }); }; + self.testWebcamSnapshotUrlBusy = ko.observable(false); self.testWebcamSnapshotUrl = function(viewModel, event) { if (!self.webcam_snapshotUrl()) { return; } - var target = $(event.target); - target.prepend(' '); + if (self.testWebcamSnapshotUrlBusy()) { + return; + } var errorText = gettext("Could not retrieve snapshot URL, please double check the URL"); var errorTitle = gettext("Snapshot test failed"); + self.testWebcamSnapshotUrlBusy(true); OctoPrint.util.testUrl(self.webcam_snapshotUrl(), {method: "GET", response: "bytes"}) .done(function(response) { - $("i.icon-spinner", target).remove(); - if (!response.result) { showMessageDialog({ title: errorTitle, @@ -274,23 +291,34 @@ $(function() { var text = gettext("If you see your webcam snapshot picture below, the entered snapshot URL is ok."); showMessageDialog({ title: gettext("Snapshot test"), - message: $('

' + text + '

') + message: $('

' + text + '

'), + onclose: function() { + self.testWebcamSnapshotUrlBusy(false); + } }); }) .fail(function() { - $("i.icon-spinner", target).remove(); showMessageDialog({ title: errorTitle, - message: errorText + message: errorText, + onclose: function() { + self.testWebcamSnapshotUrlBusy(false); + } }); }); }; + self.testWebcamFfmpegPathBusy = ko.observable(false); self.testWebcamFfmpegPath = function() { if (!self.webcam_ffmpegPath()) { return; } + if (self.testWebcamFfmpegPathBusy()) { + return; + } + + self.testWebcamFfmpegPathBusy(true); OctoPrint.util.testExecutable(self.webcam_ffmpegPath()) .done(function(response) { if (!response.result) { @@ -306,6 +334,9 @@ $(function() { } self.webcam_ffmpegPathOk(response.result); self.webcam_ffmpegPathBroken(!response.result); + }) + .always(function() { + self.testWebcamFfmpegPathBusy(false); }); }; diff --git a/src/octoprint/static/js/app/viewmodels/terminal.js b/src/octoprint/static/js/app/viewmodels/terminal.js index baa58678b..4fdd47e7a 100644 --- a/src/octoprint/static/js/app/viewmodels/terminal.js +++ b/src/octoprint/static/js/app/viewmodels/terminal.js @@ -35,8 +35,10 @@ $(function() { self.enableFancyFunctionality = ko.observable(true); self.disableTerminalLogDuringPrinting = ko.observable(false); - self.acceptableTime = 500; + + self.acceptableFancyTime = 500; self.acceptableUnfancyTime = 300; + self.reenableTimeout = 5000; self.forceFancyFunctionality = ko.observable(false); self.forceTerminalLogDuringPrinting = ko.observable(false); @@ -122,23 +124,63 @@ $(function() { self.updateFilterRegex(); }); + self._reenableFancyTimer = undefined; + self._reenableUnfancyTimer = undefined; + self._disableFancy = function(difference) { + log.warn("Terminal: Detected slow client (needed " + difference + "ms for processing new log data), disabling fancy terminal functionality"); + if (self._reenableFancyTimer) { + window.clearTimeout(self._reenableFancyTimer); + self._reenableFancyTimer = undefined; + } + self.enableFancyFunctionality(false); + }; + self._reenableFancy = function(difference) { + if (self._reenableFancyTimer) return; + self._reenableFancyTimer = window.setTimeout(function() { + log.info("Terminal: Client speed recovered, enabling fancy terminal functionality"); + self.enableFancyFunctionality(true); + }, self.reenableTimeout); + }; + self._disableUnfancy = function(difference) { + log.warn("Terminal: Detected very slow client (needed " + difference + "ms for processing new log data), completely disabling terminal output during printing"); + if (self._reenableUnfancyTimer) { + window.clearTimeout(self._reenableUnfancyTimer); + self._reenableUnfancyTimer = undefined; + } + self.disableTerminalLogDuringPrinting(true); + }; + self._reenableUnfancy = function() { + if (self._reenableUnfancyTimer) return; + self._reenableUnfancyTimer = window.setTimeout(function() { + log.info("Terminal: Client speed recovered, enabling terminal output during printing"); + self.disableTerminalLogDuringPrinting(false); + }, self.reenableTimeout); + }; + self.fromCurrentData = function(data) { self._processStateData(data.state); var start = new Date().getTime(); self._processCurrentLogData(data.logs); var end = new Date().getTime(); - var difference = end - start; + if (self.enableFancyFunctionality()) { - if (difference > self.acceptableTime) { - self.enableFancyFunctionality(false); - log.warn("Terminal: Detected slow client (needed " + difference + "ms for processing new log data), disabling fancy terminal functionality"); + // fancy enabled -> check if we need to disable fancy + if (difference >= self.acceptableFancyTime) { + self._disableFancy(difference); + } + } else if (!self.disableTerminalLogDuringPrinting()) { + // fancy disabled, unfancy not -> check if we need to disable unfancy or re-enable fancy + if (difference >= self.acceptableUnfancyTime) { + self._disableUnfancy(difference); + } else if (difference < self.acceptableFancyTime / 2.0) { + self._reenableFancy(difference); } } else { - if (!self.disableTerminalLogDuringPrinting() && difference > self.acceptableUnfancyTime) { - self.disableTerminalLogDuringPrinting(true); - log.warn("Terminal: Detected very slow client (needed " + difference + "ms for processing new log data), completely disabling terminal output during printing"); + // fancy & unfancy disabled -> check if we need to re-enable unfancy + if (difference < self.acceptableUnfancyTime / 2.0) { + self._reenableUnfancy(difference); } } }; diff --git a/src/octoprint/static/js/app/viewmodels/timelapse.js b/src/octoprint/static/js/app/viewmodels/timelapse.js index f6a96c682..d8dae3755 100644 --- a/src/octoprint/static/js/app/viewmodels/timelapse.js +++ b/src/octoprint/static/js/app/viewmodels/timelapse.js @@ -10,7 +10,7 @@ $(function() { self.defaultPostRoll = 0; self.defaultInterval = 10; self.defaultRetractionZHop = 0; - self.defaultCapturePostroll = true; + self.defaultCapturePostRoll = true; self.timelapseType = ko.observable(undefined); self.timelapseTimedInterval = ko.observable(self.defaultInterval); @@ -48,7 +48,7 @@ $(function() { return ("timed" == self.timelapseType()); }); self.saveButtonEnabled = ko.pureComputed(function() { - return self.isDirty() && self.isOperational() && !self.isPrinting() && self.loginState.isUser(); + return self.isDirty() && !self.isPrinting() && self.loginState.isUser(); }); self.isOperational.subscribe(function() { @@ -159,18 +159,20 @@ $(function() { // timelapse config self.timelapseType(config.type); - if (config.type == "timed") { - if (config.interval != undefined && config.interval > 0) { - self.timelapseTimedInterval(config.interval); - } + if (config.type == "timed" && config.interval != undefined && config.interval > 0) { + self.timelapseTimedInterval(config.interval); } else { self.timelapseTimedInterval(self.defaultInterval); } - if (config.type == "zchange") { - if (config.retractionZHop != undefined && config.retractionZHop > 0) { - self.timelapseRetractionZHop(config.retractionZHop); - } + if (config.type == "timed" && config.capturePostRoll != undefined){ + self.timelapseCapturePostRoll(config.capturePostRoll); + } else { + self.timelapseCapturePostRoll(self.defaultCapturePostRoll); + } + + if (config.type == "zchange" && config.retractionZHop != undefined && config.retractionZHop > 0) { + self.timelapseRetractionZHop(config.retractionZHop); } else { self.timelapseRetractionZHop(self.defaultRetractionZHop); } @@ -187,12 +189,6 @@ $(function() { self.timelapseFps(self.defaultFps); } - if (config.capturePostRoll != undefined){ - self.timelapseCapturePostRoll(config.capturePostRoll); - } else { - self.timelapseCapturePostRoll(self.defaultCapturePostRoll); - } - self.persist(false); self.isDirty(false); }; diff --git a/src/octoprint/static/js/lib/sockjs.js b/src/octoprint/static/js/lib/sockjs.js index 0df18ae41..f168d5f7b 100644 --- a/src/octoprint/static/js/lib/sockjs.js +++ b/src/octoprint/static/js/lib/sockjs.js @@ -1,5 +1,5 @@ -/* sockjs-client v1.1.1 | http://sockjs.org | MIT license */ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.SockJS=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= v31? // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages - (navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31); + (typeof navigator !== 'undefined' && navigator && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) || + // double check webkit in userAgent just in case we are in a worker + (typeof navigator !== 'undefined' && navigator && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)); } /** @@ -3800,7 +3792,11 @@ function useColors() { */ exports.formatters.j = function(v) { - return JSON.stringify(v); + try { + return JSON.stringify(v); + } catch (err) { + return '[UnexpectedJSONParseError]: ' + err.message; + } }; @@ -3810,8 +3806,7 @@ exports.formatters.j = function(v) { * @api public */ -function formatArgs() { - var args = arguments; +function formatArgs(args) { var useColors = this.useColors; args[0] = (useColors ? '%c' : '') @@ -3821,17 +3816,17 @@ function formatArgs() { + (useColors ? '%c ' : ' ') + '+' + exports.humanize(this.diff); - if (!useColors) return args; + if (!useColors) return; var c = 'color: ' + this.color; - args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1)); + args.splice(1, 0, c, 'color: inherit') // the final "%c" is somewhat tricky, because there could be other // arguments passed either before or after the %c, so we need to // figure out the correct index to insert the CSS into var index = 0; var lastC = 0; - args[0].replace(/%[a-z%]/g, function(match) { + args[0].replace(/%[a-zA-Z%]/g, function(match) { if ('%%' === match) return; index++; if ('%c' === match) { @@ -3842,7 +3837,6 @@ function formatArgs() { }); args.splice(lastC, 0, c); - return args; } /** @@ -3885,11 +3879,14 @@ function save(namespaces) { */ function load() { - var r; try { - r = exports.storage.debug; + return exports.storage.debug; } catch(e) {} - return r; + + // If debug isn't set in LS, and we're in Electron, try to load $DEBUG + if (typeof process !== 'undefined' && 'env' in process) { + return process.env.DEBUG; + } } /** @@ -3909,12 +3906,14 @@ exports.enable(load()); * @api private */ -function localstorage(){ +function localstorage() { try { return window.localStorage; } catch (e) {} } +}).call(this,{ env: {} }) + },{"./debug":55}],55:[function(require,module,exports){ /** @@ -3924,7 +3923,7 @@ function localstorage(){ * Expose `debug()` as the module. */ -exports = module.exports = debug; +exports = module.exports = createDebug.debug = createDebug.default = createDebug; exports.coerce = coerce; exports.disable = disable; exports.enable = enable; @@ -3941,17 +3940,11 @@ exports.skips = []; /** * Map of special "%n" handling functions, for the debug "format" argument. * - * Valid key names are a single, lowercased letter, i.e. "n". + * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". */ exports.formatters = {}; -/** - * Previously assigned color. - */ - -var prevColor = 0; - /** * Previous log timestamp. */ @@ -3960,13 +3953,20 @@ var prevTime; /** * Select a color. - * + * @param {String} namespace * @return {Number} * @api private */ -function selectColor() { - return exports.colors[prevColor++ % exports.colors.length]; +function selectColor(namespace) { + var hash = 0, i; + + for (i in namespace) { + hash = ((hash << 5) - hash) + namespace.charCodeAt(i); + hash |= 0; // Convert to 32bit integer + } + + return exports.colors[Math.abs(hash) % exports.colors.length]; } /** @@ -3977,17 +3977,13 @@ function selectColor() { * @api public */ -function debug(namespace) { +function createDebug(namespace) { - // define the `disabled` version - function disabled() { - } - disabled.enabled = false; + function debug() { + // disabled? + if (!debug.enabled) return; - // define the `enabled` version - function enabled() { - - var self = enabled; + var self = debug; // set `diff` timestamp var curr = +new Date(); @@ -3997,22 +3993,22 @@ function debug(namespace) { self.curr = curr; prevTime = curr; - // add the `color` if not set - if (null == self.useColors) self.useColors = exports.useColors(); - if (null == self.color && self.useColors) self.color = selectColor(); - - var args = Array.prototype.slice.call(arguments); + // turn the `arguments` into a proper Array + var args = new Array(arguments.length); + for (var i = 0; i < args.length; i++) { + args[i] = arguments[i]; + } args[0] = exports.coerce(args[0]); if ('string' !== typeof args[0]) { - // anything else let's inspect with %o - args = ['%o'].concat(args); + // anything else let's inspect with %O + args.unshift('%O'); } // apply any `formatters` transformations var index = 0; - args[0] = args[0].replace(/%([a-z%])/g, function(match, format) { + args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) { // if we encounter an escaped % then don't increase the array index if (match === '%%') return match; index++; @@ -4028,19 +4024,24 @@ function debug(namespace) { return match; }); - if ('function' === typeof exports.formatArgs) { - args = exports.formatArgs.apply(self, args); - } - var logFn = enabled.log || exports.log || console.log.bind(console); + // apply env-specific formatting (colors, etc.) + exports.formatArgs.call(self, args); + + var logFn = debug.log || exports.log || console.log.bind(console); logFn.apply(self, args); } - enabled.enabled = true; - var fn = exports.enabled(namespace) ? enabled : disabled; + debug.namespace = namespace; + debug.enabled = exports.enabled(namespace); + debug.useColors = exports.useColors(); + debug.color = selectColor(namespace); - fn.namespace = namespace; + // env-specific initialization logic for debug instances + if ('function' === typeof exports.init) { + exports.init(debug); + } - return fn; + return debug; } /** @@ -4114,134 +4115,7 @@ function coerce(val) { return val; } -},{"ms":56}],56:[function(require,module,exports){ -/** - * Helpers. - */ - -var s = 1000; -var m = s * 60; -var h = m * 60; -var d = h * 24; -var y = d * 365.25; - -/** - * Parse or format the given `val`. - * - * Options: - * - * - `long` verbose formatting [false] - * - * @param {String|Number} val - * @param {Object} options - * @return {String|Number} - * @api public - */ - -module.exports = function(val, options){ - options = options || {}; - if ('string' == typeof val) return parse(val); - return options.long - ? long(val) - : short(val); -}; - -/** - * Parse the given `str` and return milliseconds. - * - * @param {String} str - * @return {Number} - * @api private - */ - -function parse(str) { - str = '' + str; - if (str.length > 10000) return; - var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str); - if (!match) return; - var n = parseFloat(match[1]); - var type = (match[2] || 'ms').toLowerCase(); - switch (type) { - case 'years': - case 'year': - case 'yrs': - case 'yr': - case 'y': - return n * y; - case 'days': - case 'day': - case 'd': - return n * d; - case 'hours': - case 'hour': - case 'hrs': - case 'hr': - case 'h': - return n * h; - case 'minutes': - case 'minute': - case 'mins': - case 'min': - case 'm': - return n * m; - case 'seconds': - case 'second': - case 'secs': - case 'sec': - case 's': - return n * s; - case 'milliseconds': - case 'millisecond': - case 'msecs': - case 'msec': - case 'ms': - return n; - } -} - -/** - * Short format for `ms`. - * - * @param {Number} ms - * @return {String} - * @api private - */ - -function short(ms) { - if (ms >= d) return Math.round(ms / d) + 'd'; - if (ms >= h) return Math.round(ms / h) + 'h'; - if (ms >= m) return Math.round(ms / m) + 'm'; - if (ms >= s) return Math.round(ms / s) + 's'; - return ms + 'ms'; -} - -/** - * Long format for `ms`. - * - * @param {Number} ms - * @return {String} - * @api private - */ - -function long(ms) { - return plural(ms, d, 'day') - || plural(ms, h, 'hour') - || plural(ms, m, 'minute') - || plural(ms, s, 'second') - || ms + ' ms'; -} - -/** - * Pluralization helper. - */ - -function plural(ms, n, name) { - if (ms < n) return; - if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name; - return Math.ceil(ms / n) + ' ' + name + 's'; -} - -},{}],57:[function(require,module,exports){ +},{"ms":58}],56:[function(require,module,exports){ if (typeof Object.create === 'function') { // implementation from standard node.js 'util' module module.exports = function inherits(ctor, superCtor) { @@ -4266,7 +4140,7 @@ if (typeof Object.create === 'function') { } } -},{}],58:[function(require,module,exports){ +},{}],57:[function(require,module,exports){ (function (global){ /*! JSON v3.3.2 | http://bestiejs.github.io/json3 | Copyright 2012-2014, Kit Cambridge | http://kit.mit-license.org */ ;(function () { @@ -5172,18 +5046,271 @@ if (typeof Object.create === 'function') { }).call(this); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9qc29uMy9saWIvanNvbjMuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQ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gb3IgYG51bGxgIGxpdGVyYWwuIFRoaXMgYXBwbGllcyB0b1xuICAgICAgICAgICAgICAgIC8vIG9iamVjdHMgd2l0aCBjdXN0b20gYHRvSlNPTmAgbWV0aG9kcyBhcyB3ZWxsLCB1bmxlc3MgdGhleSBhcmUgbmVzdGVkXG4gICAgICAgICAgICAgICAgLy8gaW5zaWRlIG9iamVjdCBvciBhcnJheSBsaXRlcmFscy4gWVVJIDMuMC4wYjEgaWdub3JlcyBjdXN0b20gYHRvSlNPTmBcbiAgICAgICAgICAgICAgICAvLyBtZXRob2RzIGVudGlyZWx5LlxuICAgICAgICAgICAgICAgIHN0cmluZ2lmeSh2YWx1ZSkgPT09IFwiMVwiICYmXG4gICAgICAgICAgICAgICAgc3RyaW5naWZ5KFt2YWx1ZV0pID09IFwiWzFdXCIgJiZcbiAgICAgICAgICAgICAgICAvLyBQcm90b3R5cGUgPD0gMS42LjEgc2VyaWFsaXplcyBgW3VuZGVmaW5lZF1gIGFzIGBcIltdXCJgIGluc3RlYWQgb2ZcbiAgICAgICAgICAgICAgICAvLyBgXCJbbnVsbF1cImAuXG4gICAgICAgICAgICAgICAgc3RyaW5naWZ5KFt1bmRlZl0pID09IFwiW251bGxdXCIgJiZcbiAgICAgICAgICAgICAgICAvLyBZVUkgMy4wLjBiMSBmYWlscyB0byBzZXJpYWxpemUgYG51bGxgIGxpdGVyYWxzLlxuICAgICAgICAgICAgICAgIHN0cmluZ2lmeShudWxsKSA9PSBcIm51bGxcIiAmJlxuICAgICAgICAgICAgICAgIC8vIEZGIDMuMWIxLCAyIGhhbHRzIHNlcmlhbGl6YXRpb24gaWYgYW4gYXJyYXkgY29udGFpbnMgYSBmdW5jdGlvbjpcbiAgICAgICAgICAgICAgICAvLyBgWzEsIHRydWUsIGdldENsYXNzLCAxXWAgc2VyaWFsaXplcyBhcyBcIlsxLHRydWUsXSxcIi4gRkYgMy4xYjNcbiAgICAgICAgICAgICAgICAvLyBlbGlkZXMgbm9uLUpTT04gdmF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ZWQgPSAhcGFyc2UoJ1wiXFx0XCInKTtcbiAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge31cbiAgICAgICAgICAgICAgICAgIGlmIChwYXJzZVN1cHBvcnRlZCkge1xuICAgICAgICAgICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgICAgICAgIC8vIEZGIDQuMCBhbmQgNC4wLjEgYWxsb3cgbGVhZGluZyBgK2Agc2lnbnMgYW5kIGxlYWRpbmdcbiAgICAgICAgICAgICAgICAgICAgICAvLyBkZWNpbWFsIHBvaW50cy4gRkYgNC4wLCA0LjAuMSwgYW5kIElFIDktMTAgYWxzbyBhbGxvd1xuICAgICAgICAgICAgICAgICAgICAgIC8vIGNlcnRhaW4gb2N0YWwgbGl0ZXJhbHMuXG4gICAgICAgICAgICAgICAgICAgICAgcGFyc2VTdXBwb3J0ZWQgPSBwYXJzZShcIjAxXCIpICE9PSAxO1xuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHt9XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICBpZiAocGFyc2VTdXBwb3J0ZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgICAvLyBGRiA0LjAsIDQuMC4xLCBhbmQgUmhpbm8gMS43UjMtUjQgYWxsb3cgdHJhaWxpbmcgZGVjaW1hbFxuICAgICAgICAgICAgICAgICAgICAgIC8vIHBvaW50cy4gVGhlc2UgZW52aXJvbm1lbnRzLCBhbG9uZyB3aXRoIEZGIDMuMWIxIGFuZCAyLFxuICAgICAgICAgICAgICAgICAgICAgIC8vIGFsc28gYWxsb3cgdHJhaWxpbmcgY29tbWFzIGluIEpTT04gb2JqZWN0cyBhbmQgYXJyYXlzLlxuICAgICAgICAgICAgICAgICAgICAgIHBhcnNlU3VwcG9ydGVkID0gcGFyc2UoXCIxLlwiKSAhPT0gMTtcbiAgICAgICAgICAgICA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Db21waWxlci5cbiAgICAgICAgICAgICAgdmFyIG9yaWdpbmFsID0gdGhpcy5fX3Byb3RvX18sIHJlc3VsdCA9IHByb3BlcnR5IGluICh0aGlzLl9fcHJvdG9fXyA9IG51bGwsIHRoaXMpO1xuICAgICAgICAgICAgICAvLyBSZXN0b3JlIHRoZSBvcmlnaW5hbCBwcm90b3R5cGUgY2hhaW4uXG4gICAgICAgICAgICAgIHRoaXMuX19wcm90b19fID0gb3JpZ2luYWw7XG4gICAgICAgICAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgICAgICAgICB9O1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAvLyBDYXB0dXJlIGEgcmVmZXJlbmNlIHRvIHRoZSB0b3AtbGV2ZWwgYE9iamVjdGAgY29uc3RydWN0b3IuXG4gICAgICAgICAgICBjb25zdHJ1Y3RvciA9IG1lbWJlcnMuY29uc3RydWN0b3I7XG4gICAgICAgICAgICAvLyBVc2UgdGhlIGBjb25zdHJ1Y3RvcmAgcHJvcGVydHkgdG8gc2ltdWxhdGUgYE9iamVjdCNoYXNPd25Qcm9wZXJ0eWAgaW5cbiAgICAgICAgICAgIC8vIG90aGVyIGVudmlyb25tZW50cy5cbiAgICAgICAgICAgIGlzUHJvcGVydHkgPSBmdW5jdGlvbiAocHJvcGVydHkpIHtcbiAgICAgICAgICAgICAgdmFyIHBhcmVudCA9ICh0aGlzLmNvbnN0cnVjdG9yIHx8IGNvbnN0cnVjdG9yKS5wcm90b3R5cGU7XG4gICAgICAgICAgICAgIHJldHVybiBwcm9wZXJ0eSBpbiB0aGlzICYmICEocHJvcGVydHkgaW4gcGFyZW50ICYmIHRoaXNbcHJvcGVydHldID09PSBwYXJlbnRbcHJvcGVydHldKTtcbiAgICAgICAgICAgIH07XG4gICAgICAgICAgfVxuICAgICAgICAgIG1lbWJlcnMgPSBudWxsO1xuICAgICAgICAgIHJldHVybiBpc1Byb3BlcnR5LmNhbGwodGhpcywgcHJvcGVydHkpO1xuIC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gJiYgb2JqZWN0Lmhhc093blByb3BlcnR5IHx8IGlzUHJvcGVydHk7XG4gICAgICAgICAgICBmb3IgKHByb3BlcnR5IGluIG9iamVjdCkge1xuICAgICAgICAgICAgICAvLyBHZWNrbyA8PSAxLjAgZW51bWVyYXRlcyB0aGUgYHByb3RvdHlwZWAgcHJvcGVydHkgb2YgZnVuY3Rpb25zIHVuZGVyXG4gICAgICAgICAgICAgIC8vIGNlcnRhaW4gY29uZGl0aW9uczsgSUUgZG9lcyBub3QuXG4gICAgICAgICAgICAgIGlmICghKGlzRnVuY3Rpb24gJiYgcHJvcGVydHkgPT0gXCJwcm90b3R5cGVcIikgJiYgaGFzUHJvcGVydHkuY2FsbChvYmplY3QsIHByb3BlcnR5KSkge1xuICAgICAgICAgICAgICAgIGNhbGxiYWNrKHByb3BlcnR5KTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgLy8gTWFudWFsbHkgaW52b2tlIHRoZSBjYWxsYmFjayBmb3IgZWFjaCBub24tZW51bWVyYWJsZSBwcm9wZXJ0eS5cbiAgICAgICAgICAgIGZvciAobGVuZ3RoID0gbWVtYmVycy5sZW5ndGg7IHByb3BlcnR5ID0gbWVtYmVyc1stLWxlbmd0aF07IGhhc1Byb3BlcnR5LmNhbGwob2JqZWN0LCBwcm9wZXJ0eSkgJiYgY2FsbGJhY2socHJvcGVydHkpKTtcbiAgICAgICAgICB9O1xuICAgICAgICB9IGVsc2UgaWYgKHNpemUgPT0gMikge1xuICAgICAgICAgIC8vIFNhZmFyaSA8PSAyLjAuNCBlbnVtZXJhdGVzIHNoYWRvd2VkIHByb3BlcnRpZXMgdHdpY2UuXG4gICAgICAgICAgZm9yRWFjaCA9IGZ1bmN0aW9uIChvYmplY3QsIGNhbGxiYWNrKSB7XG4gICAgICAgICAgICAvLyBDcmVhdGUgYSBzZXQgb2YgaXRlcmF0ZWQgcHJvcGVydGllcy5cbiAgICAgICAgICAgIHZhciBtZW1iZXJzID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gICAgICAgICB2YXIgY2hhckNvZGUgPSB2YWx1ZS5jaGFyQ29kZUF0KGluZGV4KTtcbiAgICAgICAgICAgIC8vIElmIHRoZSBjaGFyYWN0ZXIgaXMgYSBjb250cm9sIGNoYXJhY3RlciwgYXBwZW5kIGl0cyBVbmljb2RlIG9yXG4gICAgICAgICAgICAvLyBzaG9ydGhhbmQgZXNjYXBlIHNlcXVlbmNlOyBvdGhlcndpc2UsIGFwcGVuZCB0aGUgY2hhcmFjdGVyIGFzLWlzLlxuICAgICAgICAgICAgc3dpdGNoIChjaGFyQ29kZSkge1xuICAgICAgICAgICAgICBjYXNlIDg6IGNhc2UgOTogY2FzZSAxMDogY2FzZSAxMjogY2FzZSAxMzogY2FzZSAzNDogY2FzZSA5MjpcbiAgICAgICAgICAgICAgICByZXN1bHQgKz0gRXNjYXBlc1tjaGFyQ29kZV07XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgICAgICAgaWYgKGNoYXJDb2RlIDwgMzIpIHtcbiAgICAgICAgICAgICAgICAgIHJlc3VsdCArPSB1bmljb2RlUHJlZml4ICsgdG9QYWRkZWRTdHJpbmcoMiwgY2hhckNvZGUudG9TdHJpbmcoMTYpKTtcbiAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXN1bHQgKz0gdXNlQ2hhckluZGV4ID8gc3ltYm9sc1tpbmRleF0gOiB2YWx1ZS5jaGFyQXQoaW5kZXgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICByZXR1cm4gcmVzdWx0ICsgJ1wiJztcbiAgICAgICAgfTtcblxuICAgICAgICAvLyBJbnRlcm5hbDogUmVjdXJzaXZlbHkgc2VyaWFsaXplcyBhbiBvYmplY3QuIEltcGxlbWVudHMgdGhlXG4gICAgICAgIC8vIGBTdHIoa2V5LCBob2xkZXIpYCwgYEpPKHZ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vLyB0byBjb21wdXRlIGBBIG1vZHVsbyBCYCwgYXMgdGhlIGAlYCBvcGVyYXRvciBkb2VzIG5vdFxuICAgICAgICAgICAgICAgICAgLy8gY29ycmVzcG9uZCB0byB0aGUgYG1vZHVsb2Agb3BlcmF0aW9uIGZvciBuZWdhdGl2ZSBudW1iZXJzLlxuICAgICAgICAgICAgICAgICAgdGltZSA9ICh2YWx1ZSAlIDg2NGU1ICsgODY0ZTUpICUgODY0ZTU7XG4gICAgICAgICAgICAgICAgICAvLyBUaGUgaG91cnMsIG1pbnV0ZXMsIHNlY29uZHMsIGFuZCBtaWxsaXNlY29uZHMgYXJlIG9idGFpbmVkIGJ5XG4gICAgICAgICAgICAgICAgICAvLyBkZWNvbXBvc2luZyB0aGUgdGltZSB3aXRoaW4gdGhlIGRheS4gU2VlIHNlY3Rpb24gMTUuOS4xLjEwLlxuICAgICAgICAgICAgICAgICAgaG91cnMgPSBmbG9vcih0aW1lIC8gMzZlNSkgJSAyNDtcbiAgICAgICAgICAgICAgICAgIG1pbnV0ZXMgPSBmbG9vcih0aW1lIC8gNmU0KSAlIDYwO1xuICAgICAgICAgICAgICAgICAgc2Vjb25kcyA9IGZsb29yKHRpbWUgLyAxZTMpICUgNjA7XG4gICAgICAgICAgICAgICAgICBtaWxsaXNlY29uZHMgPSB0aW1lICUgMWUzO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICB5ZWFyID0gdmFsdWUuZ2V0VVRDRnVsbFllYXIoKTtcbiAgICAgICAgICAgICAgICAgIG1vbnRoID0gdmFsdWUuZ2V0VVRDTW9udGgoKTtcbiAgICAgICAgICAgICAgICAgIGRhdGUgPSB2YWx1ZS5nZXRVVENEYXRlKCk7XG4gICAgICAgICAgICAgICAgICBob3VycyA9IHZhbHVlLmdldFVUQ0hvdXJzKCk7XG4gICAgICAgICAgICAgICAgICBtaW51dGVzID0gdmFsdWUuZ2V0VVRDTWludXRlcygpO1xuICAgICAgICAgICAg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gICAgICAgIC8vIHRoZSBjdXJyZW50IHBvc2l0aW9uLlxuICAgICAgICAgICAgICAgIHZhbHVlID0gY2hhckluZGV4QnVnZ3kgPyBzb3VyY2UuY2hhckF0KEluZGV4KSA6IHNvdXJjZVtJbmRleF07XG4gICAgICAgICAgICAgICAgSW5kZXgrKztcbiAgICAgICAgICAgICAgICByZXR1cm4gdmFsdWU7XG4gICAgICAgICAgICAgIGNhc2UgMzQ6XG4gICAgICAgICAgICAgICAgLy8gYFwiYCBkZWxpbWl0cyBhIEpTT04gc3RyaW5nOyBhZHZhbmNlIHRvIHRoZSBuZXh0IGNoYXJhY3RlciBhbmRcbiAgICAgICAgICAgICAgICAvLyBiZWdpbiBwYXJzaW5nIHRoZSBzdHJpbmcuIFN0cmluZyB0b2tlbnMgYXJlIHByZWZpeGVkIHdpdGggdGhlXG4gICAgICAgICAgICAgICAgLy8gc2VudGluZWwgYEBgIGNoYXJhY3RlciB0byBkaXN0aW5ndWlzaCB0aGVtIGZyb20gcHVuY3R1YXRvcnMgYW5kXG4gICAgICAgICAgICAgICAgLy8gZW5kLW9mLXN0cmluZyB0b2tlbnMuXG4gICAgICAgICAgICAgICAgZm9yICh2YWx1ZSA9IFwiQFwiLCBJbmRleCsrOyBJbmRleCA8IGxlbmd0aDspIHtcbiAgICAgICAgICAgICAgICAgIGNoYXJDb2RlID0gc291cmNlLmNoYXJDb2RlQXQoSW5kZXgpO1xuICAgICAgICAgICAgICAgICAgaWYgKGNoYXJDb2RlIDwgMzIpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gVW5lc2NhcGVkIEFTQ0lJIGNvbnRyb2wgY2hhcmFjdGVycyAodGhvc2Ugd2l0aCBhIGNvZGUgdW5pdFxuICAgICAgICAgICAgICAgICAgICAvLyBsZXNzIHRoYW4gdGhlIHNwYWNlIGNoYXJhY3RlcikgYXJlIG5vdCBwZXJtaXR0ZWQuXG4gICAgICAgICAgICAgICAgICAgIGFib3J0KCk7XG4gICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGNoYXJDb2RlID09IDkyKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIEEgcmV2ZXJzZSBzb2xpZHVzIChgXFxgKSBtYXJrcyB0aGUgYmVnaW5uaW5nIG9mIGFuIGVzY2FwZWRcbiAgICAgICAgICAgICAgICAgICAgLy8gY29udHJvbCBjaGFyYWN0ZXIgKGluY2x1ZGluZyBgXCJgLCBgXFxgLCBhbmQgYC9gKSBvciBVbmljb2RlXG4gICAgICAgICAgICAgICAgICAgIC8vIGVzY2FwZSBzZXF1ZW5jZS5cbiAgICAgICAgICAgICAgICAgICAgY2hhckNvZGUgPSBzb3VyY2UuY2hhckNvZGVBdCgrK0luZGV4KTtcbiAgICAgICAgICAgICAgICAgICAgc3dpdGNoIChjaGFyQ29kZSkge1xuICAgICAgICAgICAgICAgICAgICAgIGNhc2UgOTI6IGNhc2UgMzQ6IGNhc2UgNDc6IGNhc2UgOTg6IGNhc2UgMTE2OiBjYXNlIDExMDogY2FzZSAxMDI6IGNhc2UgMTE0OlxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gUmV2aXZlIGVzY2FwZWQgY29udHJvbCBjaGFyYWN0ZXJzLlxuICAgICAgICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gVW5lc2NhcGVzW2NoYXJDb2RlXTtcbiAgICAgICAgICAgICAgICAgICAgICAgIEluZGV4Kys7XG4gICAgICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICAgICAgICBjYXNlIDExNzpcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIGBcXHVgIG1hcmtzIHRoZSBiZWdpbm5pbmcgb2YgYSBVbmljb2RlIGVzY2FwZSBzZXF1ZW5jZS5cbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIEFkdmFuY2UgdG8gdGhlIGZpcnN0IGNoYXJhY3RlciBhbmQgdmFsaWRhdGUgdGhlXG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBmb3VyLWRpZ2l0IGNvZGUgcG9pbnQuXG4gICAgICAgICAgICAgICAgICAgICAgICBiZWdpbiA9ICsrSW5kZXg7XG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKHBvc2l0aW9uID0gSW5kZXggKyA0OyBJbmRleCA8IHBvc2l0aW9uOyBJbmRleCsrKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgIGNoYXJDb2RlID0gc291cmNlLmNoYXJDb2RlQXQoSW5kZXgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBBIHZhbGlkIHNlcXVlbmNlIGNvbXByaXNlcyBmb3VyIGhleGRpZ2l0cyAoY2FzZS1cbiAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gaW5zZW5zaXRpdmUpIHRoYXQgZm9ybSBhIHNpbmdsZSBoZXhhZGVjaW1hbCB2YWx1ZS5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCEoY2hhckNvZGUgPj0gNDggJiYgY2hhckNvZGUgPD0gNTcgfHwgY2hhckNvZGUgPj0gOTcgJiYgY2hhckNvZGUgPD0gMTAyIHx8IGNoYXJDb2RlID49IDY1ICYmIGNoYXJDb2RlIDw9IDcwKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIEludmFsaWQgVW5pY29kZSBlc2NhcGUgc2VxdWVuY2UuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgYWJvcnQoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gUmV2aXZlIHRoZSBlc2NhcGVkIGNoYXJhY3Rlci5cbiAgICAgICAgICAgICAgICAgICAgICAgIHZhbHVlICs9IGZyb21DaGFyQ29kZShcIjB4XCIgKyBzb3VyY2Uuc2xpY2UoYmVnaW4sIEluZGV4KSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gSW52YWxpZCBlc2NhcGUgc2VxdWVuY2UuXG4gICAgICAgICAgICAgICAgICAgICAgICBhYm9ydCgpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBpZiAoY2hhckNvZGUgPT0gMzQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAvLyBBbiB1bmVzY2FwZWQgZG91YmxlLXF1b3RlIGNoYXJhY3RlciBtYXJrcyB0aGUgZW5kIG9mIHRoZVxuICAgICAgICAgICAgICAgICAgICAgIC8vIHN0cmluZy5cbiAgICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBjaGFyQ29kZSA9IHNvdXJjZS5jaGFyQ29kZUF0KEluZGV4KTtcbiAgICAgICAgICAgICAgICAgICAgYmVnaW4gPSBJbmRleDtcbiAgICAgICAgICAgICAgICAgICAgLy8gT3B0aW1pemUgZm9yIHRoZSBjb21tb24gY2FzZSB3aGVyZSBhIHN0cmluZyBpcyB2YWxpZC5cbiAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGNoYXJDb2RlID49IDMyICYmIGNoYXJDb2RlICE9IDkyICYmIGNoYXJDb2RlICE9IDM0KSB7XG4gICAgICAgICAgICAgICAgICAgICAgY2hhckNvZGUgPSBzb3VyY2UuY2hhckNvZGVBdCgrK0luZGV4KTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAvLyBBcHBlbmQgdGhlIHN0cmluZyBhcy1pcy5cbiAgICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gc291cmNlLnNsaWNlKGJlZ2luLCBJbmRleCk7XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmIChzb3VyY2UuY2hhckNvZGVBdChJbmRleCkgPT0gMzQpIHtcbiAgICAgICAgICAgICAgICAgIC8vIEFkdmFuY2UgdG8gdGhlIG5leHQgY2hhcmFjdGVyIGFuZCByZXR1cm4gdGhlIHJldml2ZWQgc3RyaW5nLlxuICAgICAgICAgICAgICAgICAgSW5kZXgrKztcbiAgICAgICAgICAgICAgICAgIHJldHVybiB2YWx1ZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgLy8gVW50ZXJtaW5hdGVkIHN0cmluZy5cbiAgICAgICAgICAgICAgICBhYm9ydCgpO1xuICAgICAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgICAgIC8vIFBhcnNlIG51bWJlcnMgYW5kIGxpdGVyYWxzLlxuICAgICAgICAgICAgICAgIGJlZ2luID0gSW5kZXg7XG4gICAgICAgICAgICAgICAgLy8gQWR2YW5jZSBwYXN0IHRoZSBuZWdhdGl2ZSBzaWduLCBpZiBvbmUgaXMgc3BlY2lmaWVkLlxuICAgICAgICAgICAgICAgIGlmIChjaGFyQ29kZSA9PSA0NSkge1xuICAgICAgICAgICAgICAgICAgaXNTaWduZWQgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgY2hhckNvZGUgPSBzb3VyY2UuY2hhckNvZGVBdCgrK0luZGV4KTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgLy8gUGFyc2UgYW4gaW50ZWdlciBvciBmbG9hdGluZy1wb2ludCB2YWx1ZS5cbiAgICAgICAgICAgICAgICBpZiAoY2hhckNvZGUgPj0gNDggJiYgY2hhckNvZGUgPD0gNTcpIHtcbiAgICAgICAgICAgICAgICAgIC8vIExlYWRpbmcgemVyb2VzIGFyZSBpbnRlcnByZXRlZCBhcyBvY3RhbCBsaXRlcmFscy5cbiAgICAgICAgICAgICAgICAgIGlmIChjaGFyQ29kZSA9PSA0OCAmJiAoKGNoYXJDb2RlID0gc291cmNlLmNoYXJDb2RlQXQoSW5kZXggKyAxKSksIGNoYXJDb2RlID49IDQ4ICYmIGNoYXJDb2RlIDw9IDU3KSkge1xuICAgICAgICAgICAgICAgICAgICAvLyBJbGxlZ2FsIG9jdGFsIGxpdGVyYWwuXG4gICAgICAgICAgICAgICAgICAgIGFib3J0KCk7XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICBpc1NpZ25lZCA9IGZhbHNlO1xuICAgICAgICAgICAgICAgICAgLy8gUGFyc2UgdGhlIGludGVnZXIgY29tcG9uZW50LlxuICAgICAgICAgICAgICAgICAgZm9yICg7IEluZGV4IDwgbGVuZ3RoICYmICgoY2hhckNvZGUgPSBzb3VyY2UuY2hhckNvZGVBdChJbmRleCkpLCBjaGFyQ29kZSA+PSA0OCAmJiBjaGFyQ29kZSA8PSA1Nyk7IEluZGV4KyspO1xuICAgICAgICAgICAgICAgICAgLy8gRmxvYXRzIGNhbm5vdCBjb250YWluIGEgbGVhZGluZyBkZWNpbWFsIHBvaW50OyBob3dldmVyLCB0aGlzXG4gICAgICAgICAgICAgICAgICAvLyBjYXNlIGlzIGFscmVhZHkgYWNjb3VudGVkIGZvciBieSB0aGUgcGFyc2VyLlxuICAgICAgICAgICAgICAgICAgaWYgKHNvdXJjZS5jaGFyQ29kZUF0KEluZGV4KSA9PSA0Nikge1xuICAgICAgICAgICAgICAgICAgICBwb3NpdGlvbiA9ICsrSW5kZXg7XG4gICAgICAgICAgICAgICAgICAgIC8vIFBhcnNlIHRoZSBkZWNpbWFsIGNvbXBvbmVudC5cbiAgICAgICAgICAgICAgICAgICAgZm9yICg7IHBvc2l0aW9uIDwgbGVuZ3RoICYmICgoY2hhckNvZGUgPSBzb3VyY2UuY2hhckNvZGVBdChwb3NpdGlvbikpLCBjaGFyQ29kZSA+PSA0OCAmJiBjaGFyQ29kZSA8PSA1Nyk7IHBvc2l0aW9uKyspO1xuICAgICAgICAgICAgICAgICAgICBpZiAocG9zaXRpb24gPT0gSW5kZXgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAvLyBJbGxlZ2FsIHRyYWlsaW5nIGRlY2ltYWwuXG4gICAgICAgICAgICAgICAgICAgICAgYWJvcnQoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBJbmRleCA9IHBvc2l0aW9uO1xuICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgLy8gUGFyc2UgZXhwb25lbnRzLiBUaGUgYGVgIGRlbm90aW5nIHRoZSBleHBvbmVudCBpc1xuICAgICAgICAgICAgICAgICAgLy8gY2FzZS1pbnNlbnNpdGl2ZS5cbiAgICAgICAgICAgICAgICAgIGNoYXJDb2RlID0gc291cmNlLmNoYXJDb2RlQXQoSW5kZXgpO1xuICAgICAgICAgICAgICAgICAgaWYgKGNoYXJDb2RlID09IDEwMSB8fCBjaGFyQ29kZSA9PSA2OSkge1xuICAgICAgICAgICAgICAgICAgICBjaGFyQ29kZSA9IHNvdXJjZS5jaGFyQ29kZUF0KCsrSW5kZXgpO1xuICAgICAgICAgICAgICAgICAgICAvLyBTa2lwIHBhc3QgdGhlIHNpZ24gZm9sbG93aW5nIHRoZSBleHBvbmVudCwgaWYgb25lIGlzXG4gICAgICAgICAgICAgICAgICAgIC8vIHNwZWNpZmllZC5cbiAgICAgICAgICAgICAgICAgICAgaWYgKGNoYXJDb2RlID09IDQzIHx8IGNoYXJDb2RlID09IDQ1KSB7XG4gICAgICAgICAgICAgICAgICAgICAgSW5kZXgrKztcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAvLyBQYXJzZSB0aGUgZXhwb25lbnRpYWwgY29tcG9uZW50LlxuICAgICAgICAgICAgICAgICAgICBmb3IgKHBvc2l0aW9uID0gSW5kZXg7IHBvc2l0aW9uIDwgbGVuZ3RoICYmICgoY2hhckNvZGUgPSBzb3VyY2UuY2hhckNvZGVBdChwb3NpdGlvbikpLCBjaGFyQ29kZSA+PSA0OCAmJiBjaGFyQ29kZSA8PSA1Nyk7IHBvc2l0aW9uKyspO1xuICAgICAgICAgICAgICAgICAgICBpZiAocG9zaXRpb24gPT0gSW5kZXgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAvLyBJbGxlZ2FsIGVtcHR5IGV4cG9uZW50LlxuICAgICAgICAgICAgICAgICAgICAgIGFib3J0KCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgSW5kZXggPSBwb3NpdGlvbjtcbiAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgIC8vIENvZXJjZSB0aGUgcGFyc2VkIHZhbHVlIHRvIGEgSmF2YVNjcmlwdCBudW1iZXIuXG4gICAgICAgICAgICAgICAgICByZXR1cm4gK3NvdXJjZS5zbGljZShiZWdpbiwgSW5kZXgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAvLyBBIG5lZ2F0aXZlIHNpZ24gbWF5IG9ubHkgcHJlY2VkZSBudW1iZXJzLlxuICAgICAgICAgICAgICAgIGlmIChpc1NpZ25lZCkge1xuICAgICAgICAgICAgICAgICAgYWJvcnQoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgLy8gYHRydWVgLCBgZmFsc2VgLCBhbmQgYG51bGxgIGxpdGVyYWxzLlxuICAgICAgICAgICAgICAgIGlmIChzb3VyY2Uuc2xpY2UoSW5kZXgsIEluZGV4ICsgNCkgPT0gXCJ0cnVlXCIpIHtcbiAgICAgICAgICAgICAgICAgIEluZGV4ICs9IDQ7XG4gICAgICAgICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHNvdXJjZS5zbGljZShJbmRleCwgSW5kZXggKyA1KSA9PSBcImZhbHNlXCIpIHtcbiAgICAgICAgICAgICAgICAgIEluZGV4ICs9IDU7XG4gICAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzb3VyY2Uuc2xpY2UoSW5kZXgsIEluZGV4ICsgNCkgPT0gXCJudWxsXCIpIHtcbiAgICAgICAgICAgICAgICAgIEluZGV4ICs9IDQ7XG4gICAgICAgICAgICAgICAgICByZXR1cm4gbnVsbDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgLy8gVW5yZWNvZ25pemVkIHRva2VuLlxuICAgICAgICAgICAgICAgIGFib3J0KCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIC8vIFJldHVybiB0aGUgc2VudGluZWwgYCRgIGNoYXJhY3RlciBpZiB0aGUgcGFyc2VyIGhhcyByZWFjaGVkIHRoZSBlbmRcbiAgICAgICAgICAvLyBvZiB0aGUgc291cmNlIHN0cmluZy5cbiAgICAgICAgICByZXR1cm4gXCIkXCI7XG4gICAgICAgIH07XG5cbiAgICAgICAgLy8gSW50ZXJuYWw6IFBhcnNlcyBhIEpTT04gYHZhbHVlYCB0b2tlbi5cbiAgICAgICAgdmFyIGdldCA9IGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgIHZhciByZXN1bHRzLCBoYXNNZW1iZXJzO1xuICAgICAgICAgIGlmICh2YWx1ZSA9PSBcIiRcIikge1xuICAgICAgICAgICAgLy8gVW5leHBlY3RlZCBlbmQgb2YgaW5wdXQuXG4gICAgICAgICAgICBhYm9ydCgpO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAodHlwZW9mIHZhbHVlID09IFwic3RyaW5nXCIpIHtcbiAgICAgICAgICAgIGlmICgoY2hhckluZGV4QnVnZ3kgPyB2YWx1ZS5jaGFyQXQoMCkgOiB2YWx1ZVswXSkgPT0gXCJAXCIpIHtcbiAgICAgICAgICAgICAgLy8gUmVtb3ZlIHRoZSBzZW50aW5lbCBgQGAgY2hhcmFjdGVyLlxuICAgICAgICAgICAgICByZXR1cm4gdmFsdWUuc2xpY2UoMSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICAvLyBQYXJzZSBvYmplY3QgYW5kIGFycmF5IGxpdGVyYWxzLlxuICAgICAgICAgICAgaWYgKHZhbHVlID09IFwiW1wiKSB7XG4gICAgICAgICAgICAgIC8vIFBhcnNlcyBhIEpTT04gYXJyYXksIHJldHVybmluZyBhIG5ldyBKYXZhU2NyaXB0IGFycmF5LlxuICAgICAgICAgICAgICByZXN1bHRzID0gW107XG4gICAgICAgICAgICAgIGZvciAoOzsgaGFzTWVtYmVycyB8fCAoaGFzTWVtYmVycyA9IHRydWUpKSB7XG4gICAgICAgICAgICAgICAgdmFsdWUgPSBsZXgoKTtcbiAgICAgICAgICAgICAgICAvLyBBIGNsb3Npbmcgc3F1YXJlIGJyYWNrZXQgbWFya3MgdGhlIGVuZCBvZiB0aGUgYXJyYXkgbGl0ZXJhbC5cbiAgICAgICAgICAgICAgICBpZiAodmFsdWUgPT0gXCJdXCIpIHtcbiAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAvLyBJZiB0aGUgYXJyYXkgbGl0ZXJhbCBjb250YWlucyBlbGVtZW50cywgdGhlIGN1cnJlbnQgdG9rZW5cbiAgICAgICAgICAgICAgICAvLyBzaG91bGQgYmUgYSBjb21tYSBzZXBhcmF0aW5nIHRoZSBwcmV2aW91cyBlbGVtZW50IGZyb20gdGhlXG4gICAgICAgICAgICAgICAgLy8gbmV4dC5cbiAgICAgICAgICAgICAgICBpZiAoaGFzTWVtYmVycykge1xuICAgICAgICAgICAgICAgICAgaWYgKHZhbHVlID09IFwiLFwiKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhbHVlID0gbGV4KCk7XG4gICAgICAgICAgICAgICAgICAgIGlmICh2YWx1ZSA9PSBcIl1cIikge1xuICAgICAgICAgICAgICAgICAgICAgIC8vIFVuZXhwZWN0ZWQgdHJhaWxpbmcgYCxgIGluIGFycmF5IGxpdGVyYWwuXG4gICAgICAgICAgICAgICAgICAgICAgYWJvcnQoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gQSBgLGAgbXVzdCBzZXBhcmF0ZSBlYWNoIGFycmF5IGVsZW1lbnQuXG4gICAgICAgICAgICAgICAgICAgIGFib3J0KCk7XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIC8vIEVsaXNpb25zIGFuZCBsZWFkaW5nIGNvbW1hcyBhcmUgbm90IHBlcm1pdHRlZC5cbiAgICAgICAgICAgICAgICBpZiAodmFsdWUgPT0gXCIsXCIpIHtcbiAgICAgICAgICAgICAgICAgIGFib3J0KCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHJlc3VsdHMucHVzaChnZXQodmFsdWUpKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICByZXR1cm4gcmVzdWx0cztcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodmFsdWUgPT0gXCJ7XCIpIHtcbiAgICAgICAgICAgICAgLy8gUGFyc2VzIGEgSlNPTiBvYmplY3QsIHJldHVybmluZyBhIG5ldyBKYXZhU2NyaXB0IG9iamVjdC5cbiAgICAgICAgICAgICAgcmVzdWx0cyA9IHt9O1xuICAgICAgICAgICAgICBmb3IgKDs7IGhhc01lbWJlcnMgfHwgKGhhc01lbWJlcnMgPSB0cnVlKSkge1xuICAgICAgICAgICAgICAgIHZhbHVlID0gbGV4KCk7XG4gICAgICAgICAgICAgICAgLy8gQSBjbG9zaW5nIGN1cmx5IGJyYWNlIG1hcmtzIHRoZSBlbmQgb2YgdGhlIG9iamVjdCBsaXRlcmFsLlxuICAgICAgICAgICAgICAgIGlmICh2YWx1ZSA9PSBcIn1cIikge1xuICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIC8vIElmIHRoZSBvYmplY3QgbGl0ZXJhbCBjb250YWlucyBtZW1iZXJzLCB0aGUgY3VycmVudCB0b2tlblxuICAgICAgICAgICAgICAgIC8vIHNob3VsZCBiZSBhIGNvbW1hIHNlcGFyYXRvci5cbiAgICAgICAgICAgICAgICBpZiAoaGFzTWVtYmVycykge1xuICAgICAgICAgICAgICAgICAgaWYgKHZhbHVlID09IFwiLFwiKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhbHVlID0gbGV4KCk7XG4gICAgICAgICAgICAgICAgICAgIGlmICh2YWx1ZSA9PSBcIn1cIikge1xuICAgICAgICAgICAgICAgICAgICAgIC8vIFVuZXhwZWN0ZWQgdHJhaWxpbmcgYCxgIGluIG9iamVjdCBsaXRlcmFsLlxuICAgICAgICAgICAgICAgICAgICAgIGFib3J0KCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIEEgYCxgIG11c3Qgc2VwYXJhdGUgZWFjaCBvYmplY3QgbWVtYmVyLlxuICAgICAgICAgICAgICAgICAgICBhYm9ydCgpO1xuICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAvLyBMZWFkaW5nIGNvbW1hcyBhcmUgbm90IHBlcm1pdHRlZCwgb2JqZWN0IHByb3BlcnR5IG5hbWVzIG11c3QgYmVcbiAgICAgICAgICAgICAgICAvLyBkb3VibGUtcXVvdGVkIHN0cmluZ3MsIGFuZCBhIGA6YCBtdXN0IHNlcGFyYXRlIGVhY2ggcHJvcGVydHlcbiAgICAgICAgICAgICAgICAvLyBuYW1lIGFuZCB2YWx1ZS5cbiAgICAgICAgICAgICAgICBpZiAodmFsdWUgPT0gXCIsXCIgfHwgdHlwZW9mIHZhbHVlICE9IFwic3RyaW5nXCIgfHwgKGNoYXJJbmRleEJ1Z2d5ID8gdmFsdWUuY2hhckF0KDApIDogdmFsdWVbMF0pICE9IFwiQFwiIHx8IGxleCgpICE9IFwiOlwiKSB7XG4gICAgICAgICAgICAgICAgICBhYm9ydCgpO1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sKHRoaXMpO1xuIl19 + +},{}],58:[function(require,module,exports){ +/** + * Helpers. + */ + +var s = 1000 +var m = s * 60 +var h = m * 60 +var d = h * 24 +var y = d * 365.25 + +/** + * Parse or format the given `val`. + * + * Options: + * + * - `long` verbose formatting [false] + * + * @param {String|Number} val + * @param {Object} options + * @throws {Error} throw an error if val is not a non-empty string or a number + * @return {String|Number} + * @api public + */ + +module.exports = function (val, options) { + options = options || {} + var type = typeof val + if (type === 'string' && val.length > 0) { + return parse(val) + } else if (type === 'number' && isNaN(val) === false) { + return options.long ? + fmtLong(val) : + fmtShort(val) + } + throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val)) +} + +/** + * Parse the given `str` and return milliseconds. + * + * @param {String} str + * @return {Number} + * @api private + */ + +function parse(str) { + str = String(str) + if (str.length > 10000) { + return + } + var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str) + if (!match) { + return + } + var n = parseFloat(match[1]) + var type = (match[2] || 'ms').toLowerCase() + switch (type) { + case 'years': + case 'year': + case 'yrs': + case 'yr': + case 'y': + return n * y + case 'days': + case 'day': + case 'd': + return n * d + case 'hours': + case 'hour': + case 'hrs': + case 'hr': + case 'h': + return n * h + case 'minutes': + case 'minute': + case 'mins': + case 'min': + case 'm': + return n * m + case 'seconds': + case 'second': + case 'secs': + case 'sec': + case 's': + return n * s + case 'milliseconds': + case 'millisecond': + case 'msecs': + case 'msec': + case 'ms': + return n + default: + return undefined + } +} + +/** + * Short format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ + +function fmtShort(ms) { + if (ms >= d) { + return Math.round(ms / d) + 'd' + } + if (ms >= h) { + return Math.round(ms / h) + 'h' + } + if (ms >= m) { + return Math.round(ms / m) + 'm' + } + if (ms >= s) { + return Math.round(ms / s) + 's' + } + return ms + 'ms' +} + +/** + * Long format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ + +function fmtLong(ms) { + return plural(ms, d, 'day') || + plural(ms, h, 'hour') || + plural(ms, m, 'minute') || + plural(ms, s, 'second') || + ms + ' ms' +} + +/** + * Pluralization helper. + */ + +function plural(ms, n, name) { + if (ms < n) { + return + } + if (ms < n * 1.5) { + return Math.floor(ms / n) + ' ' + name + } + return Math.ceil(ms / n) + ' ' + name + 's' +} + },{}],59:[function(require,module,exports){ 'use strict'; +var has = Object.prototype.hasOwnProperty; + +/** + * Simple query string parser. + * + * @param {String} query The query string that needs to be parsed. + * @returns {Object} + * @api public + */ +function querystring(query) { + var parser = /([^=?&]+)=?([^&]*)/g + , result = {} + , part; + + // + // Little nifty parsing hack, leverage the fact that RegExp.exec increments + // the lastIndex property so we can continue executing this loop until we've + // parsed all results. + // + for (; + part = parser.exec(query); + result[decodeURIComponent(part[1])] = decodeURIComponent(part[2]) + ); + + return result; +} + +/** + * Transform a query string to an object. + * + * @param {Object} obj Object that should be transformed. + * @param {String} prefix Optional prefix. + * @returns {String} + * @api public + */ +function querystringify(obj, prefix) { + prefix = prefix || ''; + + var pairs = []; + + // + // Optionally prefix with a '?' if needed + // + if ('string' !== typeof prefix) prefix = '?'; + + for (var key in obj) { + if (has.call(obj, key)) { + pairs.push(encodeURIComponent(key) +'='+ encodeURIComponent(obj[key])); + } + } + + return pairs.length ? prefix + pairs.join('&') : ''; +} + +// +// Expose the module. +// +exports.stringify = querystringify; +exports.parse = querystring; + +},{}],60:[function(require,module,exports){ +'use strict'; + +/** + * Check if we're required to add a port number. + * + * @see https://url.spec.whatwg.org/#default-port + * @param {Number|String} port Port number we need to check + * @param {String} protocol Protocol we need to check against. + * @returns {Boolean} Is it a default port for the given protocol + * @api private + */ +module.exports = function required(port, protocol) { + protocol = protocol.split(':')[0]; + port = +port; + + if (!port) return false; + + switch (protocol) { + case 'http': + case 'ws': + return port !== 80; + + case 'https': + case 'wss': + return port !== 443; + + case 'ftp': + return port !== 21; + + case 'gopher': + return port !== 70; + + case 'file': + return false; + } + + return port !== 0; +}; + +},{}],61:[function(require,module,exports){ +'use strict'; + var required = require('requires-port') , lolcation = require('./lolcation') , qs = require('querystringify') - , relativere = /^\/(?!\/)/ - , protocolre = /^([a-z0-9.+-]+:)?(\/\/)?(.*)$/i; // actual protocol is first match + , protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i; /** - * These are the parse instructions for the URL parsers, it informs the parser + * These are the parse rules for the URL parser, it informs the parser * about: * * 0. The char it Needs to parse, if it's a string it should be done using @@ -5194,44 +5321,79 @@ var required = require('requires-port') * 3. Inherit from location if non existing in the parser. * 4. `toLowerCase` the resulting value. */ -var instructions = [ +var rules = [ ['#', 'hash'], // Extract from the back. ['?', 'query'], // Extract from the back. ['/', 'pathname'], // Extract from the back. ['@', 'auth', 1], // Extract from the front. [NaN, 'host', undefined, 1, 1], // Set left over value. - [/\:(\d+)$/, 'port'], // RegExp the back. + [/:(\d+)$/, 'port', undefined, 1], // RegExp the back. [NaN, 'hostname', undefined, 1, 1] // Set left over. ]; - /** +/** * @typedef ProtocolExtract * @type Object - * @property {String} protocol Protocol matched in the URL, in lowercase - * @property {Boolean} slashes Indicates whether the protocol is followed by double slash ("//") - * @property {String} rest Rest of the URL that is not part of the protocol + * @property {String} protocol Protocol matched in the URL, in lowercase. + * @property {Boolean} slashes `true` if protocol is followed by "//", else `false`. + * @property {String} rest Rest of the URL that is not part of the protocol. */ - /** - * Extract protocol information from a URL with/without double slash ("//") - * - * @param {String} address URL we want to extract from. - * @return {ProtocolExtract} Extracted information - * @private - */ +/** + * Extract protocol information from a URL with/without double slash ("//"). + * + * @param {String} address URL we want to extract from. + * @return {ProtocolExtract} Extracted information. + * @api private + */ function extractProtocol(address) { var match = protocolre.exec(address); + return { protocol: match[1] ? match[1].toLowerCase() : '', slashes: !!match[2], - rest: match[3] ? match[3] : '' + rest: match[3] }; } +/** + * Resolve a relative URL pathname against a base URL pathname. + * + * @param {String} relative Pathname of the relative URL. + * @param {String} base Pathname of the base URL. + * @return {String} Resolved pathname. + * @api private + */ +function resolve(relative, base) { + var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/')) + , i = path.length + , last = path[i - 1] + , unshift = false + , up = 0; + + while (i--) { + if (path[i] === '.') { + path.splice(i, 1); + } else if (path[i] === '..') { + path.splice(i, 1); + up++; + } else if (up) { + if (i === 0) unshift = true; + path.splice(i, 1); + up--; + } + } + + if (unshift) path.unshift(''); + if (last === '.' || last === '..') path.push(''); + + return path.join('/'); +} + /** * The actual URL instance. Instead of returning an object we've opted-in to * create an actual constructor as it's much more memory efficient and - * faster and it pleases my CDO. + * faster and it pleases my OCD. * * @constructor * @param {String} address URL we want to parse. @@ -5244,8 +5406,8 @@ function URL(address, location, parser) { return new URL(address, location, parser); } - var relative = relativere.test(address) - , parse, instruction, index, key + var relative, extracted, parse, instruction, index, key + , instructions = rules.slice() , type = typeof location , url = this , i = 0; @@ -5266,18 +5428,25 @@ function URL(address, location, parser) { location = null; } - if (parser && 'function' !== typeof parser) { - parser = qs.parse; - } + if (parser && 'function' !== typeof parser) parser = qs.parse; location = lolcation(location); - // extract protocol information before running the instructions - var extracted = extractProtocol(address); + // + // Extract protocol information before running the instructions. + // + extracted = extractProtocol(address || ''); + relative = !extracted.protocol && !extracted.slashes; + url.slashes = extracted.slashes || relative && location.slashes; url.protocol = extracted.protocol || location.protocol || ''; - url.slashes = extracted.slashes || location.slashes; address = extracted.rest; + // + // When the authority component is absent the URL starts with a path + // component. + // + if (!extracted.slashes) instructions[2] = [/(.*)/, 'pathname']; + for (; i < instructions.length; i++) { instruction = instructions[i]; parse = instruction[0]; @@ -5297,18 +5466,18 @@ function URL(address, location, parser) { } } else if (index = parse.exec(address)) { url[key] = index[1]; - address = address.slice(0, address.length - index[0].length); + address = address.slice(0, index.index); } - url[key] = url[key] || (instruction[3] || ('port' === key && relative) ? location[key] || '' : ''); + url[key] = url[key] || ( + relative && instruction[3] ? location[key] || '' : '' + ); // // Hostname, host and protocol should be lowercased so they can be used to // create a proper `origin`. // - if (instruction[4]) { - url[key] = url[key].toLowerCase(); - } + if (instruction[4]) url[key] = url[key].toLowerCase(); } // @@ -5318,6 +5487,18 @@ function URL(address, location, parser) { // if (parser) url.query = parser(url.query); + // + // If the URL is relative, resolve the pathname against the base URL. + // + if ( + relative + && location.slashes + && url.pathname.charAt(0) !== '/' + && (url.pathname !== '' || location.pathname !== '') + ) { + url.pathname = resolve(url.pathname, location.pathname); + } + // // We should not add port numbers if they are already the default port number // for a given protocol. As the host also contains the port number we're going @@ -5338,6 +5519,10 @@ function URL(address, location, parser) { url.password = instruction[1] || ''; } + url.origin = url.protocol && url.host && url.protocol !== 'file:' + ? url.protocol +'//'+ url.host + : 'null'; + // // The href is just the compiled result. // @@ -5348,54 +5533,86 @@ function URL(address, location, parser) { * This is convenience method for changing properties in the URL instance to * insure that they all propagate correctly. * - * @param {String} prop Property we need to adjust. + * @param {String} part Property we need to adjust. * @param {Mixed} value The newly assigned value. - * @param {Boolean|Function} fn When setting the query, it will be the function used to parse - * the query. - * When setting the protocol, double slash will be removed from - * the final url if it is true. + * @param {Boolean|Function} fn When setting the query, it will be the function + * used to parse the query. + * When setting the protocol, double slash will be + * removed from the final url if it is true. * @returns {URL} * @api public */ URL.prototype.set = function set(part, value, fn) { var url = this; - if ('query' === part) { - if ('string' === typeof value && value.length) { - value = (fn || qs.parse)(value); - } + switch (part) { + case 'query': + if ('string' === typeof value && value.length) { + value = (fn || qs.parse)(value); + } - url[part] = value; - } else if ('port' === part) { - url[part] = value; + url[part] = value; + break; - if (!required(value, url.protocol)) { - url.host = url.hostname; - url[part] = ''; - } else if (value) { - url.host = url.hostname +':'+ value; - } - } else if ('hostname' === part) { - url[part] = value; + case 'port': + url[part] = value; - if (url.port) value += ':'+ url.port; - url.host = value; - } else if ('host' === part) { - url[part] = value; + if (!required(value, url.protocol)) { + url.host = url.hostname; + url[part] = ''; + } else if (value) { + url.host = url.hostname +':'+ value; + } - if (/\:\d+/.test(value)) { - value = value.split(':'); - url.hostname = value[0]; - url.port = value[1]; - } - } else if ('protocol' === part) { - url.protocol = value; - url.slashes = !fn; - } else { - url[part] = value; + break; + + case 'hostname': + url[part] = value; + + if (url.port) value += ':'+ url.port; + url.host = value; + break; + + case 'host': + url[part] = value; + + if (/:\d+$/.test(value)) { + value = value.split(':'); + url.port = value.pop(); + url.hostname = value.join(':'); + } else { + url.hostname = value; + url.port = ''; + } + + break; + + case 'protocol': + url.protocol = value.toLowerCase(); + url.slashes = !fn; + break; + + case 'pathname': + url.pathname = value.length && value.charAt(0) !== '/' ? '/' + value : value; + + break; + + default: + url[part] = value; } + for (var i = 0; i < rules.length; i++) { + var ins = rules[i]; + + if (ins[4]) url[ins[1]] = url[ins[1]].toLowerCase(); + } + + url.origin = url.protocol && url.host && url.protocol !== 'file:' + ? url.protocol +'//'+ url.host + : 'null'; + url.href = url.toString(); + return url; }; @@ -5423,10 +5640,7 @@ URL.prototype.toString = function toString(stringify) { result += '@'; } - result += url.hostname; - if (url.port) result += ':'+ url.port; - - result += url.pathname; + result += url.host + url.pathname; query = 'object' === typeof url.query ? stringify(url.query) : url.query; if (query) result += '?' !== query.charAt(0) ? '?'+ query : query; @@ -5438,13 +5652,15 @@ URL.prototype.toString = function toString(stringify) { // // Expose the URL parser and some additional properties that might be useful for -// others. +// others or testing. // -URL.qs = qs; +URL.extractProtocol = extractProtocol; URL.location = lolcation; +URL.qs = qs; + module.exports = URL; -},{"./lolcation":60,"querystringify":61,"requires-port":62}],60:[function(require,module,exports){ +},{"./lolcation":62,"querystringify":59,"requires-port":60}],62:[function(require,module,exports){ (function (global){ 'use strict'; @@ -5501,112 +5717,9 @@ module.exports = function lolcation(loc) { }; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy91cmwtcGFyc2UvbG9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yA9PT0gdHlwZSkge1xuICAgIGZpbmFsZGVzdGluYXRpb24gPSBuZXcgVVJMKGxvYywge30pO1xuICAgIGZvciAoa2V5IGluIGlnbm9yZSkgZGVsZXRlIGZpbmFsZGVzdGluYXRpb25ba2V5XTtcbiAgfSBlbHNlIGlmICgnb2JqZWN0JyA9PT0gdHlwZSkge1xuICAgIGZvciAoa2V5IGluIGxvYykge1xuICAgICAgaWYgKGtleSBpbiBpZ25vcmUpIGNvbnRpbnVlO1xuICAgICAgZmluYWxkZXN0aW5hdGlvbltrZXldID0gbG9jW2tleV07XG4gICAgfVxuXG4gICAgaWYgKGZpbmFsZGVzdGluYXRpb24uc2xhc2hlcyA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICBmaW5hbGRlc3RpbmF0aW9uLnNsYXNoZXMgPSBzbGFzaGVzLnRlc3QobG9jLmhyZWYpO1xuICAgIH1cbiAgfVxuXG4gIHJldHVybiBmaW5hbGRlc3RpbmF0aW9uO1xufTtcbiJdfQ== -},{"./":59}],61:[function(require,module,exports){ -'use strict'; -var has = Object.prototype.hasOwnProperty; - -/** - * Simple query string parser. - * - * @param {String} query The query string that needs to be parsed. - * @returns {Object} - * @api public - */ -function querystring(query) { - var parser = /([^=?&]+)=([^&]*)/g - , result = {} - , part; - - // - // Little nifty parsing hack, leverage the fact that RegExp.exec increments - // the lastIndex property so we can continue executing this loop until we've - // parsed all results. - // - for (; - part = parser.exec(query); - result[decodeURIComponent(part[1])] = decodeURIComponent(part[2]) - ); - - return result; -} - -/** - * Transform a query string to an object. - * - * @param {Object} obj Object that should be transformed. - * @param {String} prefix Optional prefix. - * @returns {String} - * @api public - */ -function querystringify(obj, prefix) { - prefix = prefix || ''; - - var pairs = []; - - // - // Optionally prefix with a '?' if needed - // - if ('string' !== typeof prefix) prefix = '?'; - - for (var key in obj) { - if (has.call(obj, key)) { - pairs.push(encodeURIComponent(key) +'='+ encodeURIComponent(obj[key])); - } - } - - return pairs.length ? prefix + pairs.join('&') : ''; -} - -// -// Expose the module. -// -exports.stringify = querystringify; -exports.parse = querystring; - -},{}],62:[function(require,module,exports){ -'use strict'; - -/** - * Check if we're required to add a port number. - * - * @see https://url.spec.whatwg.org/#default-port - * @param {Number|String} port Port number we need to check - * @param {String} protocol Protocol we need to check against. - * @returns {Boolean} Is it a default port for the given protocol - * @api private - */ -module.exports = function required(port, protocol) { - protocol = protocol.split(':')[0]; - port = +port; - - if (!port) return false; - - switch (protocol) { - case 'http': - case 'ws': - return port !== 80; - - case 'https': - case 'wss': - return port !== 443; - - case 'ftp': - return port !== 21; - - case 'gopher': - return port !== 70; - - case 'file': - return false; - } - - return port !== 0; -}; - -},{}]},{},[1])(1) +},{"./":61}]},{},[1])(1) }); -//# sourceMappingURL=sockjs.js.map \ No newline at end of file +//# sourceMappingURL=sockjs.js.map diff --git a/src/octoprint/static/js/lib/sockjs.js.map b/src/octoprint/static/js/lib/sockjs.js.map new file mode 100644 index 000000000..fa8bee664 --- /dev/null +++ b/src/octoprint/static/js/lib/sockjs.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["node_modules/browser-pack/_prelude.js","lib/entry.js","lib/event/close.js","lib/event/emitter.js","lib/event/event.js","lib/event/eventtarget.js","lib/event/trans-message.js","lib/facade.js","lib/iframe-bootstrap.js","lib/info-ajax.js","lib/info-iframe-receiver.js","lib/info-iframe.js","lib/info-receiver.js","lib/location.js","lib/main.js","lib/shims.js","lib/transport-list.js","lib/transport/browser/abstract-xhr.js","lib/transport/browser/eventsource.js","lib/transport/browser/websocket.js","lib/transport/eventsource.js","lib/transport/htmlfile.js","lib/transport/iframe.js","lib/transport/jsonp-polling.js","lib/transport/lib/ajax-based.js","lib/transport/lib/buffered-sender.js","lib/transport/lib/iframe-wrap.js","lib/transport/lib/polling.js","lib/transport/lib/sender-receiver.js","lib/transport/receiver/eventsource.js","lib/transport/receiver/htmlfile.js","lib/transport/receiver/jsonp.js","lib/transport/receiver/xhr.js","lib/transport/sender/jsonp.js","lib/transport/sender/xdr.js","lib/transport/sender/xhr-cors.js","lib/transport/sender/xhr-fake.js","lib/transport/sender/xhr-local.js","lib/transport/websocket.js","lib/transport/xdr-polling.js","lib/transport/xdr-streaming.js","lib/transport/xhr-polling.js","lib/transport/xhr-streaming.js","lib/utils/browser-crypto.js","lib/utils/browser.js","lib/utils/escape.js","lib/utils/event.js","lib/utils/iframe.js","lib/utils/log.js","lib/utils/object.js","lib/utils/random.js","lib/utils/transport.js","lib/utils/url.js","lib/version.js","node_modules/debug/src/browser.js","node_modules/debug/src/debug.js","node_modules/inherits/inherits_browser.js","node_modules/json3/lib/json3.js","node_modules/ms/index.js","node_modules/querystringify/index.js","node_modules/requires-port/index.js","node_modules/url-parse/index.js","node_modules/url-parse/lolcation.js"],"names":[],"mappings":";AAAA;;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AC3BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACtGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;ACjDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;ACjCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACrEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACzFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AC7XA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACpcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AClBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACjMA;AACA;;;;;ACDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC3BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;ACzBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AC7IA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AClCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACjDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACvFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACjCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACzDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AC7CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AC/DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACvFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACvLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACtEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACnGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;ACvGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;ACjBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;ACnGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;ACjCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACzCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACjBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AC3BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AClDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACzEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AC1LA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AClBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AC7BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AClDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AC/CA;AACA;;;ACDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;ACtLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;ACvBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;ACt4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrJA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC7DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;ACrWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"sockjs.js","sourcesContent":["(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o 1) {\n // Make a copy so as not to interfere with a current dispatchEvent.\n this._listeners[eventType] = arr.slice(0, idx).concat(arr.slice(idx + 1));\n } else {\n delete this._listeners[eventType];\n }\n return;\n }\n};\n\nEventTarget.prototype.dispatchEvent = function() {\n var event = arguments[0];\n var t = event.type;\n // equivalent of Array.prototype.slice.call(arguments, 0);\n var args = arguments.length === 1 ? [event] : Array.apply(null, arguments);\n // TODO: This doesn't match the real behavior; per spec, onfoo get\n // their place in line from the /first/ time they're set from\n // non-null. Although WebKit bumps it to the end every time it's\n // set.\n if (this['on' + t]) {\n this['on' + t].apply(this, args);\n }\n if (t in this._listeners) {\n // Grab a reference to the listeners list. removeEventListener may alter the list.\n var listeners = this._listeners[t];\n for (var i = 0; i < listeners.length; i++) {\n listeners[i].apply(this, args);\n }\n }\n};\n\nmodule.exports = EventTarget;\n","'use strict';\n\nvar inherits = require('inherits')\n , Event = require('./event')\n ;\n\nfunction TransportMessageEvent(data) {\n Event.call(this);\n this.initEvent('message', false, false);\n this.data = data;\n}\n\ninherits(TransportMessageEvent, Event);\n\nmodule.exports = TransportMessageEvent;\n","'use strict';\n\nvar JSON3 = require('json3')\n , iframeUtils = require('./utils/iframe')\n ;\n\nfunction FacadeJS(transport) {\n this._transport = transport;\n transport.on('message', this._transportMessage.bind(this));\n transport.on('close', this._transportClose.bind(this));\n}\n\nFacadeJS.prototype._transportClose = function(code, reason) {\n iframeUtils.postMessage('c', JSON3.stringify([code, reason]));\n};\nFacadeJS.prototype._transportMessage = function(frame) {\n iframeUtils.postMessage('t', frame);\n};\nFacadeJS.prototype._send = function(data) {\n this._transport.send(data);\n};\nFacadeJS.prototype._close = function() {\n this._transport.close();\n this._transport.removeAllListeners();\n};\n\nmodule.exports = FacadeJS;\n","'use strict';\n\nvar urlUtils = require('./utils/url')\n , eventUtils = require('./utils/event')\n , JSON3 = require('json3')\n , FacadeJS = require('./facade')\n , InfoIframeReceiver = require('./info-iframe-receiver')\n , iframeUtils = require('./utils/iframe')\n , loc = require('./location')\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:iframe-bootstrap');\n}\n\nmodule.exports = function(SockJS, availableTransports) {\n var transportMap = {};\n availableTransports.forEach(function(at) {\n if (at.facadeTransport) {\n transportMap[at.facadeTransport.transportName] = at.facadeTransport;\n }\n });\n\n // hard-coded for the info iframe\n // TODO see if we can make this more dynamic\n transportMap[InfoIframeReceiver.transportName] = InfoIframeReceiver;\n var parentOrigin;\n\n /* eslint-disable camelcase */\n SockJS.bootstrap_iframe = function() {\n /* eslint-enable camelcase */\n var facade;\n iframeUtils.currentWindowId = loc.hash.slice(1);\n var onMessage = function(e) {\n if (e.source !== parent) {\n return;\n }\n if (typeof parentOrigin === 'undefined') {\n parentOrigin = e.origin;\n }\n if (e.origin !== parentOrigin) {\n return;\n }\n\n var iframeMessage;\n try {\n iframeMessage = JSON3.parse(e.data);\n } catch (ignored) {\n debug('bad json', e.data);\n return;\n }\n\n if (iframeMessage.windowId !== iframeUtils.currentWindowId) {\n return;\n }\n switch (iframeMessage.type) {\n case 's':\n var p;\n try {\n p = JSON3.parse(iframeMessage.data);\n } catch (ignored) {\n debug('bad json', iframeMessage.data);\n break;\n }\n var version = p[0];\n var transport = p[1];\n var transUrl = p[2];\n var baseUrl = p[3];\n debug(version, transport, transUrl, baseUrl);\n // change this to semver logic\n if (version !== SockJS.version) {\n throw new Error('Incompatible SockJS! Main site uses:' +\n ' \"' + version + '\", the iframe:' +\n ' \"' + SockJS.version + '\".');\n }\n\n if (!urlUtils.isOriginEqual(transUrl, loc.href) ||\n !urlUtils.isOriginEqual(baseUrl, loc.href)) {\n throw new Error('Can\\'t connect to different domain from within an ' +\n 'iframe. (' + loc.href + ', ' + transUrl + ', ' + baseUrl + ')');\n }\n facade = new FacadeJS(new transportMap[transport](transUrl, baseUrl));\n break;\n case 'm':\n facade._send(iframeMessage.data);\n break;\n case 'c':\n if (facade) {\n facade._close();\n }\n facade = null;\n break;\n }\n };\n\n eventUtils.attachEvent('message', onMessage);\n\n // Start\n iframeUtils.postMessage('s');\n };\n};\n","'use strict';\n\nvar EventEmitter = require('events').EventEmitter\n , inherits = require('inherits')\n , JSON3 = require('json3')\n , objectUtils = require('./utils/object')\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:info-ajax');\n}\n\nfunction InfoAjax(url, AjaxObject) {\n EventEmitter.call(this);\n\n var self = this;\n var t0 = +new Date();\n this.xo = new AjaxObject('GET', url);\n\n this.xo.once('finish', function(status, text) {\n var info, rtt;\n if (status === 200) {\n rtt = (+new Date()) - t0;\n if (text) {\n try {\n info = JSON3.parse(text);\n } catch (e) {\n debug('bad json', text);\n }\n }\n\n if (!objectUtils.isObject(info)) {\n info = {};\n }\n }\n self.emit('finish', info, rtt);\n self.removeAllListeners();\n });\n}\n\ninherits(InfoAjax, EventEmitter);\n\nInfoAjax.prototype.close = function() {\n this.removeAllListeners();\n this.xo.close();\n};\n\nmodule.exports = InfoAjax;\n","'use strict';\n\nvar inherits = require('inherits')\n , EventEmitter = require('events').EventEmitter\n , JSON3 = require('json3')\n , XHRLocalObject = require('./transport/sender/xhr-local')\n , InfoAjax = require('./info-ajax')\n ;\n\nfunction InfoReceiverIframe(transUrl) {\n var self = this;\n EventEmitter.call(this);\n\n this.ir = new InfoAjax(transUrl, XHRLocalObject);\n this.ir.once('finish', function(info, rtt) {\n self.ir = null;\n self.emit('message', JSON3.stringify([info, rtt]));\n });\n}\n\ninherits(InfoReceiverIframe, EventEmitter);\n\nInfoReceiverIframe.transportName = 'iframe-info-receiver';\n\nInfoReceiverIframe.prototype.close = function() {\n if (this.ir) {\n this.ir.close();\n this.ir = null;\n }\n this.removeAllListeners();\n};\n\nmodule.exports = InfoReceiverIframe;\n","'use strict';\n\nvar EventEmitter = require('events').EventEmitter\n , inherits = require('inherits')\n , JSON3 = require('json3')\n , utils = require('./utils/event')\n , IframeTransport = require('./transport/iframe')\n , InfoReceiverIframe = require('./info-iframe-receiver')\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:info-iframe');\n}\n\nfunction InfoIframe(baseUrl, url) {\n var self = this;\n EventEmitter.call(this);\n\n var go = function() {\n var ifr = self.ifr = new IframeTransport(InfoReceiverIframe.transportName, url, baseUrl);\n\n ifr.once('message', function(msg) {\n if (msg) {\n var d;\n try {\n d = JSON3.parse(msg);\n } catch (e) {\n debug('bad json', msg);\n self.emit('finish');\n self.close();\n return;\n }\n\n var info = d[0], rtt = d[1];\n self.emit('finish', info, rtt);\n }\n self.close();\n });\n\n ifr.once('close', function() {\n self.emit('finish');\n self.close();\n });\n };\n\n // TODO this seems the same as the 'needBody' from transports\n if (!global.document.body) {\n utils.attachEvent('load', go);\n } else {\n go();\n }\n}\n\ninherits(InfoIframe, EventEmitter);\n\nInfoIframe.enabled = function() {\n return IframeTransport.enabled();\n};\n\nInfoIframe.prototype.close = function() {\n if (this.ifr) {\n this.ifr.close();\n }\n this.removeAllListeners();\n this.ifr = null;\n};\n\nmodule.exports = InfoIframe;\n","'use strict';\n\nvar EventEmitter = require('events').EventEmitter\n , inherits = require('inherits')\n , urlUtils = require('./utils/url')\n , XDR = require('./transport/sender/xdr')\n , XHRCors = require('./transport/sender/xhr-cors')\n , XHRLocal = require('./transport/sender/xhr-local')\n , XHRFake = require('./transport/sender/xhr-fake')\n , InfoIframe = require('./info-iframe')\n , InfoAjax = require('./info-ajax')\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:info-receiver');\n}\n\nfunction InfoReceiver(baseUrl, urlInfo) {\n debug(baseUrl);\n var self = this;\n EventEmitter.call(this);\n\n setTimeout(function() {\n self.doXhr(baseUrl, urlInfo);\n }, 0);\n}\n\ninherits(InfoReceiver, EventEmitter);\n\n// TODO this is currently ignoring the list of available transports and the whitelist\n\nInfoReceiver._getReceiver = function(baseUrl, url, urlInfo) {\n // determine method of CORS support (if needed)\n if (urlInfo.sameOrigin) {\n return new InfoAjax(url, XHRLocal);\n }\n if (XHRCors.enabled) {\n return new InfoAjax(url, XHRCors);\n }\n if (XDR.enabled && urlInfo.sameScheme) {\n return new InfoAjax(url, XDR);\n }\n if (InfoIframe.enabled()) {\n return new InfoIframe(baseUrl, url);\n }\n return new InfoAjax(url, XHRFake);\n};\n\nInfoReceiver.prototype.doXhr = function(baseUrl, urlInfo) {\n var self = this\n , url = urlUtils.addPath(baseUrl, '/info')\n ;\n debug('doXhr', url);\n\n this.xo = InfoReceiver._getReceiver(baseUrl, url, urlInfo);\n\n this.timeoutRef = setTimeout(function() {\n debug('timeout');\n self._cleanup(false);\n self.emit('finish');\n }, InfoReceiver.timeout);\n\n this.xo.once('finish', function(info, rtt) {\n debug('finish', info, rtt);\n self._cleanup(true);\n self.emit('finish', info, rtt);\n });\n};\n\nInfoReceiver.prototype._cleanup = function(wasClean) {\n debug('_cleanup');\n clearTimeout(this.timeoutRef);\n this.timeoutRef = null;\n if (!wasClean && this.xo) {\n this.xo.close();\n }\n this.xo = null;\n};\n\nInfoReceiver.prototype.close = function() {\n debug('close');\n this.removeAllListeners();\n this._cleanup(false);\n};\n\nInfoReceiver.timeout = 8000;\n\nmodule.exports = InfoReceiver;\n","'use strict';\n\nmodule.exports = global.location || {\n origin: 'http://localhost:80'\n, protocol: 'http'\n, host: 'localhost'\n, port: 80\n, href: 'http://localhost/'\n, hash: ''\n};\n","'use strict';\n\nrequire('./shims');\n\nvar URL = require('url-parse')\n , inherits = require('inherits')\n , JSON3 = require('json3')\n , random = require('./utils/random')\n , escape = require('./utils/escape')\n , urlUtils = require('./utils/url')\n , eventUtils = require('./utils/event')\n , transport = require('./utils/transport')\n , objectUtils = require('./utils/object')\n , browser = require('./utils/browser')\n , log = require('./utils/log')\n , Event = require('./event/event')\n , EventTarget = require('./event/eventtarget')\n , loc = require('./location')\n , CloseEvent = require('./event/close')\n , TransportMessageEvent = require('./event/trans-message')\n , InfoReceiver = require('./info-receiver')\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:main');\n}\n\nvar transports;\n\n// follow constructor steps defined at http://dev.w3.org/html5/websockets/#the-websocket-interface\nfunction SockJS(url, protocols, options) {\n if (!(this instanceof SockJS)) {\n return new SockJS(url, protocols, options);\n }\n if (arguments.length < 1) {\n throw new TypeError(\"Failed to construct 'SockJS: 1 argument required, but only 0 present\");\n }\n EventTarget.call(this);\n\n this.readyState = SockJS.CONNECTING;\n this.extensions = '';\n this.protocol = '';\n\n // non-standard extension\n options = options || {};\n if (options.protocols_whitelist) {\n log.warn(\"'protocols_whitelist' is DEPRECATED. Use 'transports' instead.\");\n }\n this._transportsWhitelist = options.transports;\n this._transportOptions = options.transportOptions || {};\n\n var sessionId = options.sessionId || 8;\n if (typeof sessionId === 'function') {\n this._generateSessionId = sessionId;\n } else if (typeof sessionId === 'number') {\n this._generateSessionId = function() {\n return random.string(sessionId);\n };\n } else {\n throw new TypeError('If sessionId is used in the options, it needs to be a number or a function.');\n }\n\n this._server = options.server || random.numberString(1000);\n\n // Step 1 of WS spec - parse and validate the url. Issue #8\n var parsedUrl = new URL(url);\n if (!parsedUrl.host || !parsedUrl.protocol) {\n throw new SyntaxError(\"The URL '\" + url + \"' is invalid\");\n } else if (parsedUrl.hash) {\n throw new SyntaxError('The URL must not contain a fragment');\n } else if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {\n throw new SyntaxError(\"The URL's scheme must be either 'http:' or 'https:'. '\" + parsedUrl.protocol + \"' is not allowed.\");\n }\n\n var secure = parsedUrl.protocol === 'https:';\n // Step 2 - don't allow secure origin with an insecure protocol\n if (loc.protocol === 'https' && !secure) {\n throw new Error('SecurityError: An insecure SockJS connection may not be initiated from a page loaded over HTTPS');\n }\n\n // Step 3 - check port access - no need here\n // Step 4 - parse protocols argument\n if (!protocols) {\n protocols = [];\n } else if (!Array.isArray(protocols)) {\n protocols = [protocols];\n }\n\n // Step 5 - check protocols argument\n var sortedProtocols = protocols.sort();\n sortedProtocols.forEach(function(proto, i) {\n if (!proto) {\n throw new SyntaxError(\"The protocols entry '\" + proto + \"' is invalid.\");\n }\n if (i < (sortedProtocols.length - 1) && proto === sortedProtocols[i + 1]) {\n throw new SyntaxError(\"The protocols entry '\" + proto + \"' is duplicated.\");\n }\n });\n\n // Step 6 - convert origin\n var o = urlUtils.getOrigin(loc.href);\n this._origin = o ? o.toLowerCase() : null;\n\n // remove the trailing slash\n parsedUrl.set('pathname', parsedUrl.pathname.replace(/\\/+$/, ''));\n\n // store the sanitized url\n this.url = parsedUrl.href;\n debug('using url', this.url);\n\n // Step 7 - start connection in background\n // obtain server info\n // http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-26\n this._urlInfo = {\n nullOrigin: !browser.hasDomain()\n , sameOrigin: urlUtils.isOriginEqual(this.url, loc.href)\n , sameScheme: urlUtils.isSchemeEqual(this.url, loc.href)\n };\n\n this._ir = new InfoReceiver(this.url, this._urlInfo);\n this._ir.once('finish', this._receiveInfo.bind(this));\n}\n\ninherits(SockJS, EventTarget);\n\nfunction userSetCode(code) {\n return code === 1000 || (code >= 3000 && code <= 4999);\n}\n\nSockJS.prototype.close = function(code, reason) {\n // Step 1\n if (code && !userSetCode(code)) {\n throw new Error('InvalidAccessError: Invalid code');\n }\n // Step 2.4 states the max is 123 bytes, but we are just checking length\n if (reason && reason.length > 123) {\n throw new SyntaxError('reason argument has an invalid length');\n }\n\n // Step 3.1\n if (this.readyState === SockJS.CLOSING || this.readyState === SockJS.CLOSED) {\n return;\n }\n\n // TODO look at docs to determine how to set this\n var wasClean = true;\n this._close(code || 1000, reason || 'Normal closure', wasClean);\n};\n\nSockJS.prototype.send = function(data) {\n // #13 - convert anything non-string to string\n // TODO this currently turns objects into [object Object]\n if (typeof data !== 'string') {\n data = '' + data;\n }\n if (this.readyState === SockJS.CONNECTING) {\n throw new Error('InvalidStateError: The connection has not been established yet');\n }\n if (this.readyState !== SockJS.OPEN) {\n return;\n }\n this._transport.send(escape.quote(data));\n};\n\nSockJS.version = require('./version');\n\nSockJS.CONNECTING = 0;\nSockJS.OPEN = 1;\nSockJS.CLOSING = 2;\nSockJS.CLOSED = 3;\n\nSockJS.prototype._receiveInfo = function(info, rtt) {\n debug('_receiveInfo', rtt);\n this._ir = null;\n if (!info) {\n this._close(1002, 'Cannot connect to server');\n return;\n }\n\n // establish a round-trip timeout (RTO) based on the\n // round-trip time (RTT)\n this._rto = this.countRTO(rtt);\n // allow server to override url used for the actual transport\n this._transUrl = info.base_url ? info.base_url : this.url;\n info = objectUtils.extend(info, this._urlInfo);\n debug('info', info);\n // determine list of desired and supported transports\n var enabledTransports = transports.filterToEnabled(this._transportsWhitelist, info);\n this._transports = enabledTransports.main;\n debug(this._transports.length + ' enabled transports');\n\n this._connect();\n};\n\nSockJS.prototype._connect = function() {\n for (var Transport = this._transports.shift(); Transport; Transport = this._transports.shift()) {\n debug('attempt', Transport.transportName);\n if (Transport.needBody) {\n if (!global.document.body ||\n (typeof global.document.readyState !== 'undefined' &&\n global.document.readyState !== 'complete' &&\n global.document.readyState !== 'interactive')) {\n debug('waiting for body');\n this._transports.unshift(Transport);\n eventUtils.attachEvent('load', this._connect.bind(this));\n return;\n }\n }\n\n // calculate timeout based on RTO and round trips. Default to 5s\n var timeoutMs = (this._rto * Transport.roundTrips) || 5000;\n this._transportTimeoutId = setTimeout(this._transportTimeout.bind(this), timeoutMs);\n debug('using timeout', timeoutMs);\n\n var transportUrl = urlUtils.addPath(this._transUrl, '/' + this._server + '/' + this._generateSessionId());\n var options = this._transportOptions[Transport.transportName];\n debug('transport url', transportUrl);\n var transportObj = new Transport(transportUrl, this._transUrl, options);\n transportObj.on('message', this._transportMessage.bind(this));\n transportObj.once('close', this._transportClose.bind(this));\n transportObj.transportName = Transport.transportName;\n this._transport = transportObj;\n\n return;\n }\n this._close(2000, 'All transports failed', false);\n};\n\nSockJS.prototype._transportTimeout = function() {\n debug('_transportTimeout');\n if (this.readyState === SockJS.CONNECTING) {\n this._transportClose(2007, 'Transport timed out');\n }\n};\n\nSockJS.prototype._transportMessage = function(msg) {\n debug('_transportMessage', msg);\n var self = this\n , type = msg.slice(0, 1)\n , content = msg.slice(1)\n , payload\n ;\n\n // first check for messages that don't need a payload\n switch (type) {\n case 'o':\n this._open();\n return;\n case 'h':\n this.dispatchEvent(new Event('heartbeat'));\n debug('heartbeat', this.transport);\n return;\n }\n\n if (content) {\n try {\n payload = JSON3.parse(content);\n } catch (e) {\n debug('bad json', content);\n }\n }\n\n if (typeof payload === 'undefined') {\n debug('empty payload', content);\n return;\n }\n\n switch (type) {\n case 'a':\n if (Array.isArray(payload)) {\n payload.forEach(function(p) {\n debug('message', self.transport, p);\n self.dispatchEvent(new TransportMessageEvent(p));\n });\n }\n break;\n case 'm':\n debug('message', this.transport, payload);\n this.dispatchEvent(new TransportMessageEvent(payload));\n break;\n case 'c':\n if (Array.isArray(payload) && payload.length === 2) {\n this._close(payload[0], payload[1], true);\n }\n break;\n }\n};\n\nSockJS.prototype._transportClose = function(code, reason) {\n debug('_transportClose', this.transport, code, reason);\n if (this._transport) {\n this._transport.removeAllListeners();\n this._transport = null;\n this.transport = null;\n }\n\n if (!userSetCode(code) && code !== 2000 && this.readyState === SockJS.CONNECTING) {\n this._connect();\n return;\n }\n\n this._close(code, reason);\n};\n\nSockJS.prototype._open = function() {\n debug('_open', this._transport.transportName, this.readyState);\n if (this.readyState === SockJS.CONNECTING) {\n if (this._transportTimeoutId) {\n clearTimeout(this._transportTimeoutId);\n this._transportTimeoutId = null;\n }\n this.readyState = SockJS.OPEN;\n this.transport = this._transport.transportName;\n this.dispatchEvent(new Event('open'));\n debug('connected', this.transport);\n } else {\n // The server might have been restarted, and lost track of our\n // connection.\n this._close(1006, 'Server lost session');\n }\n};\n\nSockJS.prototype._close = function(code, reason, wasClean) {\n debug('_close', this.transport, code, reason, wasClean, this.readyState);\n var forceFail = false;\n\n if (this._ir) {\n forceFail = true;\n this._ir.close();\n this._ir = null;\n }\n if (this._transport) {\n this._transport.close();\n this._transport = null;\n this.transport = null;\n }\n\n if (this.readyState === SockJS.CLOSED) {\n throw new Error('InvalidStateError: SockJS has already been closed');\n }\n\n this.readyState = SockJS.CLOSING;\n setTimeout(function() {\n this.readyState = SockJS.CLOSED;\n\n if (forceFail) {\n this.dispatchEvent(new Event('error'));\n }\n\n var e = new CloseEvent('close');\n e.wasClean = wasClean || false;\n e.code = code || 1000;\n e.reason = reason;\n\n this.dispatchEvent(e);\n this.onmessage = this.onclose = this.onerror = null;\n debug('disconnected');\n }.bind(this), 0);\n};\n\n// See: http://www.erg.abdn.ac.uk/~gerrit/dccp/notes/ccid2/rto_estimator/\n// and RFC 2988.\nSockJS.prototype.countRTO = function(rtt) {\n // In a local environment, when using IE8/9 and the `jsonp-polling`\n // transport the time needed to establish a connection (the time that pass\n // from the opening of the transport to the call of `_dispatchOpen`) is\n // around 200msec (the lower bound used in the article above) and this\n // causes spurious timeouts. For this reason we calculate a value slightly\n // larger than that used in the article.\n if (rtt > 100) {\n return 4 * rtt; // rto > 400msec\n }\n return 300 + rtt; // 300msec < rto <= 400msec\n};\n\nmodule.exports = function(availableTransports) {\n transports = transport(availableTransports);\n require('./iframe-bootstrap')(SockJS, availableTransports);\n return SockJS;\n};\n","/* eslint-disable */\n/* jscs: disable */\n'use strict';\n\n// pulled specific shims from https://github.com/es-shims/es5-shim\n\nvar ArrayPrototype = Array.prototype;\nvar ObjectPrototype = Object.prototype;\nvar FunctionPrototype = Function.prototype;\nvar StringPrototype = String.prototype;\nvar array_slice = ArrayPrototype.slice;\n\nvar _toString = ObjectPrototype.toString;\nvar isFunction = function (val) {\n return ObjectPrototype.toString.call(val) === '[object Function]';\n};\nvar isArray = function isArray(obj) {\n return _toString.call(obj) === '[object Array]';\n};\nvar isString = function isString(obj) {\n return _toString.call(obj) === '[object String]';\n};\n\nvar supportsDescriptors = Object.defineProperty && (function () {\n try {\n Object.defineProperty({}, 'x', {});\n return true;\n } catch (e) { /* this is ES3 */\n return false;\n }\n}());\n\n// Define configurable, writable and non-enumerable props\n// if they don't exist.\nvar defineProperty;\nif (supportsDescriptors) {\n defineProperty = function (object, name, method, forceAssign) {\n if (!forceAssign && (name in object)) { return; }\n Object.defineProperty(object, name, {\n configurable: true,\n enumerable: false,\n writable: true,\n value: method\n });\n };\n} else {\n defineProperty = function (object, name, method, forceAssign) {\n if (!forceAssign && (name in object)) { return; }\n object[name] = method;\n };\n}\nvar defineProperties = function (object, map, forceAssign) {\n for (var name in map) {\n if (ObjectPrototype.hasOwnProperty.call(map, name)) {\n defineProperty(object, name, map[name], forceAssign);\n }\n }\n};\n\nvar toObject = function (o) {\n if (o == null) { // this matches both null and undefined\n throw new TypeError(\"can't convert \" + o + ' to object');\n }\n return Object(o);\n};\n\n//\n// Util\n// ======\n//\n\n// ES5 9.4\n// http://es5.github.com/#x9.4\n// http://jsperf.com/to-integer\n\nfunction toInteger(num) {\n var n = +num;\n if (n !== n) { // isNaN\n n = 0;\n } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {\n n = (n > 0 || -1) * Math.floor(Math.abs(n));\n }\n return n;\n}\n\nfunction ToUint32(x) {\n return x >>> 0;\n}\n\n//\n// Function\n// ========\n//\n\n// ES-5 15.3.4.5\n// http://es5.github.com/#x15.3.4.5\n\nfunction Empty() {}\n\ndefineProperties(FunctionPrototype, {\n bind: function bind(that) { // .length is 1\n // 1. Let Target be the this value.\n var target = this;\n // 2. If IsCallable(Target) is false, throw a TypeError exception.\n if (!isFunction(target)) {\n throw new TypeError('Function.prototype.bind called on incompatible ' + target);\n }\n // 3. Let A be a new (possibly empty) internal list of all of the\n // argument values provided after thisArg (arg1, arg2 etc), in order.\n // XXX slicedArgs will stand in for \"A\" if used\n var args = array_slice.call(arguments, 1); // for normal call\n // 4. Let F be a new native ECMAScript object.\n // 11. Set the [[Prototype]] internal property of F to the standard\n // built-in Function prototype object as specified in 15.3.3.1.\n // 12. Set the [[Call]] internal property of F as described in\n // 15.3.4.5.1.\n // 13. Set the [[Construct]] internal property of F as described in\n // 15.3.4.5.2.\n // 14. Set the [[HasInstance]] internal property of F as described in\n // 15.3.4.5.3.\n var binder = function () {\n\n if (this instanceof bound) {\n // 15.3.4.5.2 [[Construct]]\n // When the [[Construct]] internal method of a function object,\n // F that was created using the bind function is called with a\n // list of arguments ExtraArgs, the following steps are taken:\n // 1. Let target be the value of F's [[TargetFunction]]\n // internal property.\n // 2. If target has no [[Construct]] internal method, a\n // TypeError exception is thrown.\n // 3. Let boundArgs be the value of F's [[BoundArgs]] internal\n // property.\n // 4. Let args be a new list containing the same values as the\n // list boundArgs in the same order followed by the same\n // values as the list ExtraArgs in the same order.\n // 5. Return the result of calling the [[Construct]] internal\n // method of target providing args as the arguments.\n\n var result = target.apply(\n this,\n args.concat(array_slice.call(arguments))\n );\n if (Object(result) === result) {\n return result;\n }\n return this;\n\n } else {\n // 15.3.4.5.1 [[Call]]\n // When the [[Call]] internal method of a function object, F,\n // which was created using the bind function is called with a\n // this value and a list of arguments ExtraArgs, the following\n // steps are taken:\n // 1. Let boundArgs be the value of F's [[BoundArgs]] internal\n // property.\n // 2. Let boundThis be the value of F's [[BoundThis]] internal\n // property.\n // 3. Let target be the value of F's [[TargetFunction]] internal\n // property.\n // 4. Let args be a new list containing the same values as the\n // list boundArgs in the same order followed by the same\n // values as the list ExtraArgs in the same order.\n // 5. Return the result of calling the [[Call]] internal method\n // of target providing boundThis as the this value and\n // providing args as the arguments.\n\n // equiv: target.call(this, ...boundArgs, ...args)\n return target.apply(\n that,\n args.concat(array_slice.call(arguments))\n );\n\n }\n\n };\n\n // 15. If the [[Class]] internal property of Target is \"Function\", then\n // a. Let L be the length property of Target minus the length of A.\n // b. Set the length own property of F to either 0 or L, whichever is\n // larger.\n // 16. Else set the length own property of F to 0.\n\n var boundLength = Math.max(0, target.length - args.length);\n\n // 17. Set the attributes of the length own property of F to the values\n // specified in 15.3.5.1.\n var boundArgs = [];\n for (var i = 0; i < boundLength; i++) {\n boundArgs.push('$' + i);\n }\n\n // XXX Build a dynamic function with desired amount of arguments is the only\n // way to set the length property of a function.\n // In environments where Content Security Policies enabled (Chrome extensions,\n // for ex.) all use of eval or Function costructor throws an exception.\n // However in all of these environments Function.prototype.bind exists\n // and so this code will never be executed.\n var bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);\n\n if (target.prototype) {\n Empty.prototype = target.prototype;\n bound.prototype = new Empty();\n // Clean up dangling references.\n Empty.prototype = null;\n }\n\n // TODO\n // 18. Set the [[Extensible]] internal property of F to true.\n\n // TODO\n // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).\n // 20. Call the [[DefineOwnProperty]] internal method of F with\n // arguments \"caller\", PropertyDescriptor {[[Get]]: thrower, [[Set]]:\n // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and\n // false.\n // 21. Call the [[DefineOwnProperty]] internal method of F with\n // arguments \"arguments\", PropertyDescriptor {[[Get]]: thrower,\n // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},\n // and false.\n\n // TODO\n // NOTE Function objects created using Function.prototype.bind do not\n // have a prototype property or the [[Code]], [[FormalParameters]], and\n // [[Scope]] internal properties.\n // XXX can't delete prototype in pure-js.\n\n // 22. Return F.\n return bound;\n }\n});\n\n//\n// Array\n// =====\n//\n\n// ES5 15.4.3.2\n// http://es5.github.com/#x15.4.3.2\n// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray\ndefineProperties(Array, { isArray: isArray });\n\n\nvar boxedString = Object('a');\nvar splitString = boxedString[0] !== 'a' || !(0 in boxedString);\n\nvar properlyBoxesContext = function properlyBoxed(method) {\n // Check node 0.6.21 bug where third parameter is not boxed\n var properlyBoxesNonStrict = true;\n var properlyBoxesStrict = true;\n if (method) {\n method.call('foo', function (_, __, context) {\n if (typeof context !== 'object') { properlyBoxesNonStrict = false; }\n });\n\n method.call([1], function () {\n 'use strict';\n properlyBoxesStrict = typeof this === 'string';\n }, 'x');\n }\n return !!method && properlyBoxesNonStrict && properlyBoxesStrict;\n};\n\ndefineProperties(ArrayPrototype, {\n forEach: function forEach(fun /*, thisp*/) {\n var object = toObject(this),\n self = splitString && isString(this) ? this.split('') : object,\n thisp = arguments[1],\n i = -1,\n length = self.length >>> 0;\n\n // If no callback function or if callback is not a callable function\n if (!isFunction(fun)) {\n throw new TypeError(); // TODO message\n }\n\n while (++i < length) {\n if (i in self) {\n // Invoke the callback function with call, passing arguments:\n // context, property value, property key, thisArg object\n // context\n fun.call(thisp, self[i], i, object);\n }\n }\n }\n}, !properlyBoxesContext(ArrayPrototype.forEach));\n\n// ES5 15.4.4.14\n// http://es5.github.com/#x15.4.4.14\n// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf\nvar hasFirefox2IndexOfBug = Array.prototype.indexOf && [0, 1].indexOf(1, 2) !== -1;\ndefineProperties(ArrayPrototype, {\n indexOf: function indexOf(sought /*, fromIndex */ ) {\n var self = splitString && isString(this) ? this.split('') : toObject(this),\n length = self.length >>> 0;\n\n if (!length) {\n return -1;\n }\n\n var i = 0;\n if (arguments.length > 1) {\n i = toInteger(arguments[1]);\n }\n\n // handle negative indices\n i = i >= 0 ? i : Math.max(0, length + i);\n for (; i < length; i++) {\n if (i in self && self[i] === sought) {\n return i;\n }\n }\n return -1;\n }\n}, hasFirefox2IndexOfBug);\n\n//\n// String\n// ======\n//\n\n// ES5 15.5.4.14\n// http://es5.github.com/#x15.5.4.14\n\n// [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]\n// Many browsers do not split properly with regular expressions or they\n// do not perform the split correctly under obscure conditions.\n// See http://blog.stevenlevithan.com/archives/cross-browser-split\n// I've tested in many browsers and this seems to cover the deviant ones:\n// 'ab'.split(/(?:ab)*/) should be [\"\", \"\"], not [\"\"]\n// '.'.split(/(.?)(.?)/) should be [\"\", \".\", \"\", \"\"], not [\"\", \"\"]\n// 'tesst'.split(/(s)*/) should be [\"t\", undefined, \"e\", \"s\", \"t\"], not\n// [undefined, \"t\", undefined, \"e\", ...]\n// ''.split(/.?/) should be [], not [\"\"]\n// '.'.split(/()()/) should be [\".\"], not [\"\", \"\", \".\"]\n\nvar string_split = StringPrototype.split;\nif (\n 'ab'.split(/(?:ab)*/).length !== 2 ||\n '.'.split(/(.?)(.?)/).length !== 4 ||\n 'tesst'.split(/(s)*/)[1] === 't' ||\n 'test'.split(/(?:)/, -1).length !== 4 ||\n ''.split(/.?/).length ||\n '.'.split(/()()/).length > 1\n) {\n (function () {\n var compliantExecNpcg = /()??/.exec('')[1] === void 0; // NPCG: nonparticipating capturing group\n\n StringPrototype.split = function (separator, limit) {\n var string = this;\n if (separator === void 0 && limit === 0) {\n return [];\n }\n\n // If `separator` is not a regex, use native split\n if (_toString.call(separator) !== '[object RegExp]') {\n return string_split.call(this, separator, limit);\n }\n\n var output = [],\n flags = (separator.ignoreCase ? 'i' : '') +\n (separator.multiline ? 'm' : '') +\n (separator.extended ? 'x' : '') + // Proposed for ES6\n (separator.sticky ? 'y' : ''), // Firefox 3+\n lastLastIndex = 0,\n // Make `global` and avoid `lastIndex` issues by working with a copy\n separator2, match, lastIndex, lastLength;\n separator = new RegExp(separator.source, flags + 'g');\n string += ''; // Type-convert\n if (!compliantExecNpcg) {\n // Doesn't need flags gy, but they don't hurt\n separator2 = new RegExp('^' + separator.source + '$(?!\\\\s)', flags);\n }\n /* Values for `limit`, per the spec:\n * If undefined: 4294967295 // Math.pow(2, 32) - 1\n * If 0, Infinity, or NaN: 0\n * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;\n * If negative number: 4294967296 - Math.floor(Math.abs(limit))\n * If other: Type-convert, then use the above rules\n */\n limit = limit === void 0 ?\n -1 >>> 0 : // Math.pow(2, 32) - 1\n ToUint32(limit);\n while (match = separator.exec(string)) {\n // `separator.lastIndex` is not reliable cross-browser\n lastIndex = match.index + match[0].length;\n if (lastIndex > lastLastIndex) {\n output.push(string.slice(lastLastIndex, match.index));\n // Fix browsers whose `exec` methods don't consistently return `undefined` for\n // nonparticipating capturing groups\n if (!compliantExecNpcg && match.length > 1) {\n match[0].replace(separator2, function () {\n for (var i = 1; i < arguments.length - 2; i++) {\n if (arguments[i] === void 0) {\n match[i] = void 0;\n }\n }\n });\n }\n if (match.length > 1 && match.index < string.length) {\n ArrayPrototype.push.apply(output, match.slice(1));\n }\n lastLength = match[0].length;\n lastLastIndex = lastIndex;\n if (output.length >= limit) {\n break;\n }\n }\n if (separator.lastIndex === match.index) {\n separator.lastIndex++; // Avoid an infinite loop\n }\n }\n if (lastLastIndex === string.length) {\n if (lastLength || !separator.test('')) {\n output.push('');\n }\n } else {\n output.push(string.slice(lastLastIndex));\n }\n return output.length > limit ? output.slice(0, limit) : output;\n };\n }());\n\n// [bugfix, chrome]\n// If separator is undefined, then the result array contains just one String,\n// which is the this value (converted to a String). If limit is not undefined,\n// then the output array is truncated so that it contains no more than limit\n// elements.\n// \"0\".split(undefined, 0) -> []\n} else if ('0'.split(void 0, 0).length) {\n StringPrototype.split = function split(separator, limit) {\n if (separator === void 0 && limit === 0) { return []; }\n return string_split.call(this, separator, limit);\n };\n}\n\n// ECMA-262, 3rd B.2.3\n// Not an ECMAScript standard, although ECMAScript 3rd Edition has a\n// non-normative section suggesting uniform semantics and it should be\n// normalized across all browsers\n// [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE\nvar string_substr = StringPrototype.substr;\nvar hasNegativeSubstrBug = ''.substr && '0b'.substr(-1) !== 'b';\ndefineProperties(StringPrototype, {\n substr: function substr(start, length) {\n return string_substr.call(\n this,\n start < 0 ? ((start = this.length + start) < 0 ? 0 : start) : start,\n length\n );\n }\n}, hasNegativeSubstrBug);\n","'use strict';\n\nmodule.exports = [\n // streaming transports\n require('./transport/websocket')\n, require('./transport/xhr-streaming')\n, require('./transport/xdr-streaming')\n, require('./transport/eventsource')\n, require('./transport/lib/iframe-wrap')(require('./transport/eventsource'))\n\n // polling transports\n, require('./transport/htmlfile')\n, require('./transport/lib/iframe-wrap')(require('./transport/htmlfile'))\n, require('./transport/xhr-polling')\n, require('./transport/xdr-polling')\n, require('./transport/lib/iframe-wrap')(require('./transport/xhr-polling'))\n, require('./transport/jsonp-polling')\n];\n","'use strict';\n\nvar EventEmitter = require('events').EventEmitter\n , inherits = require('inherits')\n , utils = require('../../utils/event')\n , urlUtils = require('../../utils/url')\n , XHR = global.XMLHttpRequest\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:browser:xhr');\n}\n\nfunction AbstractXHRObject(method, url, payload, opts) {\n debug(method, url);\n var self = this;\n EventEmitter.call(this);\n\n setTimeout(function () {\n self._start(method, url, payload, opts);\n }, 0);\n}\n\ninherits(AbstractXHRObject, EventEmitter);\n\nAbstractXHRObject.prototype._start = function(method, url, payload, opts) {\n var self = this;\n\n try {\n this.xhr = new XHR();\n } catch (x) {\n // intentionally empty\n }\n\n if (!this.xhr) {\n debug('no xhr');\n this.emit('finish', 0, 'no xhr support');\n this._cleanup();\n return;\n }\n\n // several browsers cache POSTs\n url = urlUtils.addQuery(url, 't=' + (+new Date()));\n\n // Explorer tends to keep connection open, even after the\n // tab gets closed: http://bugs.jquery.com/ticket/5280\n this.unloadRef = utils.unloadAdd(function() {\n debug('unload cleanup');\n self._cleanup(true);\n });\n try {\n this.xhr.open(method, url, true);\n if (this.timeout && 'timeout' in this.xhr) {\n this.xhr.timeout = this.timeout;\n this.xhr.ontimeout = function() {\n debug('xhr timeout');\n self.emit('finish', 0, '');\n self._cleanup(false);\n };\n }\n } catch (e) {\n debug('exception', e);\n // IE raises an exception on wrong port.\n this.emit('finish', 0, '');\n this._cleanup(false);\n return;\n }\n\n if ((!opts || !opts.noCredentials) && AbstractXHRObject.supportsCORS) {\n debug('withCredentials');\n // Mozilla docs says https://developer.mozilla.org/en/XMLHttpRequest :\n // \"This never affects same-site requests.\"\n\n this.xhr.withCredentials = 'true';\n }\n if (opts && opts.headers) {\n for (var key in opts.headers) {\n this.xhr.setRequestHeader(key, opts.headers[key]);\n }\n }\n\n this.xhr.onreadystatechange = function() {\n if (self.xhr) {\n var x = self.xhr;\n var text, status;\n debug('readyState', x.readyState);\n switch (x.readyState) {\n case 3:\n // IE doesn't like peeking into responseText or status\n // on Microsoft.XMLHTTP and readystate=3\n try {\n status = x.status;\n text = x.responseText;\n } catch (e) {\n // intentionally empty\n }\n debug('status', status);\n // IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450\n if (status === 1223) {\n status = 204;\n }\n\n // IE does return readystate == 3 for 404 answers.\n if (status === 200 && text && text.length > 0) {\n debug('chunk');\n self.emit('chunk', status, text);\n }\n break;\n case 4:\n status = x.status;\n debug('status', status);\n // IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450\n if (status === 1223) {\n status = 204;\n }\n // IE returns this for a bad port\n // http://msdn.microsoft.com/en-us/library/windows/desktop/aa383770(v=vs.85).aspx\n if (status === 12005 || status === 12029) {\n status = 0;\n }\n\n debug('finish', status, x.responseText);\n self.emit('finish', status, x.responseText);\n self._cleanup(false);\n break;\n }\n }\n };\n\n try {\n self.xhr.send(payload);\n } catch (e) {\n self.emit('finish', 0, '');\n self._cleanup(false);\n }\n};\n\nAbstractXHRObject.prototype._cleanup = function(abort) {\n debug('cleanup');\n if (!this.xhr) {\n return;\n }\n this.removeAllListeners();\n utils.unloadDel(this.unloadRef);\n\n // IE needs this field to be a function\n this.xhr.onreadystatechange = function() {};\n if (this.xhr.ontimeout) {\n this.xhr.ontimeout = null;\n }\n\n if (abort) {\n try {\n this.xhr.abort();\n } catch (x) {\n // intentionally empty\n }\n }\n this.unloadRef = this.xhr = null;\n};\n\nAbstractXHRObject.prototype.close = function() {\n debug('close');\n this._cleanup(true);\n};\n\nAbstractXHRObject.enabled = !!XHR;\n// override XMLHttpRequest for IE6/7\n// obfuscate to avoid firewalls\nvar axo = ['Active'].concat('Object').join('X');\nif (!AbstractXHRObject.enabled && (axo in global)) {\n debug('overriding xmlhttprequest');\n XHR = function() {\n try {\n return new global[axo]('Microsoft.XMLHTTP');\n } catch (e) {\n return null;\n }\n };\n AbstractXHRObject.enabled = !!new XHR();\n}\n\nvar cors = false;\ntry {\n cors = 'withCredentials' in new XHR();\n} catch (ignored) {\n // intentionally empty\n}\n\nAbstractXHRObject.supportsCORS = cors;\n\nmodule.exports = AbstractXHRObject;\n","module.exports = global.EventSource;\n","'use strict';\n\nvar Driver = global.WebSocket || global.MozWebSocket;\nif (Driver) {\n\tmodule.exports = function WebSocketBrowserDriver(url) {\n\t\treturn new Driver(url);\n\t};\n} else {\n\tmodule.exports = undefined;\n}\n","'use strict';\n\nvar inherits = require('inherits')\n , AjaxBasedTransport = require('./lib/ajax-based')\n , EventSourceReceiver = require('./receiver/eventsource')\n , XHRCorsObject = require('./sender/xhr-cors')\n , EventSourceDriver = require('eventsource')\n ;\n\nfunction EventSourceTransport(transUrl) {\n if (!EventSourceTransport.enabled()) {\n throw new Error('Transport created when disabled');\n }\n\n AjaxBasedTransport.call(this, transUrl, '/eventsource', EventSourceReceiver, XHRCorsObject);\n}\n\ninherits(EventSourceTransport, AjaxBasedTransport);\n\nEventSourceTransport.enabled = function() {\n return !!EventSourceDriver;\n};\n\nEventSourceTransport.transportName = 'eventsource';\nEventSourceTransport.roundTrips = 2;\n\nmodule.exports = EventSourceTransport;\n","'use strict';\n\nvar inherits = require('inherits')\n , HtmlfileReceiver = require('./receiver/htmlfile')\n , XHRLocalObject = require('./sender/xhr-local')\n , AjaxBasedTransport = require('./lib/ajax-based')\n ;\n\nfunction HtmlFileTransport(transUrl) {\n if (!HtmlfileReceiver.enabled) {\n throw new Error('Transport created when disabled');\n }\n AjaxBasedTransport.call(this, transUrl, '/htmlfile', HtmlfileReceiver, XHRLocalObject);\n}\n\ninherits(HtmlFileTransport, AjaxBasedTransport);\n\nHtmlFileTransport.enabled = function(info) {\n return HtmlfileReceiver.enabled && info.sameOrigin;\n};\n\nHtmlFileTransport.transportName = 'htmlfile';\nHtmlFileTransport.roundTrips = 2;\n\nmodule.exports = HtmlFileTransport;\n","'use strict';\n\n// Few cool transports do work only for same-origin. In order to make\n// them work cross-domain we shall use iframe, served from the\n// remote domain. New browsers have capabilities to communicate with\n// cross domain iframe using postMessage(). In IE it was implemented\n// from IE 8+, but of course, IE got some details wrong:\n// http://msdn.microsoft.com/en-us/library/cc197015(v=VS.85).aspx\n// http://stevesouders.com/misc/test-postmessage.php\n\nvar inherits = require('inherits')\n , JSON3 = require('json3')\n , EventEmitter = require('events').EventEmitter\n , version = require('../version')\n , urlUtils = require('../utils/url')\n , iframeUtils = require('../utils/iframe')\n , eventUtils = require('../utils/event')\n , random = require('../utils/random')\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:transport:iframe');\n}\n\nfunction IframeTransport(transport, transUrl, baseUrl) {\n if (!IframeTransport.enabled()) {\n throw new Error('Transport created when disabled');\n }\n EventEmitter.call(this);\n\n var self = this;\n this.origin = urlUtils.getOrigin(baseUrl);\n this.baseUrl = baseUrl;\n this.transUrl = transUrl;\n this.transport = transport;\n this.windowId = random.string(8);\n\n var iframeUrl = urlUtils.addPath(baseUrl, '/iframe.html') + '#' + this.windowId;\n debug(transport, transUrl, iframeUrl);\n\n this.iframeObj = iframeUtils.createIframe(iframeUrl, function(r) {\n debug('err callback');\n self.emit('close', 1006, 'Unable to load an iframe (' + r + ')');\n self.close();\n });\n\n this.onmessageCallback = this._message.bind(this);\n eventUtils.attachEvent('message', this.onmessageCallback);\n}\n\ninherits(IframeTransport, EventEmitter);\n\nIframeTransport.prototype.close = function() {\n debug('close');\n this.removeAllListeners();\n if (this.iframeObj) {\n eventUtils.detachEvent('message', this.onmessageCallback);\n try {\n // When the iframe is not loaded, IE raises an exception\n // on 'contentWindow'.\n this.postMessage('c');\n } catch (x) {\n // intentionally empty\n }\n this.iframeObj.cleanup();\n this.iframeObj = null;\n this.onmessageCallback = this.iframeObj = null;\n }\n};\n\nIframeTransport.prototype._message = function(e) {\n debug('message', e.data);\n if (!urlUtils.isOriginEqual(e.origin, this.origin)) {\n debug('not same origin', e.origin, this.origin);\n return;\n }\n\n var iframeMessage;\n try {\n iframeMessage = JSON3.parse(e.data);\n } catch (ignored) {\n debug('bad json', e.data);\n return;\n }\n\n if (iframeMessage.windowId !== this.windowId) {\n debug('mismatched window id', iframeMessage.windowId, this.windowId);\n return;\n }\n\n switch (iframeMessage.type) {\n case 's':\n this.iframeObj.loaded();\n // window global dependency\n this.postMessage('s', JSON3.stringify([\n version\n , this.transport\n , this.transUrl\n , this.baseUrl\n ]));\n break;\n case 't':\n this.emit('message', iframeMessage.data);\n break;\n case 'c':\n var cdata;\n try {\n cdata = JSON3.parse(iframeMessage.data);\n } catch (ignored) {\n debug('bad json', iframeMessage.data);\n return;\n }\n this.emit('close', cdata[0], cdata[1]);\n this.close();\n break;\n }\n};\n\nIframeTransport.prototype.postMessage = function(type, data) {\n debug('postMessage', type, data);\n this.iframeObj.post(JSON3.stringify({\n windowId: this.windowId\n , type: type\n , data: data || ''\n }), this.origin);\n};\n\nIframeTransport.prototype.send = function(message) {\n debug('send', message);\n this.postMessage('m', message);\n};\n\nIframeTransport.enabled = function() {\n return iframeUtils.iframeEnabled;\n};\n\nIframeTransport.transportName = 'iframe';\nIframeTransport.roundTrips = 2;\n\nmodule.exports = IframeTransport;\n","'use strict';\n\n// The simplest and most robust transport, using the well-know cross\n// domain hack - JSONP. This transport is quite inefficient - one\n// message could use up to one http request. But at least it works almost\n// everywhere.\n// Known limitations:\n// o you will get a spinning cursor\n// o for Konqueror a dumb timer is needed to detect errors\n\nvar inherits = require('inherits')\n , SenderReceiver = require('./lib/sender-receiver')\n , JsonpReceiver = require('./receiver/jsonp')\n , jsonpSender = require('./sender/jsonp')\n ;\n\nfunction JsonPTransport(transUrl) {\n if (!JsonPTransport.enabled()) {\n throw new Error('Transport created when disabled');\n }\n SenderReceiver.call(this, transUrl, '/jsonp', jsonpSender, JsonpReceiver);\n}\n\ninherits(JsonPTransport, SenderReceiver);\n\nJsonPTransport.enabled = function() {\n return !!global.document;\n};\n\nJsonPTransport.transportName = 'jsonp-polling';\nJsonPTransport.roundTrips = 1;\nJsonPTransport.needBody = true;\n\nmodule.exports = JsonPTransport;\n","'use strict';\n\nvar inherits = require('inherits')\n , urlUtils = require('../../utils/url')\n , SenderReceiver = require('./sender-receiver')\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:ajax-based');\n}\n\nfunction createAjaxSender(AjaxObject) {\n return function(url, payload, callback) {\n debug('create ajax sender', url, payload);\n var opt = {};\n if (typeof payload === 'string') {\n opt.headers = {'Content-type': 'text/plain'};\n }\n var ajaxUrl = urlUtils.addPath(url, '/xhr_send');\n var xo = new AjaxObject('POST', ajaxUrl, payload, opt);\n xo.once('finish', function(status) {\n debug('finish', status);\n xo = null;\n\n if (status !== 200 && status !== 204) {\n return callback(new Error('http status ' + status));\n }\n callback();\n });\n return function() {\n debug('abort');\n xo.close();\n xo = null;\n\n var err = new Error('Aborted');\n err.code = 1000;\n callback(err);\n };\n };\n}\n\nfunction AjaxBasedTransport(transUrl, urlSuffix, Receiver, AjaxObject) {\n SenderReceiver.call(this, transUrl, urlSuffix, createAjaxSender(AjaxObject), Receiver, AjaxObject);\n}\n\ninherits(AjaxBasedTransport, SenderReceiver);\n\nmodule.exports = AjaxBasedTransport;\n","'use strict';\n\nvar inherits = require('inherits')\n , EventEmitter = require('events').EventEmitter\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:buffered-sender');\n}\n\nfunction BufferedSender(url, sender) {\n debug(url);\n EventEmitter.call(this);\n this.sendBuffer = [];\n this.sender = sender;\n this.url = url;\n}\n\ninherits(BufferedSender, EventEmitter);\n\nBufferedSender.prototype.send = function(message) {\n debug('send', message);\n this.sendBuffer.push(message);\n if (!this.sendStop) {\n this.sendSchedule();\n }\n};\n\n// For polling transports in a situation when in the message callback,\n// new message is being send. If the sending connection was started\n// before receiving one, it is possible to saturate the network and\n// timeout due to the lack of receiving socket. To avoid that we delay\n// sending messages by some small time, in order to let receiving\n// connection be started beforehand. This is only a halfmeasure and\n// does not fix the big problem, but it does make the tests go more\n// stable on slow networks.\nBufferedSender.prototype.sendScheduleWait = function() {\n debug('sendScheduleWait');\n var self = this;\n var tref;\n this.sendStop = function() {\n debug('sendStop');\n self.sendStop = null;\n clearTimeout(tref);\n };\n tref = setTimeout(function() {\n debug('timeout');\n self.sendStop = null;\n self.sendSchedule();\n }, 25);\n};\n\nBufferedSender.prototype.sendSchedule = function() {\n debug('sendSchedule', this.sendBuffer.length);\n var self = this;\n if (this.sendBuffer.length > 0) {\n var payload = '[' + this.sendBuffer.join(',') + ']';\n this.sendStop = this.sender(this.url, payload, function(err) {\n self.sendStop = null;\n if (err) {\n debug('error', err);\n self.emit('close', err.code || 1006, 'Sending error: ' + err);\n self.close();\n } else {\n self.sendScheduleWait();\n }\n });\n this.sendBuffer = [];\n }\n};\n\nBufferedSender.prototype._cleanup = function() {\n debug('_cleanup');\n this.removeAllListeners();\n};\n\nBufferedSender.prototype.close = function() {\n debug('close');\n this._cleanup();\n if (this.sendStop) {\n this.sendStop();\n this.sendStop = null;\n }\n};\n\nmodule.exports = BufferedSender;\n","'use strict';\n\nvar inherits = require('inherits')\n , IframeTransport = require('../iframe')\n , objectUtils = require('../../utils/object')\n ;\n\nmodule.exports = function(transport) {\n\n function IframeWrapTransport(transUrl, baseUrl) {\n IframeTransport.call(this, transport.transportName, transUrl, baseUrl);\n }\n\n inherits(IframeWrapTransport, IframeTransport);\n\n IframeWrapTransport.enabled = function(url, info) {\n if (!global.document) {\n return false;\n }\n\n var iframeInfo = objectUtils.extend({}, info);\n iframeInfo.sameOrigin = true;\n return transport.enabled(iframeInfo) && IframeTransport.enabled();\n };\n\n IframeWrapTransport.transportName = 'iframe-' + transport.transportName;\n IframeWrapTransport.needBody = true;\n IframeWrapTransport.roundTrips = IframeTransport.roundTrips + transport.roundTrips - 1; // html, javascript (2) + transport - no CORS (1)\n\n IframeWrapTransport.facadeTransport = transport;\n\n return IframeWrapTransport;\n};\n","'use strict';\n\nvar inherits = require('inherits')\n , EventEmitter = require('events').EventEmitter\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:polling');\n}\n\nfunction Polling(Receiver, receiveUrl, AjaxObject) {\n debug(receiveUrl);\n EventEmitter.call(this);\n this.Receiver = Receiver;\n this.receiveUrl = receiveUrl;\n this.AjaxObject = AjaxObject;\n this._scheduleReceiver();\n}\n\ninherits(Polling, EventEmitter);\n\nPolling.prototype._scheduleReceiver = function() {\n debug('_scheduleReceiver');\n var self = this;\n var poll = this.poll = new this.Receiver(this.receiveUrl, this.AjaxObject);\n\n poll.on('message', function(msg) {\n debug('message', msg);\n self.emit('message', msg);\n });\n\n poll.once('close', function(code, reason) {\n debug('close', code, reason, self.pollIsClosing);\n self.poll = poll = null;\n\n if (!self.pollIsClosing) {\n if (reason === 'network') {\n self._scheduleReceiver();\n } else {\n self.emit('close', code || 1006, reason);\n self.removeAllListeners();\n }\n }\n });\n};\n\nPolling.prototype.abort = function() {\n debug('abort');\n this.removeAllListeners();\n this.pollIsClosing = true;\n if (this.poll) {\n this.poll.abort();\n }\n};\n\nmodule.exports = Polling;\n","'use strict';\n\nvar inherits = require('inherits')\n , urlUtils = require('../../utils/url')\n , BufferedSender = require('./buffered-sender')\n , Polling = require('./polling')\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:sender-receiver');\n}\n\nfunction SenderReceiver(transUrl, urlSuffix, senderFunc, Receiver, AjaxObject) {\n var pollUrl = urlUtils.addPath(transUrl, urlSuffix);\n debug(pollUrl);\n var self = this;\n BufferedSender.call(this, transUrl, senderFunc);\n\n this.poll = new Polling(Receiver, pollUrl, AjaxObject);\n this.poll.on('message', function(msg) {\n debug('poll message', msg);\n self.emit('message', msg);\n });\n this.poll.once('close', function(code, reason) {\n debug('poll close', code, reason);\n self.poll = null;\n self.emit('close', code, reason);\n self.close();\n });\n}\n\ninherits(SenderReceiver, BufferedSender);\n\nSenderReceiver.prototype.close = function() {\n BufferedSender.prototype.close.call(this);\n debug('close');\n this.removeAllListeners();\n if (this.poll) {\n this.poll.abort();\n this.poll = null;\n }\n};\n\nmodule.exports = SenderReceiver;\n","'use strict';\n\nvar inherits = require('inherits')\n , EventEmitter = require('events').EventEmitter\n , EventSourceDriver = require('eventsource')\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:receiver:eventsource');\n}\n\nfunction EventSourceReceiver(url) {\n debug(url);\n EventEmitter.call(this);\n\n var self = this;\n var es = this.es = new EventSourceDriver(url);\n es.onmessage = function(e) {\n debug('message', e.data);\n self.emit('message', decodeURI(e.data));\n };\n es.onerror = function(e) {\n debug('error', es.readyState, e);\n // ES on reconnection has readyState = 0 or 1.\n // on network error it's CLOSED = 2\n var reason = (es.readyState !== 2 ? 'network' : 'permanent');\n self._cleanup();\n self._close(reason);\n };\n}\n\ninherits(EventSourceReceiver, EventEmitter);\n\nEventSourceReceiver.prototype.abort = function() {\n debug('abort');\n this._cleanup();\n this._close('user');\n};\n\nEventSourceReceiver.prototype._cleanup = function() {\n debug('cleanup');\n var es = this.es;\n if (es) {\n es.onmessage = es.onerror = null;\n es.close();\n this.es = null;\n }\n};\n\nEventSourceReceiver.prototype._close = function(reason) {\n debug('close', reason);\n var self = this;\n // Safari and chrome < 15 crash if we close window before\n // waiting for ES cleanup. See:\n // https://code.google.com/p/chromium/issues/detail?id=89155\n setTimeout(function() {\n self.emit('close', null, reason);\n self.removeAllListeners();\n }, 200);\n};\n\nmodule.exports = EventSourceReceiver;\n","'use strict';\n\nvar inherits = require('inherits')\n , iframeUtils = require('../../utils/iframe')\n , urlUtils = require('../../utils/url')\n , EventEmitter = require('events').EventEmitter\n , random = require('../../utils/random')\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:receiver:htmlfile');\n}\n\nfunction HtmlfileReceiver(url) {\n debug(url);\n EventEmitter.call(this);\n var self = this;\n iframeUtils.polluteGlobalNamespace();\n\n this.id = 'a' + random.string(6);\n url = urlUtils.addQuery(url, 'c=' + decodeURIComponent(iframeUtils.WPrefix + '.' + this.id));\n\n debug('using htmlfile', HtmlfileReceiver.htmlfileEnabled);\n var constructFunc = HtmlfileReceiver.htmlfileEnabled ?\n iframeUtils.createHtmlfile : iframeUtils.createIframe;\n\n global[iframeUtils.WPrefix][this.id] = {\n start: function() {\n debug('start');\n self.iframeObj.loaded();\n }\n , message: function(data) {\n debug('message', data);\n self.emit('message', data);\n }\n , stop: function() {\n debug('stop');\n self._cleanup();\n self._close('network');\n }\n };\n this.iframeObj = constructFunc(url, function() {\n debug('callback');\n self._cleanup();\n self._close('permanent');\n });\n}\n\ninherits(HtmlfileReceiver, EventEmitter);\n\nHtmlfileReceiver.prototype.abort = function() {\n debug('abort');\n this._cleanup();\n this._close('user');\n};\n\nHtmlfileReceiver.prototype._cleanup = function() {\n debug('_cleanup');\n if (this.iframeObj) {\n this.iframeObj.cleanup();\n this.iframeObj = null;\n }\n delete global[iframeUtils.WPrefix][this.id];\n};\n\nHtmlfileReceiver.prototype._close = function(reason) {\n debug('_close', reason);\n this.emit('close', null, reason);\n this.removeAllListeners();\n};\n\nHtmlfileReceiver.htmlfileEnabled = false;\n\n// obfuscate to avoid firewalls\nvar axo = ['Active'].concat('Object').join('X');\nif (axo in global) {\n try {\n HtmlfileReceiver.htmlfileEnabled = !!new global[axo]('htmlfile');\n } catch (x) {\n // intentionally empty\n }\n}\n\nHtmlfileReceiver.enabled = HtmlfileReceiver.htmlfileEnabled || iframeUtils.iframeEnabled;\n\nmodule.exports = HtmlfileReceiver;\n","'use strict';\n\nvar utils = require('../../utils/iframe')\n , random = require('../../utils/random')\n , browser = require('../../utils/browser')\n , urlUtils = require('../../utils/url')\n , inherits = require('inherits')\n , EventEmitter = require('events').EventEmitter\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:receiver:jsonp');\n}\n\nfunction JsonpReceiver(url) {\n debug(url);\n var self = this;\n EventEmitter.call(this);\n\n utils.polluteGlobalNamespace();\n\n this.id = 'a' + random.string(6);\n var urlWithId = urlUtils.addQuery(url, 'c=' + encodeURIComponent(utils.WPrefix + '.' + this.id));\n\n global[utils.WPrefix][this.id] = this._callback.bind(this);\n this._createScript(urlWithId);\n\n // Fallback mostly for Konqueror - stupid timer, 35 seconds shall be plenty.\n this.timeoutId = setTimeout(function() {\n debug('timeout');\n self._abort(new Error('JSONP script loaded abnormally (timeout)'));\n }, JsonpReceiver.timeout);\n}\n\ninherits(JsonpReceiver, EventEmitter);\n\nJsonpReceiver.prototype.abort = function() {\n debug('abort');\n if (global[utils.WPrefix][this.id]) {\n var err = new Error('JSONP user aborted read');\n err.code = 1000;\n this._abort(err);\n }\n};\n\nJsonpReceiver.timeout = 35000;\nJsonpReceiver.scriptErrorTimeout = 1000;\n\nJsonpReceiver.prototype._callback = function(data) {\n debug('_callback', data);\n this._cleanup();\n\n if (this.aborting) {\n return;\n }\n\n if (data) {\n debug('message', data);\n this.emit('message', data);\n }\n this.emit('close', null, 'network');\n this.removeAllListeners();\n};\n\nJsonpReceiver.prototype._abort = function(err) {\n debug('_abort', err);\n this._cleanup();\n this.aborting = true;\n this.emit('close', err.code, err.message);\n this.removeAllListeners();\n};\n\nJsonpReceiver.prototype._cleanup = function() {\n debug('_cleanup');\n clearTimeout(this.timeoutId);\n if (this.script2) {\n this.script2.parentNode.removeChild(this.script2);\n this.script2 = null;\n }\n if (this.script) {\n var script = this.script;\n // Unfortunately, you can't really abort script loading of\n // the script.\n script.parentNode.removeChild(script);\n script.onreadystatechange = script.onerror =\n script.onload = script.onclick = null;\n this.script = null;\n }\n delete global[utils.WPrefix][this.id];\n};\n\nJsonpReceiver.prototype._scriptError = function() {\n debug('_scriptError');\n var self = this;\n if (this.errorTimer) {\n return;\n }\n\n this.errorTimer = setTimeout(function() {\n if (!self.loadedOkay) {\n self._abort(new Error('JSONP script loaded abnormally (onerror)'));\n }\n }, JsonpReceiver.scriptErrorTimeout);\n};\n\nJsonpReceiver.prototype._createScript = function(url) {\n debug('_createScript', url);\n var self = this;\n var script = this.script = global.document.createElement('script');\n var script2; // Opera synchronous load trick.\n\n script.id = 'a' + random.string(8);\n script.src = url;\n script.type = 'text/javascript';\n script.charset = 'UTF-8';\n script.onerror = this._scriptError.bind(this);\n script.onload = function() {\n debug('onload');\n self._abort(new Error('JSONP script loaded abnormally (onload)'));\n };\n\n // IE9 fires 'error' event after onreadystatechange or before, in random order.\n // Use loadedOkay to determine if actually errored\n script.onreadystatechange = function() {\n debug('onreadystatechange', script.readyState);\n if (/loaded|closed/.test(script.readyState)) {\n if (script && script.htmlFor && script.onclick) {\n self.loadedOkay = true;\n try {\n // In IE, actually execute the script.\n script.onclick();\n } catch (x) {\n // intentionally empty\n }\n }\n if (script) {\n self._abort(new Error('JSONP script loaded abnormally (onreadystatechange)'));\n }\n }\n };\n // IE: event/htmlFor/onclick trick.\n // One can't rely on proper order for onreadystatechange. In order to\n // make sure, set a 'htmlFor' and 'event' properties, so that\n // script code will be installed as 'onclick' handler for the\n // script object. Later, onreadystatechange, manually execute this\n // code. FF and Chrome doesn't work with 'event' and 'htmlFor'\n // set. For reference see:\n // http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html\n // Also, read on that about script ordering:\n // http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order\n if (typeof script.async === 'undefined' && global.document.attachEvent) {\n // According to mozilla docs, in recent browsers script.async defaults\n // to 'true', so we may use it to detect a good browser:\n // https://developer.mozilla.org/en/HTML/Element/script\n if (!browser.isOpera()) {\n // Naively assume we're in IE\n try {\n script.htmlFor = script.id;\n script.event = 'onclick';\n } catch (x) {\n // intentionally empty\n }\n script.async = true;\n } else {\n // Opera, second sync script hack\n script2 = this.script2 = global.document.createElement('script');\n script2.text = \"try{var a = document.getElementById('\" + script.id + \"'); if(a)a.onerror();}catch(x){};\";\n script.async = script2.async = false;\n }\n }\n if (typeof script.async !== 'undefined') {\n script.async = true;\n }\n\n var head = global.document.getElementsByTagName('head')[0];\n head.insertBefore(script, head.firstChild);\n if (script2) {\n head.insertBefore(script2, head.firstChild);\n }\n};\n\nmodule.exports = JsonpReceiver;\n","'use strict';\n\nvar inherits = require('inherits')\n , EventEmitter = require('events').EventEmitter\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:receiver:xhr');\n}\n\nfunction XhrReceiver(url, AjaxObject) {\n debug(url);\n EventEmitter.call(this);\n var self = this;\n\n this.bufferPosition = 0;\n\n this.xo = new AjaxObject('POST', url, null);\n this.xo.on('chunk', this._chunkHandler.bind(this));\n this.xo.once('finish', function(status, text) {\n debug('finish', status, text);\n self._chunkHandler(status, text);\n self.xo = null;\n var reason = status === 200 ? 'network' : 'permanent';\n debug('close', reason);\n self.emit('close', null, reason);\n self._cleanup();\n });\n}\n\ninherits(XhrReceiver, EventEmitter);\n\nXhrReceiver.prototype._chunkHandler = function(status, text) {\n debug('_chunkHandler', status);\n if (status !== 200 || !text) {\n return;\n }\n\n for (var idx = -1; ; this.bufferPosition += idx + 1) {\n var buf = text.slice(this.bufferPosition);\n idx = buf.indexOf('\\n');\n if (idx === -1) {\n break;\n }\n var msg = buf.slice(0, idx);\n if (msg) {\n debug('message', msg);\n this.emit('message', msg);\n }\n }\n};\n\nXhrReceiver.prototype._cleanup = function() {\n debug('_cleanup');\n this.removeAllListeners();\n};\n\nXhrReceiver.prototype.abort = function() {\n debug('abort');\n if (this.xo) {\n this.xo.close();\n debug('close');\n this.emit('close', null, 'user');\n this.xo = null;\n }\n this._cleanup();\n};\n\nmodule.exports = XhrReceiver;\n","'use strict';\n\nvar random = require('../../utils/random')\n , urlUtils = require('../../utils/url')\n ;\n\nvar debug = function() {};\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:sender:jsonp');\n}\n\nvar form, area;\n\nfunction createIframe(id) {\n debug('createIframe', id);\n try {\n // ie6 dynamic iframes with target=\"\" support (thanks Chris Lambacher)\n return global.document.createElement('