├── .gitignore ├── public ├── overlay │ ├── youtube-live-chat-sample-avatar.png │ ├── index.html │ └── assets │ │ ├── youtube-chat.css │ │ ├── pushstream.js │ │ └── jquery.js └── index.html ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /public/overlay/youtube-live-chat-sample-avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aaronpk/live-chat-overlay-remote/main/public/overlay/youtube-live-chat-sample-avatar.png -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 |

aaronpk.tv

2 |

Chrome Extension

3 |

Source Code

4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Live Chat Overlay Remote Window 2 | 3 | The remote window for the [Live Chat Overlay](https://github.com/aaronpk/live-chat-overlay) browser extension. 4 | 5 | ## Setup 6 | 7 | You'll need to run this on nginx with the [nginx push-stream module](https://github.com/wandenberg/nginx-push-stream-module). Follow the [installation instructions](https://github.com/wandenberg/nginx-push-stream-module#installation-) to get the module running in your nginx before continuing below. 8 | 9 | ### Configuring nginx 10 | 11 | Once the push-stream module is installed, you can create a server block for this website. 12 | 13 | Download this entire repo into a folder such as `/web/sites/live-chat-overlay-remote`, and configure an nginx server block to point to the `public` folder in the repo. Enable the push-stream module publisher and subscriber using the configuration below. 14 | 15 | ``` 16 | server { 17 | listen *:443 ssl http2; 18 | server_name chat.example.com; 19 | 20 | ssl_certificate /etc/letsencrypt/live/chat.example.com/fullchain.pem; 21 | ssl_certificate_key /etc/letsencrypt/live/chat.example.copm/privkey.pem; 22 | 23 | root /web/sites/live-chat-overlay-remote/public; 24 | index index.html; 25 | 26 | location /overlay/pub { 27 | add_header 'Access-Control-Allow-Origin' '*'; 28 | push_stream_publisher admin; 29 | push_stream_channels_path $arg_id; 30 | } 31 | 32 | location /overlay/sub { 33 | add_header 'Access-Control-Allow-Origin' '*'; 34 | push_stream_subscriber eventsource; 35 | push_stream_channels_path $arg_id; 36 | push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":~text~}"; 37 | push_stream_ping_message_interval 10s; 38 | } 39 | 40 | } 41 | ``` 42 | 43 | That's it! No server-side code environment is needed as the project is static HTML and JavaScript. 44 | 45 | ### Browser Extension Configuration 46 | 47 | In your Live Chat Overlay extension, set the remote URL to the path of the "overlay" folder in this project, for example: `https://chat.example.com/overlay/`. The extension will use that full URL as the main browser source URL, and the extension will expect the `pub` path to exist where it will be pushing the chat messages to. 48 | 49 | -------------------------------------------------------------------------------- /public/overlay/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 12 | 164 | 165 | -------------------------------------------------------------------------------- /public/overlay/assets/youtube-chat.css: -------------------------------------------------------------------------------- 1 | :root { 2 | /* basic colors */ 3 | --keyer-bg-color: transparent; 4 | --comment-color: #fff; 5 | --comment-bg-color: #222; 6 | --comment-border-radius: 0px; 7 | --comment-font-size: 40px; 8 | --author-color: #222; 9 | --author-bg-color: #09e6c1; 10 | --author-avatar-border-color: #09e6c1; 11 | --author-border-radius: 0px; 12 | --author-avatar-border-size: 3px; 13 | --author-avatar-size: 128px; 14 | --author-font-size: 30px; 15 | /* donation/superchat specific */ 16 | --donation-color: #5a4211; 17 | --donation-bg-color: #fff; 18 | --donation-gradient-stop0: #BF953F; 19 | --donation-gradient-stop1: #ede599; 20 | --donation-gradient-stop2: #B38728; 21 | --donation-label-color: #fff; 22 | --donation-label-text: 'SUPERCHAT'; 23 | --donation-shadow-color: #fff; 24 | 25 | --shown-comment-bg-color: #555555; 26 | --highlighted-comment-bg-color: #f0f07d; 27 | 28 | /* 29 | LAYOUT 30 | */ 31 | --comment-width: auto; /* go 100% for a full screen lower third style*/ 32 | --comment-padding: 20px 40px 20px 70px; 33 | --comment-area-height: 30vh; 34 | --comment-scale: 1; 35 | --comment-area-size-offset: 0; 36 | --comment-area-bottom: 10px; 37 | /* 38 | STYLE 39 | */ 40 | --font-family: Avenir Next, Helvetica, Geneva, Verdana, Arial, sans-serif; 41 | --highlight-chat-font-weight: 600; 42 | --author-font-weight: 700; 43 | --comment-font-weight: 600; 44 | } 45 | 46 | body { 47 | background-color: var(--keyer-bg-color); 48 | } 49 | yt-live-chat-app { 50 | margin-bottom: var(--comment-area-height); 51 | height: 100vh !important; 52 | } 53 | .btn-clear { 54 | position: absolute; 55 | z-index: 99999; 56 | bottom: calc(var(--comment-area-height) + 60px); 57 | right: 20px; 58 | font-size: 30px; 59 | border: 1px #bbb solid; 60 | border-radius: 4px; 61 | color: #fff; 62 | background: #444; 63 | } 64 | .highlighted-comment { 65 | background-color: var(--highlighted-comment-bg-color) !important; 66 | } 67 | html[dark] .highlighted-comment #message.yt-live-chat-text-message-renderer { 68 | color: black; 69 | } 70 | html[dark] .highlighted-comment:hover #message.yt-live-chat-text-message-renderer { 71 | color: white; 72 | } 73 | html[dark] .highlighted-comment #author-name.yt-live-chat-author-chip { 74 | color: #444; 75 | } 76 | html[dark] .highlighted-comment:hover #author-name.yt-live-chat-author-chip { 77 | color: #DDD; 78 | } 79 | yt-live-chat-text-message-renderer:hover { 80 | background-color: #eee !important; 81 | } 82 | html[dark] yt-live-chat-text-message-renderer:hover { 83 | background-color: #444 !important; 84 | } 85 | yt-live-chat-text-message-renderer.shown-comment { 86 | background-color: var(--shown-comment-bg-color) !important; 87 | opacity: 0.4; 88 | } 89 | .shown-comment:hover { 90 | opacity: 0.5; 91 | } 92 | highlight-chat { 93 | font-family: var(--font-family); 94 | font-weight: var(--highlight-chat-font-weight); 95 | box-sizing: border-box; 96 | display: block; 97 | position: absolute; 98 | bottom: var(--comment-area-bottom); 99 | left: calc(var(--comment-area-size-offset) * -1px); 100 | right: calc(var(--comment-area-size-offset) * -1px); 101 | width: auto; 102 | height: var(--comment-area-height); 103 | z-index:99999999999; 104 | overflow: hidden; 105 | margin: 0px; 106 | padding: 40px 50px 40px 220px; 107 | background-color: var(--keyer-bg-color); 108 | color: #fff; 109 | font-size: 30px; 110 | transform: scale(var(--comment-scale)); 111 | } 112 | highlight-chat.preview { 113 | border: 1px #ccc solid; 114 | } 115 | .hl-c-cont { 116 | position: relative; 117 | padding: 20px; 118 | width: 100%; 119 | margin: 0 auto; 120 | transition: .5s all cubic-bezier(0.250, 0.250, 0.105, 1.2); 121 | } 122 | .hl-c-cont.fadeout { 123 | transform: translateY(600px); 124 | } 125 | 126 | .hl-name { 127 | position: absolute; 128 | top: -20px; 129 | left: 50px; 130 | font-weight: var(--author-font-weight); 131 | background: var(--author-bg-color); 132 | color: var(--author-color); 133 | padding: 10px; 134 | transform: rotate(-0deg); 135 | z-index: 1; 136 | border-radius: var(--author-border-radius); 137 | font-size: var(--author-font-size); 138 | } 139 | .hl-message { 140 | position: absolute; 141 | width: var(--comment-width); 142 | font-weight: var(--comment-font-weight); 143 | padding: var(--comment-padding); 144 | color: var(--comment-color); 145 | background-color: var(--comment-bg-color); 146 | border-radius: var(--comment-border-radius); 147 | font-size: var(--comment-font-size); 148 | } 149 | .hl-message img { 150 | width: 50px; 151 | vertical-align: middle; 152 | } 153 | .hl-message a { 154 | color: white; 155 | } 156 | .hl-img { 157 | position: absolute; 158 | top: 0; 159 | z-index: 1; 160 | left: -60px; 161 | width: var(--author-avatar-size); 162 | height: var(--author-avatar-size); 163 | background-color: var(--author-avatar-border-color); 164 | border-radius: 50%; 165 | border: 0; 166 | padding: var(--author-avatar-border-size); 167 | } 168 | .hl-img img { 169 | display: block; 170 | width: 100%; 171 | border-radius: 50%; 172 | z-index: 1; 173 | } 174 | /* overlay a very faint white layer to bump the blacks above the luma key cutoff */ 175 | .hl-img:after { 176 | content: ''; 177 | display: block; 178 | height: 100%; 179 | width: 100%; 180 | top: 0; 181 | left: 0; 182 | border-radius: 50%; 183 | position:absolute; 184 | pointer-events: none; 185 | z-index: 3; 186 | } 187 | .hl-img::after { 188 | background: rgba(255,255,255,.04); 189 | mix-blend-mode: lighten; 190 | } 191 | 192 | .hl-badges { 193 | display: inline-block; 194 | margin-left: 10px; 195 | } 196 | .hl-badges img.yt-live-chat-author-badge-renderer { 197 | width: 24px; 198 | height: 24px; 199 | } 200 | 201 | .donation { 202 | position: absolute; 203 | display: block; 204 | text-align: center; 205 | left: 10px; 206 | top: 108px; 207 | z-index: 3; 208 | min-width: 128px; 209 | border-radius: 10px; 210 | padding: 30px 5px 0; 211 | overflow: hidden; 212 | background: linear-gradient(to right, var(--donation-gradient-stop0), var(--donation-gradient-stop1), var(--donation-gradient-stop2)); 213 | color: var(--donation-color); 214 | transform: rotate(-5deg) translateX(-50%); 215 | } 216 | .membership { 217 | padding: 10px 10px 5px 10px; 218 | } 219 | .donation::before { 220 | position: absolute; 221 | top: 0; 222 | left: 0; 223 | width: 100%; 224 | font-size: 18px; 225 | text-align: center; 226 | background-color: rgba(0, 0, 0, 0.23); 227 | border-radius: 10px 10px 0 0; 228 | padding: 5px 0 0; 229 | display: block; 230 | content: var(--donation-label-text); 231 | color: var(--donation-label-color); 232 | } 233 | .membership::before { 234 | content: ''; 235 | } 236 | .donation::after { 237 | content: ''; 238 | position: absolute; 239 | top: -50%; 240 | left: 0; 241 | height: 200%; 242 | width: 1px; 243 | background-color: var(--donation-bg-color); 244 | box-shadow: 0 0 20px 20px var(--donation-shadow-color); 245 | opacity: 0.7; 246 | transform: rotate(9deg) translate3D(250px, 0, 0); 247 | animation: superchat 3s ease-in-out infinite; 248 | } 249 | @keyframes superchat { 250 | from { 251 | transform: rotate(9deg) translate3D(-250px, 0, 0); 252 | } 253 | } 254 | 255 | #tooltip.tp-yt-paper-tooltip { 256 | display: none; 257 | } 258 | 259 | 260 | /* hide chat input to give more space to the chat */ 261 | /* 262 | #input-panel, yt-live-chat-viewer-engagement-message-renderer { 263 | display: none !important; 264 | } 265 | */ 266 | 267 | yt-live-chat-item-list-renderer { 268 | margin-bottom: 20px; 269 | } 270 | 271 | yt-live-chat-text-message-renderer { 272 | font-size: 24px !important; 273 | line-height: 32px; 274 | } 275 | 276 | 277 | yt-live-chat-text-message-renderer, 278 | yt-live-chat-paid-message-renderer, 279 | yt-live-chat-membership-item-renderer { 280 | cursor: pointer; 281 | } 282 | 283 | yt-live-chat-text-message-renderer[is-deleted], 284 | yt-live-chat-paid-message-renderer[is-deleted], 285 | yt-live-chat-membership-item-renderer[is-deleted] { 286 | cursor: default; 287 | } 288 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /public/overlay/assets/pushstream.js: -------------------------------------------------------------------------------- 1 | /*global PushStream WebSocketWrapper EventSourceWrapper EventSource*/ 2 | /*jshint evil: true, plusplus: false, regexp: false */ 3 | /** 4 | The MIT License (MIT) 5 | 6 | Copyright (c) 2010-2014 Wandenberg Peixoto , Rogério Carvalho Schneider 7 | 8 | This file is part of Nginx Push Stream Module. 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | 28 | pushstream.js 29 | 30 | Created: Nov 01, 2011 31 | Authors: Wandenberg Peixoto , Rogério Carvalho Schneider 32 | */ 33 | (function (window, document, undefined) { 34 | "use strict"; 35 | 36 | /* prevent duplicate declaration */ 37 | if (window.PushStream) { return; } 38 | 39 | var Utils = {}; 40 | 41 | var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; 42 | var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; 43 | 44 | var valueToTwoDigits = function (value) { 45 | return ((value < 10) ? '0' : '') + value; 46 | }; 47 | 48 | Utils.dateToUTCString = function (date) { 49 | var time = valueToTwoDigits(date.getUTCHours()) + ':' + valueToTwoDigits(date.getUTCMinutes()) + ':' + valueToTwoDigits(date.getUTCSeconds()); 50 | return days[date.getUTCDay()] + ', ' + valueToTwoDigits(date.getUTCDate()) + ' ' + months[date.getUTCMonth()] + ' ' + date.getUTCFullYear() + ' ' + time + ' GMT'; 51 | }; 52 | 53 | var extend = function () { 54 | var object = arguments[0] || {}; 55 | for (var i = 0; i < arguments.length; i++) { 56 | var settings = arguments[i]; 57 | for (var attr in settings) { 58 | if (!settings.hasOwnProperty || settings.hasOwnProperty(attr)) { 59 | object[attr] = settings[attr]; 60 | } 61 | } 62 | } 63 | return object; 64 | }; 65 | 66 | var validChars = /^[\],:{}\s]*$/, 67 | validEscape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, 68 | validTokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, 69 | validBraces = /(?:^|:|,)(?:\s*\[)+/g; 70 | 71 | var trim = function(value) { 72 | return value.replace(/^\s*/, "").replace(/\s*$/, ""); 73 | }; 74 | 75 | Utils.parseJSON = function(data) { 76 | if (!data || !isString(data)) { 77 | return null; 78 | } 79 | 80 | // Make sure leading/trailing whitespace is removed (IE can't handle it) 81 | data = trim(data); 82 | 83 | // Attempt to parse using the native JSON parser first 84 | if (window.JSON && window.JSON.parse) { 85 | try { 86 | return window.JSON.parse( data ); 87 | } catch(e) { 88 | throw "Invalid JSON: " + data; 89 | } 90 | } 91 | 92 | // Make sure the incoming data is actual JSON 93 | // Logic borrowed from http://json.org/json2.js 94 | if (validChars.test(data.replace(validEscape, "@").replace( validTokens, "]").replace( validBraces, "")) ) { 95 | return (new Function("return " + data))(); 96 | } 97 | 98 | throw "Invalid JSON: " + data; 99 | }; 100 | 101 | var getControlParams = function(pushstream) { 102 | var data = {}; 103 | data[pushstream.tagArgument] = ""; 104 | data[pushstream.timeArgument] = ""; 105 | data[pushstream.eventIdArgument] = ""; 106 | if (pushstream.messagesControlByArgument) { 107 | data[pushstream.tagArgument] = Number(pushstream._etag); 108 | if (pushstream._lastModified) { 109 | data[pushstream.timeArgument] = pushstream._lastModified; 110 | } else if (pushstream._lastEventId) { 111 | data[pushstream.eventIdArgument] = pushstream._lastEventId; 112 | } 113 | } 114 | return data; 115 | }; 116 | 117 | var getTime = function() { 118 | return (new Date()).getTime(); 119 | }; 120 | 121 | var currentTimestampParam = function() { 122 | return { "_" : getTime() }; 123 | }; 124 | 125 | var objectToUrlParams = function(settings) { 126 | var params = settings; 127 | if (typeof(settings) === 'object') { 128 | params = ''; 129 | for (var attr in settings) { 130 | if (!settings.hasOwnProperty || settings.hasOwnProperty(attr)) { 131 | params += '&' + attr + '=' + window.escape(settings[attr]); 132 | } 133 | } 134 | params = params.substring(1); 135 | } 136 | 137 | return params || ''; 138 | }; 139 | 140 | var addParamsToUrl = function(url, params) { 141 | return url + ((url.indexOf('?') < 0) ? '?' : '&') + objectToUrlParams(params); 142 | }; 143 | 144 | var isArray = Array.isArray || function(obj) { 145 | return Object.prototype.toString.call(obj) === '[object Array]'; 146 | }; 147 | 148 | var isString = function(obj) { 149 | return Object.prototype.toString.call(obj) === '[object String]'; 150 | }; 151 | 152 | var isDate = function(obj) { 153 | return Object.prototype.toString.call(obj) === '[object Date]'; 154 | }; 155 | 156 | var Log4js = { 157 | logger: null, 158 | debug : function() { if (PushStream.LOG_LEVEL === 'debug') { Log4js._log.apply(Log4js._log, arguments); }}, 159 | info : function() { if ((PushStream.LOG_LEVEL === 'info') || (PushStream.LOG_LEVEL === 'debug')) { Log4js._log.apply(Log4js._log, arguments); }}, 160 | error : function() { Log4js._log.apply(Log4js._log, arguments); }, 161 | _initLogger : function() { 162 | var console = window.console; 163 | if (console && console.log) { 164 | if (console.log.apply) { 165 | Log4js.logger = console.log; 166 | } else if ((typeof console.log === "object") && Function.prototype.bind) { 167 | Log4js.logger = Function.prototype.bind.call(console.log, console); 168 | } else if ((typeof console.log === "object") && Function.prototype.call) { 169 | Log4js.logger = function() { 170 | Function.prototype.call.call(console.log, console, Array.prototype.slice.call(arguments)); 171 | }; 172 | } 173 | } 174 | }, 175 | _log : function() { 176 | if (!Log4js.logger) { 177 | Log4js._initLogger(); 178 | } 179 | 180 | if (Log4js.logger) { 181 | try { 182 | Log4js.logger.apply(window.console, arguments); 183 | } catch(e) { 184 | Log4js._initLogger(); 185 | if (Log4js.logger) { 186 | Log4js.logger.apply(window.console, arguments); 187 | } 188 | } 189 | } 190 | 191 | var logElement = document.getElementById(PushStream.LOG_OUTPUT_ELEMENT_ID); 192 | if (logElement) { 193 | var str = ''; 194 | for (var i = 0; i < arguments.length; i++) { 195 | str += arguments[i] + " "; 196 | } 197 | logElement.innerHTML += str + '\n'; 198 | 199 | var lines = logElement.innerHTML.split('\n'); 200 | if (lines.length > 100) { 201 | logElement.innerHTML = lines.slice(-100).join('\n'); 202 | } 203 | } 204 | } 205 | }; 206 | 207 | var Ajax = { 208 | _getXHRObject : function(crossDomain) { 209 | var xhr = false; 210 | if (crossDomain) { 211 | try { xhr = new window.XDomainRequest(); } catch (e) { } 212 | if (xhr) { 213 | return xhr; 214 | } 215 | } 216 | 217 | try { xhr = new window.XMLHttpRequest(); } 218 | catch (e1) { 219 | try { xhr = new window.ActiveXObject("Msxml2.XMLHTTP"); } 220 | catch (e2) { 221 | try { xhr = new window.ActiveXObject("Microsoft.XMLHTTP"); } 222 | catch (e3) { 223 | xhr = false; 224 | } 225 | } 226 | } 227 | return xhr; 228 | }, 229 | 230 | _send : function(settings, post) { 231 | settings = settings || {}; 232 | settings.timeout = settings.timeout || 30000; 233 | var xhr = Ajax._getXHRObject(settings.crossDomain); 234 | if (!xhr||!settings.url) { return; } 235 | 236 | Ajax.clear(settings); 237 | 238 | settings.xhr = xhr; 239 | 240 | if (window.XDomainRequest && (xhr instanceof window.XDomainRequest)) { 241 | xhr.onload = function () { 242 | if (settings.afterReceive) { settings.afterReceive(xhr); } 243 | if (settings.success) { settings.success(xhr.responseText); } 244 | }; 245 | 246 | xhr.onerror = xhr.ontimeout = function () { 247 | if (settings.afterReceive) { settings.afterReceive(xhr); } 248 | if (settings.error) { settings.error(xhr.status); } 249 | }; 250 | } else { 251 | xhr.onreadystatechange = function () { 252 | if (xhr.readyState === 4) { 253 | Ajax.clear(settings); 254 | if (settings.afterReceive) { settings.afterReceive(xhr); } 255 | if(xhr.status === 200) { 256 | if (settings.success) { settings.success(xhr.responseText); } 257 | } else { 258 | if (settings.error) { settings.error(xhr.status); } 259 | } 260 | } 261 | }; 262 | } 263 | 264 | if (settings.beforeOpen) { settings.beforeOpen(xhr); } 265 | 266 | var params = {}; 267 | var body = null; 268 | var method = "GET"; 269 | if (post) { 270 | body = objectToUrlParams(settings.data); 271 | method = "POST"; 272 | } else { 273 | params = settings.data || {}; 274 | } 275 | 276 | xhr.open(method, addParamsToUrl(settings.url, extend({}, params, currentTimestampParam())), true); 277 | 278 | if (settings.beforeSend) { settings.beforeSend(xhr); } 279 | 280 | var onerror = function() { 281 | Ajax.clear(settings); 282 | try { xhr.abort(); } catch (e) { /* ignore error on closing */ } 283 | settings.error(304); 284 | }; 285 | 286 | if (post) { 287 | if (xhr.setRequestHeader) { 288 | xhr.setRequestHeader("Accept", "application/json"); 289 | xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 290 | } 291 | } else { 292 | settings.timeoutId = window.setTimeout(onerror, settings.timeout + 2000); 293 | } 294 | 295 | xhr.send(body); 296 | return xhr; 297 | }, 298 | 299 | _clear_xhr : function(xhr) { 300 | if (xhr) { 301 | xhr.onreadystatechange = null; 302 | } 303 | }, 304 | 305 | _clear_script : function(script) { 306 | // Handling memory leak in IE, removing and dereference the script 307 | if (script) { 308 | script.onerror = script.onload = script.onreadystatechange = null; 309 | if (script.parentNode) { script.parentNode.removeChild(script); } 310 | } 311 | }, 312 | 313 | _clear_timeout : function(settings) { 314 | settings.timeoutId = clearTimer(settings.timeoutId); 315 | }, 316 | 317 | _clear_jsonp : function(settings) { 318 | var callbackFunctionName = settings.data.callback; 319 | if (callbackFunctionName) { 320 | window[callbackFunctionName] = function() { window[callbackFunctionName] = null; }; 321 | } 322 | }, 323 | 324 | clear : function(settings) { 325 | Ajax._clear_timeout(settings); 326 | Ajax._clear_jsonp(settings); 327 | Ajax._clear_script(document.getElementById(settings.scriptId)); 328 | Ajax._clear_xhr(settings.xhr); 329 | }, 330 | 331 | jsonp : function(settings) { 332 | settings.timeout = settings.timeout || 30000; 333 | Ajax.clear(settings); 334 | 335 | var head = document.head || document.getElementsByTagName("head")[0]; 336 | var script = document.createElement("script"); 337 | var startTime = getTime(); 338 | 339 | var onerror = function() { 340 | Ajax.clear(settings); 341 | var endTime = getTime(); 342 | settings.error(((endTime - startTime) > settings.timeout/2) ? 304 : 403); 343 | }; 344 | 345 | var onload = function() { 346 | Ajax.clear(settings); 347 | settings.load(); 348 | }; 349 | 350 | var onsuccess = function() { 351 | settings.afterSuccess = true; 352 | settings.success.apply(null, arguments); 353 | }; 354 | 355 | script.onerror = onerror; 356 | script.onload = script.onreadystatechange = function(eventLoad) { 357 | if (!script.readyState || /loaded|complete/.test(script.readyState)) { 358 | if (settings.afterSuccess) { 359 | onload(); 360 | } else { 361 | onerror(); 362 | } 363 | } 364 | }; 365 | 366 | if (settings.beforeOpen) { settings.beforeOpen({}); } 367 | if (settings.beforeSend) { settings.beforeSend({}); } 368 | 369 | settings.timeoutId = window.setTimeout(onerror, settings.timeout + 2000); 370 | settings.scriptId = settings.scriptId || getTime(); 371 | settings.afterSuccess = null; 372 | 373 | settings.data.callback = settings.scriptId + "_onmessage_" + getTime(); 374 | window[settings.data.callback] = onsuccess; 375 | 376 | script.setAttribute("src", addParamsToUrl(settings.url, extend({}, settings.data, currentTimestampParam()))); 377 | script.setAttribute("async", "async"); 378 | script.setAttribute("id", settings.scriptId); 379 | 380 | // Use insertBefore instead of appendChild to circumvent an IE6 bug. 381 | head.insertBefore(script, head.firstChild); 382 | return settings; 383 | }, 384 | 385 | load : function(settings) { 386 | return Ajax._send(settings, false); 387 | }, 388 | 389 | post : function(settings) { 390 | return Ajax._send(settings, true); 391 | } 392 | }; 393 | 394 | var escapeText = function(text) { 395 | return (text) ? window.escape(text) : ''; 396 | }; 397 | 398 | var unescapeText = function(text) { 399 | return (text) ? window.unescape(text) : ''; 400 | }; 401 | 402 | Utils.parseMessage = function(messageText, keys) { 403 | var msg = messageText; 404 | if (isString(messageText)) { 405 | msg = Utils.parseJSON(messageText); 406 | } 407 | var message = { 408 | id : msg[keys.jsonIdKey], 409 | channel: msg[keys.jsonChannelKey], 410 | text : isString(msg[keys.jsonTextKey]) ? unescapeText(msg[keys.jsonTextKey]) : msg[keys.jsonTextKey], 411 | tag : msg[keys.jsonTagKey], 412 | time : msg[keys.jsonTimeKey], 413 | eventid: msg[keys.jsonEventIdKey] || "" 414 | }; 415 | 416 | return message; 417 | }; 418 | 419 | var getBacktrack = function(options) { 420 | return (options.backtrack) ? ".b" + Number(options.backtrack) : ""; 421 | }; 422 | 423 | var getChannelsPath = function(channels, withBacktrack) { 424 | var path = ''; 425 | for (var channelName in channels) { 426 | if (!channels.hasOwnProperty || channels.hasOwnProperty(channelName)) { 427 | path += "/" + channelName + (withBacktrack ? getBacktrack(channels[channelName]) : ""); 428 | } 429 | } 430 | return path; 431 | }; 432 | 433 | var getSubscriberUrl = function(pushstream, prefix, extraParams, withBacktrack) { 434 | var websocket = pushstream.wrapper.type === WebSocketWrapper.TYPE; 435 | var useSSL = pushstream.useSSL; 436 | var port = normalizePort(useSSL, pushstream.port); 437 | var url = (websocket) ? ((useSSL) ? "wss://" : "ws://") : ((useSSL) ? "https://" : "http://"); 438 | url += pushstream.host; 439 | url += (port ? (":" + port) : ""); 440 | url += prefix; 441 | 442 | var channels = getChannelsPath(pushstream.channels, withBacktrack); 443 | if (pushstream.channelsByArgument) { 444 | var channelParam = {}; 445 | channelParam[pushstream.channelsArgument] = channels.substring(1); 446 | extraParams = extend({}, extraParams, channelParam); 447 | } else { 448 | url += channels; 449 | } 450 | return addParamsToUrl(url, extraParams); 451 | }; 452 | 453 | var getPublisherUrl = function(pushstream) { 454 | var port = normalizePort(pushstream.useSSL, pushstream.port); 455 | var url = (pushstream.useSSL) ? "https://" : "http://"; 456 | url += pushstream.host; 457 | url += (port ? (":" + port) : ""); 458 | url += pushstream.urlPrefixPublisher; 459 | url += "?id=" + getChannelsPath(pushstream.channels, false); 460 | 461 | return url; 462 | }; 463 | 464 | Utils.extract_xss_domain = function(domain) { 465 | // if domain is an ip address return it, else return ate least the last two parts of it 466 | if (domain.match(/^(\d{1,3}\.){3}\d{1,3}$/)) { 467 | return domain; 468 | } 469 | 470 | var domainParts = domain.split('.'); 471 | // if the domain ends with 3 chars or 2 chars preceded by more than 4 chars, 472 | // we can keep only 2 parts, else we have to keep at least 3 (or all domain name) 473 | var keepNumber = Math.max(domainParts.length - 1, (domain.match(/(\w{4,}\.\w{2}|\.\w{3,})$/) ? 2 : 3)); 474 | 475 | return domainParts.slice(-1 * keepNumber).join('.'); 476 | }; 477 | 478 | var normalizePort = function (useSSL, port) { 479 | port = Number(port || (useSSL ? 443 : 80)); 480 | return ((!useSSL && port === 80) || (useSSL && port === 443)) ? "" : port; 481 | }; 482 | 483 | Utils.isCrossDomainUrl = function(url) { 484 | if (!url) { 485 | return false; 486 | } 487 | 488 | var parser = document.createElement('a'); 489 | parser.href = url; 490 | 491 | var srcPort = normalizePort(window.location.protocol === "https:", window.location.port); 492 | var dstPort = normalizePort(parser.protocol === "https:", parser.port); 493 | 494 | return (window.location.protocol !== parser.protocol) || 495 | (window.location.hostname !== parser.hostname) || 496 | (srcPort !== dstPort); 497 | }; 498 | 499 | var linker = function(method, instance) { 500 | return function() { 501 | return method.apply(instance, arguments); 502 | }; 503 | }; 504 | 505 | var clearTimer = function(timer) { 506 | if (timer) { 507 | window.clearTimeout(timer); 508 | } 509 | return null; 510 | }; 511 | 512 | /* common callbacks */ 513 | var onmessageCallback = function(event) { 514 | Log4js.info("[" + this.type + "] message received", arguments); 515 | var message = Utils.parseMessage(event.data, this.pushstream); 516 | if (message.tag) { this.pushstream._etag = message.tag; } 517 | if (message.time) { this.pushstream._lastModified = message.time; } 518 | if (message.eventid) { this.pushstream._lastEventId = message.eventid; } 519 | this.pushstream._onmessage(message.text, message.id, message.channel, message.eventid, true); 520 | }; 521 | 522 | var onopenCallback = function() { 523 | this.pushstream._onopen(); 524 | Log4js.info("[" + this.type + "] connection opened"); 525 | }; 526 | 527 | var onerrorCallback = function(event) { 528 | Log4js.info("[" + this.type + "] error (disconnected by server):", event); 529 | if ((this.pushstream.readyState === PushStream.OPEN) && 530 | (this.type === EventSourceWrapper.TYPE) && 531 | (event.type === 'error') && 532 | (this.connection.readyState === window.EventSource.CONNECTING)) { 533 | // EventSource already has a reconnection function using the last-event-id header 534 | return; 535 | } 536 | this._closeCurrentConnection(); 537 | this.pushstream._onerror({type: ((event && ((event.type === "load") || (event.type === "close"))) || (this.pushstream.readyState === PushStream.CONNECTING)) ? "load" : "timeout"}); 538 | }; 539 | 540 | /* wrappers */ 541 | 542 | var WebSocketWrapper = function(pushstream) { 543 | if (!window.WebSocket && !window.MozWebSocket) { throw "WebSocket not supported"; } 544 | this.type = WebSocketWrapper.TYPE; 545 | this.pushstream = pushstream; 546 | this.connection = null; 547 | }; 548 | 549 | WebSocketWrapper.TYPE = "WebSocket"; 550 | 551 | WebSocketWrapper.prototype = { 552 | connect: function() { 553 | this._closeCurrentConnection(); 554 | var params = extend({}, this.pushstream.extraParams(), currentTimestampParam(), getControlParams(this.pushstream)); 555 | var url = getSubscriberUrl(this.pushstream, this.pushstream.urlPrefixWebsocket, params, !this.pushstream._useControlArguments()); 556 | this.connection = (window.WebSocket) ? new window.WebSocket(url) : new window.MozWebSocket(url); 557 | this.connection.onerror = linker(onerrorCallback, this); 558 | this.connection.onclose = linker(onerrorCallback, this); 559 | this.connection.onopen = linker(onopenCallback, this); 560 | this.connection.onmessage = linker(onmessageCallback, this); 561 | Log4js.info("[WebSocket] connecting to:", url); 562 | }, 563 | 564 | disconnect: function() { 565 | if (this.connection) { 566 | Log4js.debug("[WebSocket] closing connection to:", this.connection.url); 567 | this.connection.onclose = null; 568 | this._closeCurrentConnection(); 569 | this.pushstream._onclose(); 570 | } 571 | }, 572 | 573 | _closeCurrentConnection: function() { 574 | if (this.connection) { 575 | try { this.connection.close(); } catch (e) { /* ignore error on closing */ } 576 | this.connection = null; 577 | } 578 | }, 579 | 580 | sendMessage: function(message) { 581 | if (this.connection) { this.connection.send(message); } 582 | } 583 | }; 584 | 585 | var EventSourceWrapper = function(pushstream) { 586 | if (!window.EventSource) { throw "EventSource not supported"; } 587 | this.type = EventSourceWrapper.TYPE; 588 | this.pushstream = pushstream; 589 | this.connection = null; 590 | }; 591 | 592 | EventSourceWrapper.TYPE = "EventSource"; 593 | 594 | EventSourceWrapper.prototype = { 595 | connect: function() { 596 | this._closeCurrentConnection(); 597 | var params = extend({}, this.pushstream.extraParams(), currentTimestampParam(), getControlParams(this.pushstream)); 598 | var url = getSubscriberUrl(this.pushstream, this.pushstream.urlPrefixEventsource, params, !this.pushstream._useControlArguments()); 599 | this.connection = new window.EventSource(url); 600 | this.connection.onerror = linker(onerrorCallback, this); 601 | this.connection.onopen = linker(onopenCallback, this); 602 | this.connection.onmessage = linker(onmessageCallback, this); 603 | Log4js.info("[EventSource] connecting to:", url); 604 | }, 605 | 606 | disconnect: function() { 607 | if (this.connection) { 608 | Log4js.debug("[EventSource] closing connection to:", this.connection.url); 609 | this.connection.onclose = null; 610 | this._closeCurrentConnection(); 611 | this.pushstream._onclose(); 612 | } 613 | }, 614 | 615 | _closeCurrentConnection: function() { 616 | if (this.connection) { 617 | try { this.connection.close(); } catch (e) { /* ignore error on closing */ } 618 | this.connection = null; 619 | } 620 | } 621 | }; 622 | 623 | var StreamWrapper = function(pushstream) { 624 | this.type = StreamWrapper.TYPE; 625 | this.pushstream = pushstream; 626 | this.connection = null; 627 | this.url = null; 628 | this.frameloadtimer = null; 629 | this.pingtimer = null; 630 | this.iframeId = "PushStreamManager_" + pushstream.id; 631 | }; 632 | 633 | StreamWrapper.TYPE = "Stream"; 634 | 635 | StreamWrapper.prototype = { 636 | connect: function() { 637 | this._closeCurrentConnection(); 638 | var domain = Utils.extract_xss_domain(this.pushstream.host); 639 | try { 640 | document.domain = domain; 641 | } catch(e) { 642 | Log4js.error("[Stream] (warning) problem setting document.domain = " + domain + " (OBS: IE8 does not support set IP numbers as domain)"); 643 | } 644 | var params = extend({}, this.pushstream.extraParams(), currentTimestampParam(), {"streamid": this.pushstream.id}, getControlParams(this.pushstream)); 645 | this.url = getSubscriberUrl(this.pushstream, this.pushstream.urlPrefixStream, params, !this.pushstream._useControlArguments()); 646 | Log4js.debug("[Stream] connecting to:", this.url); 647 | this.loadFrame(this.url); 648 | }, 649 | 650 | disconnect: function() { 651 | if (this.connection) { 652 | Log4js.debug("[Stream] closing connection to:", this.url); 653 | this._closeCurrentConnection(); 654 | this.pushstream._onclose(); 655 | } 656 | }, 657 | 658 | _clear_iframe: function() { 659 | var oldIframe = document.getElementById(this.iframeId); 660 | if (oldIframe) { 661 | oldIframe.onload = null; 662 | oldIframe.src = "about:blank"; 663 | if (oldIframe.parentNode) { oldIframe.parentNode.removeChild(oldIframe); } 664 | } 665 | }, 666 | 667 | _closeCurrentConnection: function() { 668 | this._clear_iframe(); 669 | if (this.connection) { 670 | this.pingtimer = clearTimer(this.pingtimer); 671 | this.frameloadtimer = clearTimer(this.frameloadtimer); 672 | this.connection = null; 673 | this.transferDoc = null; 674 | if (typeof window.CollectGarbage === 'function') { window.CollectGarbage(); } 675 | } 676 | }, 677 | 678 | loadFrame: function(url) { 679 | this._clear_iframe(); 680 | 681 | var ifr = null; 682 | if ("ActiveXObject" in window) { 683 | var transferDoc = new window.ActiveXObject("htmlfile"); 684 | transferDoc.open(); 685 | transferDoc.write(""); 686 | transferDoc.parentWindow.PushStream = PushStream; 687 | transferDoc.close(); 688 | ifr = transferDoc.getElementById(this.iframeId); 689 | this.transferDoc = transferDoc; 690 | } else { 691 | ifr = document.createElement("IFRAME"); 692 | ifr.style.width = "1px"; 693 | ifr.style.height = "1px"; 694 | ifr.style.border = "none"; 695 | ifr.style.position = "absolute"; 696 | ifr.style.top = "-10px"; 697 | ifr.style.marginTop = "-10px"; 698 | ifr.style.zIndex = "-20"; 699 | ifr.PushStream = PushStream; 700 | document.body.appendChild(ifr); 701 | ifr.setAttribute("src", url); 702 | ifr.setAttribute("id", this.iframeId); 703 | } 704 | 705 | ifr.onload = linker(onerrorCallback, this); 706 | this.connection = ifr; 707 | this.frameloadtimer = window.setTimeout(linker(onerrorCallback, this), this.pushstream.timeout); 708 | }, 709 | 710 | register: function(iframeWindow) { 711 | this.frameloadtimer = clearTimer(this.frameloadtimer); 712 | iframeWindow.p = linker(this.process, this); 713 | this.connection.onload = linker(this._onframeloaded, this); 714 | this.pushstream._onopen(); 715 | this.setPingTimer(); 716 | Log4js.info("[Stream] frame registered"); 717 | }, 718 | 719 | process: function(id, channel, text, eventid, time, tag) { 720 | this.pingtimer = clearTimer(this.pingtimer); 721 | Log4js.info("[Stream] message received", arguments); 722 | if (id !== -1) { 723 | if (tag) { this.pushstream._etag = tag; } 724 | if (time) { this.pushstream._lastModified = time; } 725 | if (eventid) { this.pushstream._lastEventId = eventid; } 726 | } 727 | this.pushstream._onmessage(unescapeText(text), id, channel, eventid || "", true); 728 | this.setPingTimer(); 729 | }, 730 | 731 | _onframeloaded: function() { 732 | Log4js.info("[Stream] frame loaded (disconnected by server)"); 733 | this.connection.onload = null; 734 | this.disconnect(); 735 | }, 736 | 737 | setPingTimer: function() { 738 | if (this.pingtimer) { clearTimer(this.pingtimer); } 739 | this.pingtimer = window.setTimeout(linker(onerrorCallback, this), this.pushstream.pingtimeout); 740 | } 741 | }; 742 | 743 | var LongPollingWrapper = function(pushstream) { 744 | this.type = LongPollingWrapper.TYPE; 745 | this.pushstream = pushstream; 746 | this.connection = null; 747 | this.opentimer = null; 748 | this.messagesQueue = []; 749 | this._linkedInternalListen = linker(this._internalListen, this); 750 | this.xhrSettings = { 751 | timeout: this.pushstream.timeout, 752 | data: {}, 753 | url: null, 754 | success: linker(this.onmessage, this), 755 | error: linker(this.onerror, this), 756 | load: linker(this.onload, this), 757 | beforeSend: linker(this.beforeSend, this), 758 | afterReceive: linker(this.afterReceive, this) 759 | }; 760 | }; 761 | 762 | LongPollingWrapper.TYPE = "LongPolling"; 763 | 764 | LongPollingWrapper.prototype = { 765 | connect: function() { 766 | this.messagesQueue = []; 767 | this._closeCurrentConnection(); 768 | this.urlWithBacktrack = getSubscriberUrl(this.pushstream, this.pushstream.urlPrefixLongpolling, {}, true); 769 | this.urlWithoutBacktrack = getSubscriberUrl(this.pushstream, this.pushstream.urlPrefixLongpolling, {}, false); 770 | this.xhrSettings.url = this.urlWithBacktrack; 771 | this.useJSONP = this.pushstream._crossDomain || this.pushstream.useJSONP; 772 | this.xhrSettings.scriptId = "PushStreamManager_" + this.pushstream.id; 773 | if (this.useJSONP) { 774 | this.pushstream.messagesControlByArgument = true; 775 | } 776 | this._listen(); 777 | this.opentimer = window.setTimeout(linker(onopenCallback, this), 150); 778 | Log4js.info("[LongPolling] connecting to:", this.xhrSettings.url); 779 | }, 780 | 781 | _listen: function() { 782 | if (this._internalListenTimeout) { clearTimer(this._internalListenTimeout); } 783 | this._internalListenTimeout = window.setTimeout(this._linkedInternalListen, 100); 784 | }, 785 | 786 | _internalListen: function() { 787 | if (this.pushstream._keepConnected) { 788 | this.xhrSettings.url = this.pushstream._useControlArguments() ? this.urlWithoutBacktrack : this.urlWithBacktrack; 789 | this.xhrSettings.data = extend({}, this.pushstream.extraParams(), this.xhrSettings.data, getControlParams(this.pushstream)); 790 | if (this.useJSONP) { 791 | this.connection = Ajax.jsonp(this.xhrSettings); 792 | } else if (!this.connection) { 793 | this.connection = Ajax.load(this.xhrSettings); 794 | } 795 | } 796 | }, 797 | 798 | disconnect: function() { 799 | if (this.connection) { 800 | Log4js.debug("[LongPolling] closing connection to:", this.xhrSettings.url); 801 | this._closeCurrentConnection(); 802 | this.pushstream._onclose(); 803 | } 804 | }, 805 | 806 | _closeCurrentConnection: function() { 807 | this.opentimer = clearTimer(this.opentimer); 808 | if (this.connection) { 809 | try { this.connection.abort(); } catch (e) { 810 | try { Ajax.clear(this.connection); } catch (e1) { /* ignore error on closing */ } 811 | } 812 | this.connection = null; 813 | this.xhrSettings.url = null; 814 | } 815 | }, 816 | 817 | beforeSend: function(xhr) { 818 | if (!this.pushstream.messagesControlByArgument) { 819 | xhr.setRequestHeader("If-None-Match", this.pushstream._etag); 820 | xhr.setRequestHeader("If-Modified-Since", this.pushstream._lastModified); 821 | } 822 | }, 823 | 824 | afterReceive: function(xhr) { 825 | if (!this.pushstream.messagesControlByArgument) { 826 | this.pushstream._etag = xhr.getResponseHeader('Etag'); 827 | this.pushstream._lastModified = xhr.getResponseHeader('Last-Modified'); 828 | } 829 | this.connection = null; 830 | }, 831 | 832 | onerror: function(status) { 833 | this._closeCurrentConnection(); 834 | if (this.pushstream._keepConnected) { /* abort(), called by disconnect(), call this callback, but should be ignored */ 835 | if (status === 304) { 836 | this._listen(); 837 | } else { 838 | Log4js.info("[LongPolling] error (disconnected by server):", status); 839 | this.pushstream._onerror({type: ((status === 403) || (this.pushstream.readyState === PushStream.CONNECTING)) ? "load" : "timeout"}); 840 | } 841 | } 842 | }, 843 | 844 | onload: function() { 845 | this._listen(); 846 | }, 847 | 848 | onmessage: function(responseText) { 849 | if (this._internalListenTimeout) { clearTimer(this._internalListenTimeout); } 850 | Log4js.info("[LongPolling] message received", responseText); 851 | var lastMessage = null; 852 | var messages = isArray(responseText) ? responseText : responseText.replace(/\}\{/g, "}\r\n{").split("\r\n"); 853 | for (var i = 0; i < messages.length; i++) { 854 | if (messages[i]) { 855 | lastMessage = Utils.parseMessage(messages[i], this.pushstream); 856 | this.messagesQueue.push(lastMessage); 857 | if (this.pushstream.messagesControlByArgument && lastMessage.time) { 858 | this.pushstream._etag = lastMessage.tag; 859 | this.pushstream._lastModified = lastMessage.time; 860 | } 861 | } 862 | } 863 | 864 | this._listen(); 865 | 866 | while (this.messagesQueue.length > 0) { 867 | var message = this.messagesQueue.shift(); 868 | this.pushstream._onmessage(message.text, message.id, message.channel, message.eventid, (this.messagesQueue.length === 0)); 869 | } 870 | } 871 | }; 872 | 873 | /* mains class */ 874 | 875 | var PushStreamManager = []; 876 | 877 | var PushStream = function(settings) { 878 | settings = settings || {}; 879 | 880 | this.id = PushStreamManager.push(this) - 1; 881 | 882 | this.useSSL = settings.useSSL || false; 883 | this.host = settings.host || window.location.hostname; 884 | this.port = Number(settings.port || (this.useSSL ? 443 : 80)); 885 | 886 | this.timeout = settings.timeout || 30000; 887 | this.pingtimeout = settings.pingtimeout || 30000; 888 | this.reconnectOnTimeoutInterval = settings.reconnectOnTimeoutInterval || 3000; 889 | this.reconnectOnChannelUnavailableInterval = settings.reconnectOnChannelUnavailableInterval || 60000; 890 | 891 | this.lastEventId = settings.lastEventId || null; 892 | this.messagesPublishedAfter = settings.messagesPublishedAfter; 893 | this.messagesControlByArgument = settings.messagesControlByArgument || false; 894 | this.tagArgument = settings.tagArgument || 'tag'; 895 | this.timeArgument = settings.timeArgument || 'time'; 896 | this.eventIdArgument = settings.eventIdArgument || 'eventid'; 897 | this.useJSONP = settings.useJSONP || false; 898 | 899 | this._reconnecttimer = null; 900 | this._etag = 0; 901 | this._lastModified = null; 902 | this._lastEventId = null; 903 | 904 | this.urlPrefixPublisher = settings.urlPrefixPublisher || '/pub'; 905 | this.urlPrefixStream = settings.urlPrefixStream || '/sub'; 906 | this.urlPrefixEventsource = settings.urlPrefixEventsource || '/ev'; 907 | this.urlPrefixLongpolling = settings.urlPrefixLongpolling || '/lp'; 908 | this.urlPrefixWebsocket = settings.urlPrefixWebsocket || '/ws'; 909 | 910 | this.jsonIdKey = settings.jsonIdKey || 'id'; 911 | this.jsonChannelKey = settings.jsonChannelKey || 'channel'; 912 | this.jsonTextKey = settings.jsonTextKey || 'text'; 913 | this.jsonTagKey = settings.jsonTagKey || 'tag'; 914 | this.jsonTimeKey = settings.jsonTimeKey || 'time'; 915 | this.jsonEventIdKey = settings.jsonEventIdKey || 'eventid'; 916 | 917 | this.modes = (settings.modes || 'eventsource|websocket|stream|longpolling').split('|'); 918 | this.wrappers = []; 919 | this.wrapper = null; 920 | 921 | this.onchanneldeleted = settings.onchanneldeleted || null; 922 | this.onmessage = settings.onmessage || null; 923 | this.onerror = settings.onerror || null; 924 | this.onstatuschange = settings.onstatuschange || null; 925 | this.extraParams = settings.extraParams || function() { return {}; }; 926 | 927 | this.channels = {}; 928 | this.channelsCount = 0; 929 | this.channelsByArgument = settings.channelsByArgument || false; 930 | this.channelsArgument = settings.channelsArgument || 'channels'; 931 | 932 | this._crossDomain = Utils.isCrossDomainUrl(getPublisherUrl(this)); 933 | 934 | for (var i = 0; i < this.modes.length; i++) { 935 | try { 936 | var wrapper = null; 937 | switch (this.modes[i]) { 938 | case "websocket" : wrapper = new WebSocketWrapper(this); break; 939 | case "eventsource": wrapper = new EventSourceWrapper(this); break; 940 | case "longpolling": wrapper = new LongPollingWrapper(this); break; 941 | case "stream" : wrapper = new StreamWrapper(this); break; 942 | } 943 | this.wrappers[this.wrappers.length] = wrapper; 944 | } catch(e) { Log4js.info(e); } 945 | } 946 | 947 | this.readyState = 0; 948 | }; 949 | 950 | /* constants */ 951 | PushStream.LOG_LEVEL = 'error'; /* debug, info, error */ 952 | PushStream.LOG_OUTPUT_ELEMENT_ID = 'Log4jsLogOutput'; 953 | 954 | /* status codes */ 955 | PushStream.CLOSED = 0; 956 | PushStream.CONNECTING = 1; 957 | PushStream.OPEN = 2; 958 | 959 | /* main code */ 960 | PushStream.prototype = { 961 | addChannel: function(channel, options) { 962 | if (escapeText(channel) !== channel) { 963 | throw "Invalid channel name! Channel has to be a set of [a-zA-Z0-9]"; 964 | } 965 | Log4js.debug("entering addChannel"); 966 | if (typeof(this.channels[channel]) !== "undefined") { throw "Cannot add channel " + channel + ": already subscribed"; } 967 | options = options || {}; 968 | Log4js.info("adding channel", channel, options); 969 | this.channels[channel] = options; 970 | this.channelsCount++; 971 | if (this.readyState !== PushStream.CLOSED) { this.connect(); } 972 | Log4js.debug("leaving addChannel"); 973 | }, 974 | 975 | removeChannel: function(channel) { 976 | if (this.channels[channel]) { 977 | Log4js.info("removing channel", channel); 978 | delete this.channels[channel]; 979 | this.channelsCount--; 980 | } 981 | }, 982 | 983 | removeAllChannels: function() { 984 | Log4js.info("removing all channels"); 985 | this.channels = {}; 986 | this.channelsCount = 0; 987 | }, 988 | 989 | _setState: function(state) { 990 | if (this.readyState !== state) { 991 | Log4js.info("status changed", state); 992 | this.readyState = state; 993 | if (this.onstatuschange) { 994 | this.onstatuschange(this.readyState); 995 | } 996 | } 997 | }, 998 | 999 | connect: function() { 1000 | Log4js.debug("entering connect"); 1001 | if (!this.host) { throw "PushStream host not specified"; } 1002 | if (isNaN(this.port)) { throw "PushStream port not specified"; } 1003 | if (!this.channelsCount) { throw "No channels specified"; } 1004 | if (this.wrappers.length === 0) { throw "No available support for this browser"; } 1005 | 1006 | this._keepConnected = true; 1007 | this._lastUsedMode = 0; 1008 | this._connect(); 1009 | 1010 | Log4js.debug("leaving connect"); 1011 | }, 1012 | 1013 | disconnect: function() { 1014 | Log4js.debug("entering disconnect"); 1015 | this._keepConnected = false; 1016 | this._disconnect(); 1017 | this._setState(PushStream.CLOSED); 1018 | Log4js.info("disconnected"); 1019 | Log4js.debug("leaving disconnect"); 1020 | }, 1021 | 1022 | _useControlArguments :function() { 1023 | return this.messagesControlByArgument && ((this._lastModified !== null) || (this._lastEventId !== null)); 1024 | }, 1025 | 1026 | _connect: function() { 1027 | if (this._lastEventId === null) { 1028 | this._lastEventId = this.lastEventId; 1029 | } 1030 | if (this._lastModified === null) { 1031 | var date = this.messagesPublishedAfter; 1032 | if (!isDate(date)) { 1033 | var messagesPublishedAfter = Number(this.messagesPublishedAfter); 1034 | if (messagesPublishedAfter > 0) { 1035 | date = new Date(); 1036 | date.setTime(date.getTime() - (messagesPublishedAfter * 1000)); 1037 | } else if (messagesPublishedAfter < 0) { 1038 | date = new Date(0); 1039 | } 1040 | } 1041 | 1042 | if (isDate(date)) { 1043 | this._lastModified = Utils.dateToUTCString(date); 1044 | } 1045 | } 1046 | 1047 | this._disconnect(); 1048 | this._setState(PushStream.CONNECTING); 1049 | this.wrapper = this.wrappers[this._lastUsedMode++ % this.wrappers.length]; 1050 | 1051 | try { 1052 | this.wrapper.connect(); 1053 | } catch (e) { 1054 | //each wrapper has a cleanup routine at disconnect method 1055 | if (this.wrapper) { 1056 | this.wrapper.disconnect(); 1057 | } 1058 | } 1059 | }, 1060 | 1061 | _disconnect: function() { 1062 | this._reconnecttimer = clearTimer(this._reconnecttimer); 1063 | if (this.wrapper) { 1064 | this.wrapper.disconnect(); 1065 | } 1066 | }, 1067 | 1068 | _onopen: function() { 1069 | this._reconnecttimer = clearTimer(this._reconnecttimer); 1070 | this._setState(PushStream.OPEN); 1071 | if (this._lastUsedMode > 0) { 1072 | this._lastUsedMode--; //use same mode on next connection 1073 | } 1074 | }, 1075 | 1076 | _onclose: function() { 1077 | this._reconnecttimer = clearTimer(this._reconnecttimer); 1078 | this._setState(PushStream.CLOSED); 1079 | this._reconnect(this.reconnectOnTimeoutInterval); 1080 | }, 1081 | 1082 | _onmessage: function(text, id, channel, eventid, isLastMessageFromBatch) { 1083 | Log4js.debug("message", text, id, channel, eventid, isLastMessageFromBatch); 1084 | if (id === -2) { 1085 | if (this.onchanneldeleted) { this.onchanneldeleted(channel); } 1086 | } else if (id > 0) { 1087 | if (this.onmessage) { this.onmessage(text, id, channel, eventid, isLastMessageFromBatch); } 1088 | } 1089 | }, 1090 | 1091 | _onerror: function(error) { 1092 | this._setState(PushStream.CLOSED); 1093 | this._reconnect((error.type === "timeout") ? this.reconnectOnTimeoutInterval : this.reconnectOnChannelUnavailableInterval); 1094 | if (this.onerror) { this.onerror(error); } 1095 | }, 1096 | 1097 | _reconnect: function(timeout) { 1098 | if (this._keepConnected && !this._reconnecttimer && (this.readyState !== PushStream.CONNECTING)) { 1099 | Log4js.info("trying to reconnect in", timeout); 1100 | this._reconnecttimer = window.setTimeout(linker(this._connect, this), timeout); 1101 | } 1102 | }, 1103 | 1104 | sendMessage: function(message, successCallback, errorCallback) { 1105 | message = escapeText(message); 1106 | if (this.wrapper.type === WebSocketWrapper.TYPE) { 1107 | this.wrapper.sendMessage(message); 1108 | if (successCallback) { successCallback(); } 1109 | } else { 1110 | Ajax.post({url: getPublisherUrl(this), data: message, success: successCallback, error: errorCallback, crossDomain: this._crossDomain}); 1111 | } 1112 | } 1113 | }; 1114 | 1115 | PushStream.sendMessage = function(url, message, successCallback, errorCallback) { 1116 | Ajax.post({url: url, data: escapeText(message), success: successCallback, error: errorCallback}); 1117 | }; 1118 | 1119 | // to make server header template more clear, it calls register and 1120 | // by a url parameter we find the stream wrapper instance 1121 | PushStream.register = function(iframe) { 1122 | var matcher = iframe.window.location.href.match(/streamid=([0-9]*)&?/); 1123 | if (matcher[1] && PushStreamManager[matcher[1]]) { 1124 | PushStreamManager[matcher[1]].wrapper.register(iframe); 1125 | } 1126 | }; 1127 | 1128 | PushStream.unload = function() { 1129 | for (var i = 0; i < PushStreamManager.length; i++) { 1130 | try { PushStreamManager[i].disconnect(); } catch(e){} 1131 | } 1132 | }; 1133 | 1134 | /* make class public */ 1135 | window.PushStream = PushStream; 1136 | window.PushStreamManager = PushStreamManager; 1137 | 1138 | if (window.attachEvent) { window.attachEvent("onunload", PushStream.unload); } 1139 | if (window.addEventListener) { window.addEventListener.call(window, "unload", PushStream.unload, false); } 1140 | 1141 | })(window, document); 1142 | -------------------------------------------------------------------------------- /public/overlay/assets/jquery.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v3.5.1 | (c) JS Foundation and other contributors | jquery.org/license */ 2 | !function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(C,e){"use strict";var t=[],r=Object.getPrototypeOf,s=t.slice,g=t.flat?function(e){return t.flat.call(e)}:function(e){return t.concat.apply([],e)},u=t.push,i=t.indexOf,n={},o=n.toString,v=n.hasOwnProperty,a=v.toString,l=a.call(Object),y={},m=function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},x=function(e){return null!=e&&e===e.window},E=C.document,c={type:!0,src:!0,nonce:!0,noModule:!0};function b(e,t,n){var r,i,o=(n=n||E).createElement("script");if(o.text=e,t)for(r in c)(i=t[r]||t.getAttribute&&t.getAttribute(r))&&o.setAttribute(r,i);n.head.appendChild(o).parentNode.removeChild(o)}function w(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[o.call(e)]||"object":typeof e}var f="3.5.1",S=function(e,t){return new S.fn.init(e,t)};function p(e){var t=!!e&&"length"in e&&e.length,n=w(e);return!m(e)&&!x(e)&&("array"===n||0===t||"number"==typeof t&&0+~]|"+M+")"+M+"*"),U=new RegExp(M+"|>"),X=new RegExp(F),V=new RegExp("^"+I+"$"),G={ID:new RegExp("^#("+I+")"),CLASS:new RegExp("^\\.("+I+")"),TAG:new RegExp("^("+I+"|[*])"),ATTR:new RegExp("^"+W),PSEUDO:new RegExp("^"+F),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+R+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/HTML$/i,Q=/^(?:input|select|textarea|button)$/i,J=/^h\d$/i,K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ee=/[+~]/,te=new RegExp("\\\\[\\da-fA-F]{1,6}"+M+"?|\\\\([^\\r\\n\\f])","g"),ne=function(e,t){var n="0x"+e.slice(1)-65536;return t||(n<0?String.fromCharCode(n+65536):String.fromCharCode(n>>10|55296,1023&n|56320))},re=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,ie=function(e,t){return t?"\0"===e?"\ufffd":e.slice(0,-1)+"\\"+e.charCodeAt(e.length-1).toString(16)+" ":"\\"+e},oe=function(){T()},ae=be(function(e){return!0===e.disabled&&"fieldset"===e.nodeName.toLowerCase()},{dir:"parentNode",next:"legend"});try{H.apply(t=O.call(p.childNodes),p.childNodes),t[p.childNodes.length].nodeType}catch(e){H={apply:t.length?function(e,t){L.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function se(t,e,n,r){var i,o,a,s,u,l,c,f=e&&e.ownerDocument,p=e?e.nodeType:9;if(n=n||[],"string"!=typeof t||!t||1!==p&&9!==p&&11!==p)return n;if(!r&&(T(e),e=e||C,E)){if(11!==p&&(u=Z.exec(t)))if(i=u[1]){if(9===p){if(!(a=e.getElementById(i)))return n;if(a.id===i)return n.push(a),n}else if(f&&(a=f.getElementById(i))&&y(e,a)&&a.id===i)return n.push(a),n}else{if(u[2])return H.apply(n,e.getElementsByTagName(t)),n;if((i=u[3])&&d.getElementsByClassName&&e.getElementsByClassName)return H.apply(n,e.getElementsByClassName(i)),n}if(d.qsa&&!N[t+" "]&&(!v||!v.test(t))&&(1!==p||"object"!==e.nodeName.toLowerCase())){if(c=t,f=e,1===p&&(U.test(t)||z.test(t))){(f=ee.test(t)&&ye(e.parentNode)||e)===e&&d.scope||((s=e.getAttribute("id"))?s=s.replace(re,ie):e.setAttribute("id",s=S)),o=(l=h(t)).length;while(o--)l[o]=(s?"#"+s:":scope")+" "+xe(l[o]);c=l.join(",")}try{return H.apply(n,f.querySelectorAll(c)),n}catch(e){N(t,!0)}finally{s===S&&e.removeAttribute("id")}}}return g(t.replace($,"$1"),e,n,r)}function ue(){var r=[];return function e(t,n){return r.push(t+" ")>b.cacheLength&&delete e[r.shift()],e[t+" "]=n}}function le(e){return e[S]=!0,e}function ce(e){var t=C.createElement("fieldset");try{return!!e(t)}catch(e){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function fe(e,t){var n=e.split("|"),r=n.length;while(r--)b.attrHandle[n[r]]=t}function pe(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourceIndex-t.sourceIndex;if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function de(t){return function(e){return"input"===e.nodeName.toLowerCase()&&e.type===t}}function he(n){return function(e){var t=e.nodeName.toLowerCase();return("input"===t||"button"===t)&&e.type===n}}function ge(t){return function(e){return"form"in e?e.parentNode&&!1===e.disabled?"label"in e?"label"in e.parentNode?e.parentNode.disabled===t:e.disabled===t:e.isDisabled===t||e.isDisabled!==!t&&ae(e)===t:e.disabled===t:"label"in e&&e.disabled===t}}function ve(a){return le(function(o){return o=+o,le(function(e,t){var n,r=a([],e.length,o),i=r.length;while(i--)e[n=r[i]]&&(e[n]=!(t[n]=e[n]))})})}function ye(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}for(e in d=se.support={},i=se.isXML=function(e){var t=e.namespaceURI,n=(e.ownerDocument||e).documentElement;return!Y.test(t||n&&n.nodeName||"HTML")},T=se.setDocument=function(e){var t,n,r=e?e.ownerDocument||e:p;return r!=C&&9===r.nodeType&&r.documentElement&&(a=(C=r).documentElement,E=!i(C),p!=C&&(n=C.defaultView)&&n.top!==n&&(n.addEventListener?n.addEventListener("unload",oe,!1):n.attachEvent&&n.attachEvent("onunload",oe)),d.scope=ce(function(e){return a.appendChild(e).appendChild(C.createElement("div")),"undefined"!=typeof e.querySelectorAll&&!e.querySelectorAll(":scope fieldset div").length}),d.attributes=ce(function(e){return e.className="i",!e.getAttribute("className")}),d.getElementsByTagName=ce(function(e){return e.appendChild(C.createComment("")),!e.getElementsByTagName("*").length}),d.getElementsByClassName=K.test(C.getElementsByClassName),d.getById=ce(function(e){return a.appendChild(e).id=S,!C.getElementsByName||!C.getElementsByName(S).length}),d.getById?(b.filter.ID=function(e){var t=e.replace(te,ne);return function(e){return e.getAttribute("id")===t}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n=t.getElementById(e);return n?[n]:[]}}):(b.filter.ID=function(e){var n=e.replace(te,ne);return function(e){var t="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return t&&t.value===n}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n,r,i,o=t.getElementById(e);if(o){if((n=o.getAttributeNode("id"))&&n.value===e)return[o];i=t.getElementsByName(e),r=0;while(o=i[r++])if((n=o.getAttributeNode("id"))&&n.value===e)return[o]}return[]}}),b.find.TAG=d.getElementsByTagName?function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):d.qsa?t.querySelectorAll(e):void 0}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},b.find.CLASS=d.getElementsByClassName&&function(e,t){if("undefined"!=typeof t.getElementsByClassName&&E)return t.getElementsByClassName(e)},s=[],v=[],(d.qsa=K.test(C.querySelectorAll))&&(ce(function(e){var t;a.appendChild(e).innerHTML="",e.querySelectorAll("[msallowcapture^='']").length&&v.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll("[selected]").length||v.push("\\["+M+"*(?:value|"+R+")"),e.querySelectorAll("[id~="+S+"-]").length||v.push("~="),(t=C.createElement("input")).setAttribute("name",""),e.appendChild(t),e.querySelectorAll("[name='']").length||v.push("\\["+M+"*name"+M+"*="+M+"*(?:''|\"\")"),e.querySelectorAll(":checked").length||v.push(":checked"),e.querySelectorAll("a#"+S+"+*").length||v.push(".#.+[+~]"),e.querySelectorAll("\\\f"),v.push("[\\r\\n\\f]")}),ce(function(e){e.innerHTML="";var t=C.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),e.querySelectorAll("[name=d]").length&&v.push("name"+M+"*[*^$|!~]?="),2!==e.querySelectorAll(":enabled").length&&v.push(":enabled",":disabled"),a.appendChild(e).disabled=!0,2!==e.querySelectorAll(":disabled").length&&v.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),v.push(",.*:")})),(d.matchesSelector=K.test(c=a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.oMatchesSelector||a.msMatchesSelector))&&ce(function(e){d.disconnectedMatch=c.call(e,"*"),c.call(e,"[s!='']:x"),s.push("!=",F)}),v=v.length&&new RegExp(v.join("|")),s=s.length&&new RegExp(s.join("|")),t=K.test(a.compareDocumentPosition),y=t||K.test(a.contains)?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},D=t?function(e,t){if(e===t)return l=!0,0;var n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n||(1&(n=(e.ownerDocument||e)==(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!d.sortDetached&&t.compareDocumentPosition(e)===n?e==C||e.ownerDocument==p&&y(p,e)?-1:t==C||t.ownerDocument==p&&y(p,t)?1:u?P(u,e)-P(u,t):0:4&n?-1:1)}:function(e,t){if(e===t)return l=!0,0;var n,r=0,i=e.parentNode,o=t.parentNode,a=[e],s=[t];if(!i||!o)return e==C?-1:t==C?1:i?-1:o?1:u?P(u,e)-P(u,t):0;if(i===o)return pe(e,t);n=e;while(n=n.parentNode)a.unshift(n);n=t;while(n=n.parentNode)s.unshift(n);while(a[r]===s[r])r++;return r?pe(a[r],s[r]):a[r]==p?-1:s[r]==p?1:0}),C},se.matches=function(e,t){return se(e,null,null,t)},se.matchesSelector=function(e,t){if(T(e),d.matchesSelector&&E&&!N[t+" "]&&(!s||!s.test(t))&&(!v||!v.test(t)))try{var n=c.call(e,t);if(n||d.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(e){N(t,!0)}return 0":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(te,ne),e[3]=(e[3]||e[4]||e[5]||"").replace(te,ne),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||se.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&se.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return G.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&X.test(n)&&(t=h(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(te,ne).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=m[e+" "];return t||(t=new RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&m(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(n,r,i){return function(e){var t=se.attr(e,n);return null==t?"!="===r:!r||(t+="","="===r?t===i:"!="===r?t!==i:"^="===r?i&&0===t.indexOf(i):"*="===r?i&&-1:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function D(e,n,r){return m(n)?S.grep(e,function(e,t){return!!n.call(e,t,e)!==r}):n.nodeType?S.grep(e,function(e){return e===n!==r}):"string"!=typeof n?S.grep(e,function(e){return-1)[^>]*|#([\w-]+))$/;(S.fn.init=function(e,t,n){var r,i;if(!e)return this;if(n=n||j,"string"==typeof e){if(!(r="<"===e[0]&&">"===e[e.length-1]&&3<=e.length?[null,e,null]:q.exec(e))||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof S?t[0]:t,S.merge(this,S.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:E,!0)),N.test(r[1])&&S.isPlainObject(t))for(r in t)m(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return(i=E.getElementById(r[2]))&&(this[0]=i,this.length=1),this}return e.nodeType?(this[0]=e,this.length=1,this):m(e)?void 0!==n.ready?n.ready(e):e(S):S.makeArray(e,this)}).prototype=S.fn,j=S(E);var L=/^(?:parents|prev(?:Until|All))/,H={children:!0,contents:!0,next:!0,prev:!0};function O(e,t){while((e=e[t])&&1!==e.nodeType);return e}S.fn.extend({has:function(e){var t=S(e,this),n=t.length;return this.filter(function(){for(var e=0;e\x20\t\r\n\f]*)/i,he=/^$|^module$|\/(?:java|ecma)script/i;ce=E.createDocumentFragment().appendChild(E.createElement("div")),(fe=E.createElement("input")).setAttribute("type","radio"),fe.setAttribute("checked","checked"),fe.setAttribute("name","t"),ce.appendChild(fe),y.checkClone=ce.cloneNode(!0).cloneNode(!0).lastChild.checked,ce.innerHTML="",y.noCloneChecked=!!ce.cloneNode(!0).lastChild.defaultValue,ce.innerHTML="",y.option=!!ce.lastChild;var ge={thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};function ve(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||"*"):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||"*"):[],void 0===t||t&&A(e,t)?S.merge([e],n):n}function ye(e,t){for(var n=0,r=e.length;n",""]);var me=/<|&#?\w+;/;function xe(e,t,n,r,i){for(var o,a,s,u,l,c,f=t.createDocumentFragment(),p=[],d=0,h=e.length;d\s*$/g;function qe(e,t){return A(e,"table")&&A(11!==t.nodeType?t:t.firstChild,"tr")&&S(e).children("tbody")[0]||e}function Le(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function He(e){return"true/"===(e.type||"").slice(0,5)?e.type=e.type.slice(5):e.removeAttribute("type"),e}function Oe(e,t){var n,r,i,o,a,s;if(1===t.nodeType){if(Y.hasData(e)&&(s=Y.get(e).events))for(i in Y.remove(t,"handle events"),s)for(n=0,r=s[i].length;n").attr(n.scriptAttrs||{}).prop({charset:n.scriptCharset,src:n.url}).on("load error",i=function(e){r.remove(),i=null,e&&t("error"===e.type?404:200,e.type)}),E.head.appendChild(r[0])},abort:function(){i&&i()}}});var Ut,Xt=[],Vt=/(=)\?(?=&|$)|\?\?/;S.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Xt.pop()||S.expando+"_"+Ct.guid++;return this[e]=!0,e}}),S.ajaxPrefilter("json jsonp",function(e,t,n){var r,i,o,a=!1!==e.jsonp&&(Vt.test(e.url)?"url":"string"==typeof e.data&&0===(e.contentType||"").indexOf("application/x-www-form-urlencoded")&&Vt.test(e.data)&&"data");if(a||"jsonp"===e.dataTypes[0])return r=e.jsonpCallback=m(e.jsonpCallback)?e.jsonpCallback():e.jsonpCallback,a?e[a]=e[a].replace(Vt,"$1"+r):!1!==e.jsonp&&(e.url+=(Et.test(e.url)?"&":"?")+e.jsonp+"="+r),e.converters["script json"]=function(){return o||S.error(r+" was not called"),o[0]},e.dataTypes[0]="json",i=C[r],C[r]=function(){o=arguments},n.always(function(){void 0===i?S(C).removeProp(r):C[r]=i,e[r]&&(e.jsonpCallback=t.jsonpCallback,Xt.push(r)),o&&m(i)&&i(o[0]),o=i=void 0}),"script"}),y.createHTMLDocument=((Ut=E.implementation.createHTMLDocument("").body).innerHTML="
",2===Ut.childNodes.length),S.parseHTML=function(e,t,n){return"string"!=typeof e?[]:("boolean"==typeof t&&(n=t,t=!1),t||(y.createHTMLDocument?((r=(t=E.implementation.createHTMLDocument("")).createElement("base")).href=E.location.href,t.head.appendChild(r)):t=E),o=!n&&[],(i=N.exec(e))?[t.createElement(i[1])]:(i=xe([e],t,o),o&&o.length&&S(o).remove(),S.merge([],i.childNodes)));var r,i,o},S.fn.load=function(e,t,n){var r,i,o,a=this,s=e.indexOf(" ");return-1").append(S.parseHTML(e)).find(r):e)}).always(n&&function(e,t){a.each(function(){n.apply(this,o||[e.responseText,t,e])})}),this},S.expr.pseudos.animated=function(t){return S.grep(S.timers,function(e){return t===e.elem}).length},S.offset={setOffset:function(e,t,n){var r,i,o,a,s,u,l=S.css(e,"position"),c=S(e),f={};"static"===l&&(e.style.position="relative"),s=c.offset(),o=S.css(e,"top"),u=S.css(e,"left"),("absolute"===l||"fixed"===l)&&-1<(o+u).indexOf("auto")?(a=(r=c.position()).top,i=r.left):(a=parseFloat(o)||0,i=parseFloat(u)||0),m(t)&&(t=t.call(e,n,S.extend({},s))),null!=t.top&&(f.top=t.top-s.top+a),null!=t.left&&(f.left=t.left-s.left+i),"using"in t?t.using.call(e,f):("number"==typeof f.top&&(f.top+="px"),"number"==typeof f.left&&(f.left+="px"),c.css(f))}},S.fn.extend({offset:function(t){if(arguments.length)return void 0===t?this:this.each(function(e){S.offset.setOffset(this,t,e)});var e,n,r=this[0];return r?r.getClientRects().length?(e=r.getBoundingClientRect(),n=r.ownerDocument.defaultView,{top:e.top+n.pageYOffset,left:e.left+n.pageXOffset}):{top:0,left:0}:void 0},position:function(){if(this[0]){var e,t,n,r=this[0],i={top:0,left:0};if("fixed"===S.css(r,"position"))t=r.getBoundingClientRect();else{t=this.offset(),n=r.ownerDocument,e=r.offsetParent||n.documentElement;while(e&&(e===n.body||e===n.documentElement)&&"static"===S.css(e,"position"))e=e.parentNode;e&&e!==r&&1===e.nodeType&&((i=S(e).offset()).top+=S.css(e,"borderTopWidth",!0),i.left+=S.css(e,"borderLeftWidth",!0))}return{top:t.top-i.top-S.css(r,"marginTop",!0),left:t.left-i.left-S.css(r,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var e=this.offsetParent;while(e&&"static"===S.css(e,"position"))e=e.offsetParent;return e||re})}}),S.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(t,i){var o="pageYOffset"===i;S.fn[t]=function(e){return $(this,function(e,t,n){var r;if(x(e)?r=e:9===e.nodeType&&(r=e.defaultView),void 0===n)return r?r[i]:e[t];r?r.scrollTo(o?r.pageXOffset:n,o?n:r.pageYOffset):e[t]=n},t,e,arguments.length)}}),S.each(["top","left"],function(e,n){S.cssHooks[n]=$e(y.pixelPosition,function(e,t){if(t)return t=Be(e,n),Me.test(t)?S(e).position()[n]+"px":t})}),S.each({Height:"height",Width:"width"},function(a,s){S.each({padding:"inner"+a,content:s,"":"outer"+a},function(r,o){S.fn[o]=function(e,t){var n=arguments.length&&(r||"boolean"!=typeof e),i=r||(!0===e||!0===t?"margin":"border");return $(this,function(e,t,n){var r;return x(e)?0===o.indexOf("outer")?e["inner"+a]:e.document.documentElement["client"+a]:9===e.nodeType?(r=e.documentElement,Math.max(e.body["scroll"+a],r["scroll"+a],e.body["offset"+a],r["offset"+a],r["client"+a])):void 0===n?S.css(e,t,i):S.style(e,t,n,i)},s,n?e:void 0,n)}})}),S.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){S.fn[t]=function(e){return this.on(t,e)}}),S.fn.extend({bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)},hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)}}),S.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(e,n){S.fn[n]=function(e,t){return 0