├── .babelrc ├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── Jenkinsfile ├── LICENSE ├── MasterWAMPServer.js ├── MasterWAMPServer.spec.js ├── README.md ├── SlaveWAMPServer.js ├── SlaveWAMPServer.spec.js ├── WAMPClient.js ├── WAMPClient.spec.js ├── WAMPServer.js ├── WAMPServer.spec.js ├── dist ├── MasterWAMPServer.bundle.min.js ├── MasterWAMPServer.src.min.js ├── SlaveWAMPServer.bundle.min.js ├── SlaveWAMPServer.src.min.js ├── WAMPClient.bundle.min.js ├── WAMPClient.src.min.js ├── WAMPServer.bundle.min.js ├── WAMPServer.src.min.js └── index.js ├── example ├── .eslintrc.json ├── client.js ├── index.js ├── server.js └── serverWorker.js ├── index.js ├── package.json ├── schemas.js ├── testSetup.spec.js ├── utils.js ├── utils.spec.js └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["env"] 3 | } -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["lisk-base"], 3 | "env": { 4 | "node": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | npm-debug.log 4 | .idea 5 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | def initBuild() { 2 | deleteDir() 3 | checkout scm 4 | } 5 | 6 | def buildDependency() { 7 | try { 8 | sh '''#!/bin/bash 9 | npm install 10 | ''' 11 | } catch (err) { 12 | currentBuild.result = 'FAILURE' 13 | error('Stopping build, installation failed') 14 | } 15 | } 16 | 17 | def runLinter() { 18 | try { 19 | sh '''#!/bin/bash 20 | npm run eslint 21 | ''' 22 | } catch (err) { 23 | currentBuild.result = 'FAILURE' 24 | error('Eslint failed') 25 | } 26 | } 27 | 28 | def runTests() { 29 | try { 30 | sh '''#!/bin/bash 31 | npm run test 32 | ''' 33 | } catch (err) { 34 | currentBuild.result = 'FAILURE' 35 | error('Tests are failing') 36 | } 37 | } 38 | 39 | node('wamp-socket-cluster'){ 40 | lock(resource: "wamp-socket-cluster", inversePrecedence: true) { 41 | stage ('Prepare Workspace') { 42 | initBuild() 43 | } 44 | 45 | stage ('Build Dependencies') { 46 | buildDependency() 47 | } 48 | 49 | stage ('Run linter') { 50 | runLinter() 51 | } 52 | 53 | stage ('Execute Tests') { 54 | runTests() 55 | } 56 | 57 | stage ('Set milestone') { 58 | milestone 1 59 | currentBuild.result = 'SUCCESS' 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /MasterWAMPServer.js: -------------------------------------------------------------------------------- 1 | const WAMPServer = require('./WAMPServer'); 2 | const schemas = require('./schemas'); 3 | 4 | class MasterWAMPServer extends WAMPServer { 5 | /** 6 | * @param {SocketCluster.SocketCluster} socketCluster 7 | * @param {Object} config 8 | */ 9 | constructor(socketCluster, config) { 10 | super(); 11 | this.socketCluster = socketCluster; 12 | this.workerIndices = []; 13 | this.config = config; 14 | socketCluster.on('workerStart', (worker) => { 15 | this.broadcastConfigToWorkers([worker.id]); 16 | this.workerIndices.push(worker.id); 17 | }); 18 | 19 | socketCluster.on('workerMessage', (workerId, request, respond) => { 20 | if (schemas.isValid(request, schemas.EventRequestSchema) || 21 | schemas.isValid(request, schemas.MasterRPCRequestSchema) || 22 | schemas.isValid(request, schemas.InterProcessRPCRequestSchema)) { 23 | this.processWAMPRequest(request, respond); 24 | } 25 | }); 26 | 27 | socketCluster.on('workerExit', (workerInfo) => { 28 | const existingWorkerIndex = this.workerIndices.indexOf(workerInfo.id); 29 | if (existingWorkerIndex === -1) { 30 | return; 31 | } 32 | this.workerIndices.splice(existingWorkerIndex, 1); 33 | }); 34 | } 35 | 36 | /** 37 | * @param {Array} workerIds 38 | * @returns {undefined} 39 | */ 40 | broadcastConfigToWorkers(workerIds) { 41 | workerIds.forEach((workerId) => { 42 | this.socketCluster.sendToWorker(workerId, { 43 | type: schemas.MasterConfigRequestSchema.id, 44 | registeredEvents: Object.keys(this.endpoints.event), 45 | config: this.config || {}, 46 | }); 47 | }); 48 | } 49 | 50 | /** 51 | * @param {Map} endpoints 52 | * @returns {undefined} 53 | */ 54 | registerEventEndpoints(endpoints) { 55 | super.registerEventEndpoints(endpoints); 56 | this.broadcastConfigToWorkers(this.workerIndices); 57 | } 58 | 59 | /** 60 | * @param {Map} endpoints 61 | * @returns {undefined} 62 | */ 63 | registerRPCEndpoints(endpoints) { 64 | super.registerRPCEndpoints(endpoints); 65 | this.broadcastConfigToWorkers(this.workerIndices); 66 | } 67 | } 68 | 69 | module.exports = MasterWAMPServer; 70 | -------------------------------------------------------------------------------- /MasterWAMPServer.spec.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node, mocha */ 2 | /* eslint-disable no-new */ 3 | const sinon = require('sinon'); 4 | const { expect } = require('./testSetup.spec'); 5 | const MasterWAMPServer = require('./MasterWAMPServer'); 6 | const MasterRPCRequestSchema = require('./schemas').MasterRPCRequestSchema; 7 | const RPCResponseSchema = require('./schemas').RPCResponseSchema; 8 | 9 | describe('MasterWAMPServer', () => { 10 | let fakeSCServer; 11 | let masterWAMPServer; 12 | const validWorkerId = 0; 13 | 14 | beforeEach(() => { 15 | fakeSCServer = { 16 | on: sinon.spy(), 17 | sendToWorker: sinon.spy(), 18 | }; 19 | masterWAMPServer = new MasterWAMPServer(fakeSCServer); 20 | }); 21 | 22 | describe('constructor', () => { 23 | it('create SlaveWAMPServer with socketCluster field', () => { 24 | expect(masterWAMPServer).to.have.property('socketCluster').to.be.a('object'); 25 | }); 26 | 27 | 28 | it('should start listening on "workerStart"', () => { 29 | new MasterWAMPServer(fakeSCServer); 30 | expect(fakeSCServer.on.called).to.be.true(); 31 | expect(fakeSCServer.on.calledWith('workerStart')).to.be.true(); 32 | expect(fakeSCServer.on.getCalls()[0].args[1]).to.be.a('function'); 33 | }); 34 | 35 | it('should start listening on "workerMessage"', () => { 36 | new MasterWAMPServer(fakeSCServer); 37 | expect(fakeSCServer.on.called).to.be.true(); 38 | expect(fakeSCServer.on.calledWith('workerMessage')).to.be.true(); 39 | expect(fakeSCServer.on.getCalls()[1].args[1]).to.be.a('function'); 40 | }); 41 | 42 | describe('socketCluster.on', () => { 43 | const validMasterWAMPRequest = { 44 | workerId: 0, 45 | socketId: 'AYX', 46 | type: MasterRPCRequestSchema.id, 47 | procedure: 'methodA', 48 | signature: '0', 49 | data: {}, 50 | }; 51 | 52 | const validInterProcessRPCRequest = { 53 | type: '/InterProcessRPCRequestSchema', 54 | procedure: 'updatePeer', 55 | data: {}, 56 | socketId: '127.0.0.1:8000', 57 | workerId: 0, 58 | signature: '0', 59 | }; 60 | 61 | 62 | beforeEach(() => { 63 | masterWAMPServer.processWAMPRequest = sinon.spy(); 64 | }); 65 | 66 | describe('workerMessage', () => { 67 | let onWorkerMessageHandler; 68 | 69 | beforeEach(() => { 70 | onWorkerMessageHandler = fakeSCServer.on.getCalls()[1].args[1]; 71 | }); 72 | 73 | it('should call processWAMPRequest when proper InterProcessRPCRequestSchema param passed to "workerMessage" handler', () => { 74 | onWorkerMessageHandler(validWorkerId, validInterProcessRPCRequest); 75 | expect(masterWAMPServer.processWAMPRequest.called).to.be.true(); 76 | }); 77 | 78 | it('should call processWAMPRequest when proper MasterWAMPRequest param passed to "workerMessage" handler', () => { 79 | onWorkerMessageHandler(validWorkerId, validMasterWAMPRequest); 80 | expect(masterWAMPServer.processWAMPRequest.called).to.be.true(); 81 | }); 82 | 83 | it('should call processWAMPRequest when proper MasterRPCRequestSchema with received request', () => { 84 | onWorkerMessageHandler(validWorkerId, validMasterWAMPRequest); 85 | expect(masterWAMPServer.processWAMPRequest.calledWith(validMasterWAMPRequest)) 86 | .to.be.true(); 87 | }); 88 | 89 | it('should not call processWAMPRequest when invalid MasterRPCRequestSchema passed', () => { 90 | const invalidMasterWAMPCall = Object.assign({}, validMasterWAMPRequest, { type: 'invalid' }); 91 | onWorkerMessageHandler(validWorkerId, invalidMasterWAMPCall); 92 | expect(masterWAMPServer.processWAMPRequest.called).not.to.be.true(); 93 | }); 94 | 95 | it('should not call processWAMPRequest when empty request passed', () => { 96 | onWorkerMessageHandler(validWorkerId, null); 97 | expect(masterWAMPServer.processWAMPRequest.called).not.to.be.true(); 98 | }); 99 | }); 100 | 101 | describe('workerStart', () => { 102 | let onWorkerStartHandler; 103 | let validWorker; 104 | 105 | beforeEach(() => { 106 | onWorkerStartHandler = fakeSCServer.on.getCalls()[0].args[1]; 107 | validWorker = { id: validWorkerId }; 108 | }); 109 | 110 | it('should call sendToWorker function with array of worker.id', () => { 111 | onWorkerStartHandler(validWorker); 112 | expect(masterWAMPServer.socketCluster.sendToWorker.calledWith(validWorker.id)).to.be.true(); 113 | }); 114 | 115 | it('should call reply function with valid MasterConfigRequestSchema', () => { 116 | onWorkerStartHandler(validWorker); 117 | expect(masterWAMPServer.socketCluster.sendToWorker.args[0][1]).to.eql({ 118 | type: '/MasterConfigRequestSchema', 119 | registeredEvents: [], 120 | config: {}, 121 | }); 122 | }); 123 | }); 124 | 125 | describe('workerExit', () => { 126 | let onWorkerExitHandler; 127 | let validWorker; 128 | 129 | beforeEach(() => { 130 | onWorkerExitHandler = fakeSCServer.on.getCalls()[2].args[1]; 131 | validWorker = { id: validWorkerId }; 132 | }); 133 | 134 | it('should not modify empty workerIndices array', () => { 135 | onWorkerExitHandler(validWorker); 136 | expect(masterWAMPServer.workerIndices).to.be.empty(); 137 | }); 138 | 139 | it('should remove the worker index from the workerIndices array if added previously', () => { 140 | masterWAMPServer.workerIndices = [0]; 141 | onWorkerExitHandler(validWorker); 142 | expect(masterWAMPServer.workerIndices).to.be.empty(); 143 | }); 144 | 145 | it('should remove the worker index from the beginning of the workerIndices array if added previously', () => { 146 | masterWAMPServer.workerIndices = [0, 1, 2]; 147 | onWorkerExitHandler(validWorker); 148 | expect(masterWAMPServer.workerIndices).to.eql([1, 2]); 149 | }); 150 | 151 | it('should remove the worker index from the middle of the workerIndices array if added previously', () => { 152 | masterWAMPServer.workerIndices = [1, 0, 2]; 153 | onWorkerExitHandler(validWorker); 154 | expect(masterWAMPServer.workerIndices).to.eql([1, 2]); 155 | }); 156 | 157 | it('should remove the worker index from the end of the workerIndices array if added previously', () => { 158 | masterWAMPServer.workerIndices = [1, 2, 0]; 159 | onWorkerExitHandler(validWorker); 160 | expect(masterWAMPServer.workerIndices).to.eql([1, 2]); 161 | }); 162 | }); 163 | }); 164 | }); 165 | 166 | }); 167 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WAMP Socket Cluster 2 | 3 | Merges RPC ideas of WAMP protocol with good performance of SocketCluster. 4 | 5 | As [SocketCluster](http://socketcluster.io/#!/) is not compatible with [WAMP protocol](http://wamp-proto.org/) (as e.g. [AutobahnJS](https://github.com/crossbario/autobahn-js/)) this library provides the wrapper for both SocketClient (WAMPClient) and SocketServer (WAMPServer) and enables RPC web sockets usage. 6 | 7 | ## Benefits 8 | 9 | - WAMP protocol style function calls (`socket.call(...).then(...)`). 10 | - Addresses the problem of response order in case of subscribing to an event after peer sends many individual requests. 11 | 12 | ## Installation 13 | 14 | ``` 15 | npm install wamp-socket-cluster 16 | ``` 17 | 18 | ## Usage 19 | 20 | - Initialize server side 21 | 22 | ``` 23 | const rpcEndpoints = { multiplyByTwo: num => num * 2 }; 24 | scServer.on('connection', socket => { 25 | wampServer.upgradeToWAMP(socket); 26 | wampServer.reassignEndpoints(rpcEndpoints); 27 | }); 28 | ``` 29 | 30 | - Initialize client side 31 | 32 | ``` 33 | const socket = scClient.connect(options); 34 | wampClient.upgradeToWAMP(this.socket); 35 | const randNumber = Math.floor( Math.random() * 5 ); 36 | socket.call('multiplyByTwo', 2) 37 | .then(result => console.log(`RPC result: ${randNumber} * 2 = ${result}`)) 38 | .catch(err => console.error('RPC multiply by two error')); 39 | ``` 40 | 41 | ## Example Usage 42 | 43 | A simple but complete [example](https://github.com/LiskHQ/wamp-socket-cluster/tree/master/example) has been implemented. It includes socket cluster initialization, plus registration of RPC both at client and server side. 44 | 45 | ## Test 46 | 47 | - `npm test` 48 | 49 | ## Authors 50 | 51 | - Maciej Baj 52 | 53 | ## License 54 | 55 | Copyright (c) 2017 Lisk Foundation 56 | 57 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 58 | 59 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 60 | 61 | You should have received a copy of the [GNU General Public License](https://github.com/LiskHQ/wamp-socket-cluster/tree/master/LICENSE) along with this program. If not, see . 62 | -------------------------------------------------------------------------------- /SlaveWAMPServer.js: -------------------------------------------------------------------------------- 1 | const Validator = require('jsonschema').Validator; 2 | const get = require('./utils').get; 3 | const WAMPServer = require('./WAMPServer'); 4 | const WAMPClient = require('./WAMPClient'); 5 | 6 | const schemas = require('./schemas'); 7 | 8 | const v = new Validator(); 9 | 10 | class SlaveWAMPServer extends WAMPServer { 11 | /** 12 | * @param {SocketCluster.Worker} worker 13 | * @param {number} internalRequestsTimeoutMs - time [ms] to wait for responses from master 14 | * @param {number} cleanRequestsIntervalMs - frequency [ms] of cleaning outdated requests 15 | * @param {Function}[configuredCb=function] configuredCb 16 | */ 17 | constructor( 18 | worker, 19 | internalRequestsTimeoutMs = 10e3, 20 | configuredCb = () => {}) { 21 | super(); 22 | this.worker = worker; 23 | this.sockets = worker.scServer.clients; 24 | this.endpoints.slaveRpc = {}; 25 | this.config = {}; 26 | this.internalRequestsTimeoutMs = internalRequestsTimeoutMs; 27 | this.worker.on('masterMessage', (payload, respond) => { 28 | if (schemas.isValid(payload, schemas.MasterConfigRequestSchema)) { 29 | this.config = Object.assign({}, this.config, payload.config); 30 | if (payload.registeredEvents) { 31 | this.registerEventEndpoints(payload.registeredEvents.reduce( 32 | (memo, event) => Object.assign(memo, { [event]: (data) => { 33 | this.worker.sendToMaster({ 34 | data, 35 | procedure: event, 36 | type: schemas.EventRequestSchema.id, 37 | }); 38 | } }), {})); 39 | } 40 | configuredCb(null, this); 41 | configuredCb = () => {}; 42 | } else { 43 | console.error(`Received invalid master message payload of type "${payload.type}"`); 44 | } 45 | }); 46 | } 47 | 48 | /** 49 | * @param {string} procedure 50 | * @param {*} data 51 | * @param {Function} callback 52 | * @returns {undefined} 53 | */ 54 | sendToMaster(procedure, data, callback) { 55 | const req = { 56 | type: schemas.InterProcessRPCRequestSchema.id, 57 | procedure, 58 | data, 59 | }; 60 | if (callback) { 61 | this.worker.sendToMaster(req, (err, response) => { 62 | if (err) { 63 | return callback(err); 64 | } 65 | return callback(null, response.data); 66 | }); 67 | } else { 68 | this.worker.sendToMaster(req); 69 | } 70 | } 71 | 72 | /** 73 | * @param {RPCRequestSchema} request 74 | * @param {Object} respond 75 | * @returns {undefined} 76 | */ 77 | processWAMPRequest(request, respond) { 78 | if (v.validate(request, schemas.RPCRequestSchema).valid) { 79 | if (this.endpoints.slaveRpc[request.procedure] && 80 | typeof this.endpoints.slaveRpc[request.procedure] === 'function') { 81 | 82 | if (respond) { 83 | this.endpoints.slaveRpc[request.procedure](request, (error, data) => { 84 | respond(error, { 85 | type: schemas.RPCResponseSchema.id, 86 | data, 87 | }); 88 | }); 89 | } else { 90 | this.endpoints.slaveRpc[request.procedure](request); 91 | } 92 | } else { 93 | request.type = schemas.MasterRPCRequestSchema.id; 94 | this.worker.sendToMaster(request, respond); 95 | } 96 | } 97 | } 98 | 99 | /** 100 | * @param {Map} endpoints 101 | * @returns {undefined} 102 | */ 103 | reassignRPCSlaveEndpoints(endpoints) { 104 | this.endpoints.slaveRpc = endpoints; 105 | } 106 | 107 | /** 108 | * @param {Map} endpoints 109 | * @returns {undefined} 110 | */ 111 | registerRPCSlaveEndpoints(endpoints) { 112 | this.endpoints.slaveRpc = Object.assign(this.endpoints.slaveRpc, endpoints); 113 | } 114 | } 115 | 116 | module.exports = SlaveWAMPServer; 117 | -------------------------------------------------------------------------------- /SlaveWAMPServer.spec.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node, mocha */ 2 | /* eslint-disable no-new */ 3 | const sinon = require('sinon'); 4 | const SlaveWAMPServer = require('./SlaveWAMPServer'); 5 | 6 | const { expect } = require('./testSetup.spec'); 7 | 8 | describe('SlaveWAMPServer', () => { 9 | let clock; 10 | let workerMock; 11 | let slaveWAMPServer; 12 | let validData; 13 | let validRequest; 14 | let validSignature; 15 | let validInterProcessRPCEntry; 16 | const validProcedure = 'validProcedure'; 17 | const validSocketId = 'validSocketId'; 18 | const validCb = sinon.spy(); 19 | 20 | beforeEach(() => { 21 | clock = sinon.useFakeTimers(new Date(2020, 1, 1).getTime()); 22 | }); 23 | 24 | afterEach(() => { 25 | clock.restore(); 26 | }); 27 | 28 | beforeEach(() => { 29 | workerMock = { 30 | id: 0, 31 | on: sinon.spy(), 32 | sendToMaster: sinon.spy(), 33 | scServer: { 34 | clients: {}, 35 | }, 36 | }; 37 | validCb.reset(); 38 | slaveWAMPServer = new SlaveWAMPServer(workerMock); 39 | validSignature = `${new Date().getTime()}_0`; 40 | validRequest = { 41 | socketId: validSocketId, 42 | procedure: validProcedure, 43 | signature: validSignature, 44 | }; 45 | validData = { validKey: 'validValue' }; 46 | validInterProcessRPCEntry = { 47 | [validSocketId]: { 48 | [validProcedure]: { 49 | [validSignature]: { 50 | requestTimeout: setTimeout(() => {}, 0), 51 | callback: () => {}, 52 | }, 53 | }, 54 | }, 55 | }; 56 | }); 57 | 58 | 59 | describe('constructor', () => { 60 | it('create SlaveWAMPServer with worker field', () => { 61 | expect(slaveWAMPServer).to.have.property('worker').to.be.a('object').and.to.have.property('id').equal(0); 62 | }); 63 | 64 | it('create SlaveWAMPServer with sockets field', () => { 65 | expect(slaveWAMPServer).to.have.property('sockets').to.be.a('object').and.to.be.empty(); 66 | }); 67 | 68 | it('create SlaveWAMPServer with sockets field', () => { 69 | expect(slaveWAMPServer).to.have.property('sockets').to.be.a('object').and.to.be.empty(); 70 | }); 71 | 72 | it('create SlaveWAMPServer and register event listener from master process', () => { 73 | expect(workerMock.on.calledOnce).to.be.true(); 74 | expect(workerMock.on.calledWith('masterMessage')).to.be.true(); 75 | }); 76 | }); 77 | 78 | describe('processWAMPRequest', () => { 79 | let socketMock; 80 | let respondStub; 81 | let validWAMPRequest; 82 | let validSlaveToMasterRequest; 83 | 84 | beforeEach(() => { 85 | socketMock = { 86 | id: 'validSocketId', 87 | on: sinon.spy(), 88 | send: sinon.spy(), 89 | }; 90 | 91 | respondStub = sinon.spy(); 92 | 93 | validWAMPRequest = { 94 | procedure: 'procedureName', 95 | type: '/RPCRequest', 96 | }; 97 | 98 | validSlaveToMasterRequest = { 99 | procedure: 'procedureName', 100 | type: '/MasterRPCRequest', 101 | }; 102 | }); 103 | 104 | it('should pass request forward to master if procedure is not registered in SlaveWAMPServer', () => { 105 | slaveWAMPServer.processWAMPRequest(validWAMPRequest, respondStub); 106 | expect(workerMock.sendToMaster.calledOnce).to.be.true(); 107 | expect(workerMock.sendToMaster.calledWith(validWAMPRequest)).to.be.true(); 108 | expect(workerMock.sendToMaster.args[0][1]).to.be.a('function'); 109 | }); 110 | 111 | it('should pass request forward to master if procedure is not registered in SlaveWAMPServer and respond handler is not provided', () => { 112 | slaveWAMPServer.processWAMPRequest(validWAMPRequest); 113 | expect(workerMock.sendToMaster.calledOnce).to.be.true(); 114 | expect(workerMock.sendToMaster.calledWith(validSlaveToMasterRequest)).to.be.true(); 115 | }); 116 | 117 | it('should invoke procedure on SlaveWAMPServer if registered before', () => { 118 | const endpoint = { procedureName: sinon.spy() }; 119 | slaveWAMPServer.registerRPCSlaveEndpoints(endpoint); 120 | slaveWAMPServer.processWAMPRequest(validWAMPRequest, respondStub); 121 | expect(endpoint.procedureName.calledOnce).to.be.true(); 122 | expect(endpoint.procedureName.calledWith({ 123 | procedure: 'procedureName', 124 | type: '/RPCRequest', 125 | })).to.be.true(); 126 | 127 | expect(workerMock.sendToMaster.called).not.to.be.true(); 128 | }); 129 | 130 | 131 | it('should invoke procedure on SlaveWAMPServer if registered before and respond handler is not provided', () => { 132 | const endpoint = { procedureName: sinon.spy() }; 133 | slaveWAMPServer.registerRPCSlaveEndpoints(endpoint); 134 | slaveWAMPServer.processWAMPRequest(validWAMPRequest); 135 | expect(endpoint.procedureName.calledOnce).to.be.true(); 136 | expect(endpoint.procedureName.calledWith({ 137 | procedure: 'procedureName', 138 | type: '/RPCRequest', 139 | })).to.be.true(); 140 | 141 | expect(workerMock.sendToMaster.called).not.to.be.true(); 142 | }); 143 | 144 | it('should invoke procedure on SlaveWAMPServer if reassigned before', () => { 145 | const endpoint = { procedureName: sinon.spy() }; 146 | slaveWAMPServer.reassignRPCSlaveEndpoints(endpoint); 147 | slaveWAMPServer.processWAMPRequest(validWAMPRequest, respondStub); 148 | expect(endpoint.procedureName.calledOnce).to.be.true(); 149 | expect(endpoint.procedureName.calledWith({ 150 | procedure: 'procedureName', 151 | type: '/RPCRequest', 152 | })).to.be.true(); 153 | 154 | expect(workerMock.sendToMaster.called).not.to.be.true(); 155 | }); 156 | 157 | it('should invoke procedure on SlaveWAMPServer if it was registered on both WAMPServer and SlaveWAMPServer', () => { 158 | const endpoint = { procedureName: sinon.spy() }; 159 | slaveWAMPServer.registerRPCEndpoints(endpoint); 160 | slaveWAMPServer.registerRPCSlaveEndpoints(endpoint); 161 | slaveWAMPServer.processWAMPRequest(validWAMPRequest, respondStub); 162 | expect(endpoint.procedureName.calledOnce).to.be.true(); 163 | expect(endpoint.procedureName.calledWith({ 164 | procedure: 'procedureName', 165 | type: '/RPCRequest', 166 | })).to.be.true(); 167 | 168 | expect(workerMock.sendToMaster.called).not.to.be.true(); 169 | }); 170 | }); 171 | 172 | describe('sendToMaster', () => { 173 | let mathRandomStub; 174 | 175 | before(() => { 176 | mathRandomStub = sinon.stub(Math, 'random').returns(0); 177 | }); 178 | 179 | after(() => { 180 | mathRandomStub.restore(); 181 | }); 182 | 183 | it('should pass correct InterProcessRPCRequestSchema compatible request to sendToMaster function', () => { 184 | slaveWAMPServer.sendToMaster(validProcedure, validData, validCb); 185 | expect(workerMock.sendToMaster.calledOnce).to.be.true(); 186 | expect(workerMock.sendToMaster.calledWith({ 187 | type: '/InterProcessRPCRequestSchema', 188 | procedure: validProcedure, 189 | data: validData, 190 | })).to.be.true(); 191 | }); 192 | 193 | describe('when internalRequestsTimeoutMs is exceeded', () => { 194 | beforeEach((done) => { 195 | clock.restore(); 196 | slaveWAMPServer.internalRequestsTimeoutMs = 1; 197 | slaveWAMPServer.sendToMaster(validProcedure, validData, validCb); 198 | setTimeout(() => { 199 | validCb('RPC response timeout exceeded'); 200 | done(); 201 | }, slaveWAMPServer.internalRequestsTimeoutMs + 1); 202 | }); 203 | 204 | it('should resolve request', () => { 205 | expect(validCb.calledOnce).to.be.true(); 206 | }); 207 | 208 | it('should resolve request with error = "RPC response timeout exceeded"', () => { 209 | expect(validCb.calledWithExactly('RPC response timeout exceeded')).to.be.true(); 210 | }); 211 | }); 212 | }); 213 | }); 214 | -------------------------------------------------------------------------------- /WAMPClient.js: -------------------------------------------------------------------------------- 1 | const get = require('./utils').get; 2 | const schemas = require('./schemas'); 3 | 4 | class WAMPClient { 5 | 6 | /** 7 | * @param {Object} socket - SocketCluster.Socket 8 | * @returns {Object} wampSocket 9 | */ 10 | upgradeToWAMP(socket) { 11 | if (socket.call) { 12 | return socket; 13 | } 14 | const wampSocket = socket; 15 | 16 | /** 17 | * Call procedure registered in WAMPServer 18 | * @param {string} procedure 19 | * @param {*} data 20 | * @returns {Promise} 21 | */ 22 | wampSocket.call = (procedure, data) => new Promise((success, fail) => { 23 | return socket.emit('rpc-request', { 24 | type: schemas.RPCRequestSchema.id, 25 | procedure, 26 | data, 27 | }, (err, result) => { 28 | if (err) { 29 | fail(err.toString()); 30 | } else { 31 | if (result) { 32 | success(result.data); 33 | } else { 34 | success(); 35 | } 36 | } 37 | }); 38 | }); 39 | return wampSocket; 40 | } 41 | } 42 | 43 | module.exports = WAMPClient; 44 | -------------------------------------------------------------------------------- /WAMPClient.spec.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node, mocha */ 2 | const sinon = require('sinon'); 3 | const Validator = require('jsonschema').Validator; 4 | const { expect } = require('./testSetup.spec'); 5 | 6 | const v = new Validator(); 7 | 8 | const WAMPClient = require('./WAMPClient.js'); 9 | const RPCResponseSchema = require('./schemas').RPCResponseSchema; 10 | 11 | describe('WAMPClient', () => { 12 | let fakeSocket; 13 | let clock; 14 | let frozenSignature; 15 | const validProcedure = 'validProcedure'; 16 | 17 | beforeEach(() => { 18 | clock = sinon.useFakeTimers(new Date(2020, 1, 1).getTime()); 19 | frozenSignature = `${(new Date()).getTime()}_0`; 20 | }); 21 | 22 | afterEach(() => { 23 | clock.restore(); 24 | }); 25 | 26 | beforeEach(() => { 27 | fakeSocket = { 28 | on: sinon.spy(), 29 | }; 30 | }); 31 | 32 | describe('upgradeToWAMP', () => { 33 | it('should add emit function to given parameter', () => { 34 | const wampSocket = new WAMPClient().upgradeToWAMP(fakeSocket); 35 | expect(wampSocket).to.have.property('call').to.be.a('function'); 36 | }); 37 | 38 | it('should return passed socket when call and raw event listener are present', () => { 39 | fakeSocket.call = () => {}; 40 | fakeSocket.listeners = () => ({ length: true }); 41 | const returnedSocket = new WAMPClient().upgradeToWAMP(fakeSocket); 42 | expect(returnedSocket).to.equal(fakeSocket); 43 | }); 44 | }); 45 | 46 | describe('wampSocket', () => { 47 | describe('call', () => { 48 | let wampClient; 49 | let wampSocket; 50 | const someArgument = { 51 | propA: 'valueA', 52 | }; 53 | 54 | beforeEach(() => { 55 | wampClient = new WAMPClient(fakeSocket); 56 | wampSocket = { 57 | emit: sinon.spy(), 58 | on: sinon.spy(), 59 | }; 60 | wampSocket = wampClient.upgradeToWAMP(wampSocket); 61 | }); 62 | 63 | it('should return a promise', () => { 64 | expect(wampSocket.call()).to.be.a('promise'); 65 | }); 66 | 67 | it('should invoke socket.emit function', () => { 68 | wampSocket.call(validProcedure); 69 | expect(wampSocket.emit.calledOnce).to.be.true(); 70 | }); 71 | 72 | it('should invoke socket.emit function with passed 3 arguments', () => { 73 | wampSocket.call(validProcedure, someArgument); 74 | expect(wampSocket.emit.getCalls()[0].args.length).equal(3); 75 | }); 76 | 77 | it('should invoke socket.emit function with "rpc-request" as first argument', () => { 78 | wampSocket.call(validProcedure, someArgument); 79 | expect(wampSocket.emit.getCalls()[0].args[0]).equal('rpc-request'); 80 | }); 81 | 82 | it('should invoke socket.emit function with passed RPC query as second argument', () => { 83 | wampSocket.call(validProcedure, someArgument); 84 | const rpcQuery = wampSocket.emit.getCalls()[0].args[1]; 85 | expect(rpcQuery).to.have.property('data').eql({ propA: 'valueA' }); 86 | expect(rpcQuery).to.have.property('procedure').equal(validProcedure); 87 | expect(rpcQuery).to.have.property('type').equal('/RPCRequest'); 88 | }); 89 | 90 | describe('resolving responses', () => { 91 | let mathRandomStub; 92 | let validWampServerResponse; 93 | let invalidWampServerResponse; 94 | let validData; 95 | const validError = 'error description'; 96 | 97 | before(() => { 98 | mathRandomStub = sinon.stub(Math, 'random').returns(0); 99 | }); 100 | 101 | after(() => { 102 | mathRandomStub.restore(); 103 | }); 104 | 105 | beforeEach(() => { 106 | validData = { 107 | propA: 'valueA', 108 | }; 109 | validWampServerResponse = { 110 | type: RPCResponseSchema.id, 111 | procedure: validProcedure, 112 | data: validData, 113 | }; 114 | invalidWampServerResponseError = 'Failed to perform RPC'; 115 | }); 116 | 117 | it('should resolve with passed data when server responds when passed valid WAMPResult', (done) => { 118 | expect(v.validate(validWampServerResponse, RPCResponseSchema).valid).to.be.true(); 119 | 120 | wampSocket.call(validProcedure).then((data) => { 121 | expect(data).equal(validWampServerResponse.data); 122 | done(); 123 | }).catch((err) => { 124 | expect(err).to.be.empty(); 125 | }); 126 | 127 | const mockedServerResponse = wampSocket.emit.getCalls()[0].args[2]; 128 | mockedServerResponse(null, validWampServerResponse); 129 | }); 130 | 131 | it('should reject with passed data when server responds with invalid WAMPResult', (done) => { 132 | wampSocket.call(validProcedure).then((data) => { 133 | expect(data).to.be.empty(); 134 | }).catch((err) => { 135 | expect(err).equal(invalidWampServerResponseError); 136 | done(); 137 | }); 138 | 139 | const mockedServerResponse = wampSocket.emit.getCalls()[0].args[2]; 140 | mockedServerResponse(invalidWampServerResponseError); 141 | }); 142 | 143 | 144 | describe('when requestsTimeoutMs is exceeded', () => { 145 | let callRejectionSpy; 146 | 147 | beforeEach((done) => { 148 | clock.restore(); 149 | wampSocket.ackTimeout = 1; 150 | callRejectionSpy = sinon.spy(); 151 | wampSocket.call(validProcedure, validData).catch(callRejectionSpy); 152 | const mockedServerResponse = wampSocket.emit.getCalls()[0].args[2]; 153 | mockedServerResponse(new Error('RPC response timeout exceeded')); 154 | setTimeout(done, wampSocket.ackTimeout + 1); 155 | }); 156 | 157 | it('should reject promise', () => { 158 | expect(callRejectionSpy.calledOnce).to.be.true(); 159 | }); 160 | 161 | it('should reject promise with error = "RPC response timeout exceeded"', () => { 162 | const error = new Error('RPC response timeout exceeded'); 163 | expect(callRejectionSpy.calledWithExactly(error.toString())).to.be.true(); 164 | }); 165 | }); 166 | }); 167 | }); 168 | }); 169 | }); 170 | -------------------------------------------------------------------------------- /WAMPServer.js: -------------------------------------------------------------------------------- 1 | const schemas = require('./schemas'); 2 | 3 | class WAMPServer { 4 | constructor() { 5 | this.endpoints = { 6 | rpc: {}, 7 | event: {}, 8 | }; 9 | } 10 | 11 | /** 12 | * @param {Object} socket - SocketCluster.Socket 13 | * @returns {Object} wampSocket 14 | */ 15 | upgradeToWAMP(socket) { 16 | // register RPC endpoints 17 | socket.on('rpc-request', (request, respond) => { 18 | if (schemas.isValid(request, schemas.RPCRequestSchema)) { 19 | // Needed for backwards-compatibility 20 | request.socketId = socket.id; 21 | this.processWAMPRequest(request, respond); 22 | } else { 23 | respond(`Failed to process RPC request "${request.procedure}" because the request schema was not valid`); 24 | } 25 | }); 26 | // register Event endpoints 27 | Object.keys(this.endpoints.event).forEach((event) => { 28 | if (typeof this.endpoints.event[event] === 'function') { 29 | socket.on(event, this.endpoints.event[event]); 30 | } 31 | }); 32 | 33 | return socket; 34 | } 35 | 36 | /** 37 | * @param {RPCRequestSchema} request 38 | * @param {function} respond 39 | * @returns {undefined} 40 | */ 41 | processWAMPRequest(request, respond) { 42 | const isValidWAMPEndpoint = (endpointType, procedure) => 43 | this.endpoints[endpointType][procedure] && 44 | typeof this.endpoints[endpointType][procedure] === 'function'; 45 | 46 | if (isValidWAMPEndpoint('rpc', request.procedure)) { 47 | return this.endpoints.rpc[request.procedure](request.data, (error, data) => { 48 | respond(error, { 49 | type: schemas.RPCResponseSchema.id, 50 | data, 51 | }); 52 | }); 53 | } else if (isValidWAMPEndpoint('event', request.procedure)) { 54 | return this.endpoints.event[request.procedure](request.data); 55 | } 56 | return respond(`Procedure ${ 57 | request.procedure 58 | } not registered on WAMPServer. Available commands: ${ 59 | this.endpoints 60 | }`); 61 | } 62 | 63 | /** 64 | * @param {Map} endpoints 65 | * @returns {undefined} 66 | */ 67 | registerRPCEndpoints(endpoints) { 68 | this.endpoints.rpc = Object.assign(this.endpoints.rpc, endpoints); 69 | } 70 | 71 | /** 72 | * @param {Map} endpoints 73 | * @returns {undefined} 74 | */ 75 | registerEventEndpoints(endpoints) { 76 | this.endpoints.event = Object.assign(this.endpoints.event, endpoints); 77 | } 78 | 79 | /** 80 | * @param {Map} endpoints 81 | * @returns {undefined} 82 | */ 83 | reassignRPCEndpoints(endpoints) { 84 | this.endpoints.rpc = endpoints; 85 | } 86 | 87 | /** 88 | * @param {Map} endpoints 89 | * @returns {undefined} 90 | */ 91 | reassignEventEndpoints(endpoints) { 92 | this.endpoints.event = endpoints; 93 | } 94 | } 95 | 96 | module.exports = WAMPServer; 97 | -------------------------------------------------------------------------------- /WAMPServer.spec.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node, mocha */ 2 | const sinon = require('sinon'); 3 | const WAMPServer = require('./WAMPServer.js'); 4 | const { expect } = require('./testSetup.spec'); 5 | 6 | describe('WAMPServer', () => { 7 | describe('constructor', () => { 8 | it('create wampServer with endpoints field', () => { 9 | const wampServer = new WAMPServer(); 10 | expect(wampServer).to.have.nested.property('endpoints.rpc').to.be.a('object').and.to.be.empty(); 11 | expect(wampServer).to.have.nested.property('endpoints.event').to.be.a('object').and.to.be.empty(); 12 | }); 13 | }); 14 | 15 | describe('upgradeToWAMP', () => { 16 | it('should add "rpc-request" listener to passed socket', () => { 17 | let socket = { 18 | on: sinon.spy(), 19 | }; 20 | socket = new WAMPServer().upgradeToWAMP(socket); 21 | expect(socket.on.calledOnce).to.be.true(); 22 | expect(socket.on.calledWith('rpc-request')).to.be.true(); 23 | }); 24 | }); 25 | 26 | 27 | describe('registerRPCEndpoints', () => { 28 | it('should add new endpoint to rpc procedures', () => { 29 | const wampServer = new WAMPServer(); 30 | wampServer.registerRPCEndpoints({ endpointA: cb => cb() }); 31 | expect(wampServer.endpoints.rpc).to.have.property('endpointA'); 32 | }); 33 | 34 | it('should add new endpoints to rpc procedures', () => { 35 | const wampServer = new WAMPServer(); 36 | wampServer.registerRPCEndpoints({ 37 | endpointA: cb => cb(), 38 | endpointB: cb => cb(), 39 | }); 40 | expect(wampServer.endpoints.rpc).to.have.property('endpointA'); 41 | expect(wampServer.endpoints.rpc).to.have.property('endpointB'); 42 | }); 43 | }); 44 | 45 | describe('reassignRPCEndpoints', () => { 46 | it('should replace old endpoints with the new', () => { 47 | const wampServer = new WAMPServer(); 48 | wampServer.registerRPCEndpoints({ endpointA: cb => cb() }); 49 | expect(wampServer.endpoints.rpc).to.have.property('endpointA'); 50 | wampServer.reassignRPCEndpoints({ endpointB: cb => cb() }); 51 | expect(wampServer.endpoints.rpc).not.to.have.property('endpointA'); 52 | expect(wampServer.endpoints.rpc).to.have.property('endpointB'); 53 | }); 54 | }); 55 | 56 | describe('registerEventEndpoints', () => { 57 | it('should add new endpoint to event procedures', () => { 58 | const wampServer = new WAMPServer(); 59 | wampServer.registerEventEndpoints({ endpointA: cb => cb() }); 60 | expect(wampServer.endpoints.event).to.have.property('endpointA'); 61 | }); 62 | 63 | it('should add new endpoints to event procedures', () => { 64 | const wampServer = new WAMPServer(); 65 | wampServer.registerEventEndpoints({ 66 | endpointA: cb => cb(), 67 | endpointB: cb => cb(), 68 | }); 69 | expect(wampServer.endpoints.event).to.have.property('endpointA'); 70 | expect(wampServer.endpoints.event).to.have.property('endpointB'); 71 | }); 72 | }); 73 | 74 | describe('reassignEventEndpoints', () => { 75 | it('should replace old endpoints with the new', () => { 76 | const wampServer = new WAMPServer(); 77 | wampServer.registerEventEndpoints({ endpointA: cb => cb() }); 78 | expect(wampServer.endpoints.event).to.have.property('endpointA'); 79 | wampServer.reassignEventEndpoints({ endpointB: cb => cb() }); 80 | expect(wampServer.endpoints.event).not.to.have.property('endpointA'); 81 | expect(wampServer.endpoints.event).to.have.property('endpointB'); 82 | }); 83 | }); 84 | 85 | describe('processWAMPRequest', () => { 86 | it('should throw an error when trying to invoke an unregistered procedure', () => { 87 | const socket = { 88 | on: sinon.spy(), 89 | emit: sinon.spy(), 90 | }; 91 | const wampServer = new WAMPServer(); 92 | wampServer.upgradeToWAMP(socket); 93 | wampServer.processWAMPRequest({ procedure: 'not-registered-procedure' }, (err) => { 94 | expect(/Procedure not-registered-procedure not registered on WAMPServer/.test(err.toString())).to.be.true(); 95 | }); 96 | }); 97 | 98 | it('should invoke procedure when proper request passed', () => { 99 | const socket = { 100 | on: sinon.spy(), 101 | send: sinon.spy(), 102 | }; 103 | 104 | const endpoint = { procedureA: sinon.spy() }; 105 | const wampServer = new WAMPServer(); 106 | wampServer.upgradeToWAMP(socket); 107 | wampServer.registerRPCEndpoints(endpoint); 108 | wampServer.processWAMPRequest({ procedure: 'procedureA', data: 'valueA' }, () => {}); 109 | expect(endpoint.procedureA.calledOnce).to.be.true(); 110 | expect(endpoint.procedureA.calledWith('valueA')).to.be.true(); 111 | }); 112 | }); 113 | }); 114 | -------------------------------------------------------------------------------- /dist/MasterWAMPServer.bundle.min.js: -------------------------------------------------------------------------------- 1 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("wampSocketCluster",[],t):"object"==typeof exports?exports.wampSocketCluster=t():e.wampSocketCluster=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=17)}([function(e,t,r){"use strict";function n(e,t){return t+": "+e.toString()+"\n"}function o(e,t,r,n){"object"===(void 0===r?"undefined":c(r))?t[n]=a(e[n],r):-1===e.indexOf(r)&&t.push(r)}function i(e,t,r){t[r]=e[r]}function s(e,t,r,n){"object"===c(t[n])&&t[n]&&e[n]?r[n]=a(e[n],t[n]):r[n]=t[n]}function a(e,t){var r=Array.isArray(t),n=r&&[]||{};return r?(e=e||[],n=n.concat(e),t.forEach(o.bind(null,e,n))):(e&&"object"===(void 0===e?"undefined":c(e))&&Object.keys(e).forEach(i.bind(null,e,n)),Object.keys(t).forEach(s.bind(null,e,t,n))),n}function u(e){return"/"+encodeURIComponent(e).replace(/~/g,"%7E")}var c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},h=r(2),f=t.ValidationError=function(e,t,r,n,o,i){n&&(this.property=n),e&&(this.message=e),r&&(r.id?this.schema=r.id:this.schema=r),t&&(this.instance=t),this.name=o,this.argument=i,this.stack=this.toString()};f.prototype.toString=function(){return this.property+" "+this.message};var p=t.ValidatorResult=function(e,t,r,n){this.instance=e,this.schema=t,this.propertyPath=n.propertyPath,this.errors=[],this.throwError=r&&r.throwError,this.disableFormat=r&&!0===r.disableFormat};p.prototype.addError=function(e){var t;if("string"==typeof e)t=new f(e,this.instance,this.schema,this.propertyPath);else{if(!e)throw new Error("Missing error detail");if(!e.message)throw new Error("Missing error message");if(!e.name)throw new Error("Missing validator type");t=new f(e.message,this.instance,this.schema,this.propertyPath,e.name,e.argument)}if(this.throwError)throw t;return this.errors.push(t),t},p.prototype.importErrors=function(e){"string"==typeof e||e&&e.validatorType?this.addError(e):e&&e.errors&&Array.prototype.push.apply(this.errors,e.errors)},p.prototype.toString=function(e){return this.errors.map(n).join("")},Object.defineProperty(p.prototype,"valid",{get:function(){return!this.errors.length}});var l=t.SchemaError=function e(t,r){this.message=t,this.schema=r,Error.call(this,t),Error.captureStackTrace(this,e)};l.prototype=Object.create(Error.prototype,{constructor:{value:l,enumerable:!1},name:{value:"SchemaError",enumerable:!1}});var d=t.SchemaContext=function(e,t,r,n,o){this.schema=e,this.options=t,this.propertyPath=r,this.base=n,this.schemas=o};d.prototype.resolve=function(e){return h.resolve(this.base,e)},d.prototype.makeChild=function(e,t){var r=void 0===t?this.propertyPath:this.propertyPath+y(t),n=h.resolve(this.base,e.id||""),o=new d(e,this.options,r,n,Object.create(this.schemas));return e.id&&!o.schemas[n]&&(o.schemas[n]=e),o};var m=t.FORMAT_REGEXPS={"date-time":/^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])[tT ](2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])(\.\d+)?([zZ]|[+-]([0-5][0-9]):(60|[0-5][0-9]))$/,date:/^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])$/,time:/^(2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])$/,email:/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/,"ip-address":/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,ipv6:/^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/,uri:/^[a-zA-Z][a-zA-Z0-9+-.]*:[^\s]*$/,color:/^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/,hostname:/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/,"host-name":/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/,alpha:/^[a-zA-Z]+$/,alphanumeric:/^[a-zA-Z0-9]+$/,"utc-millisec":function(e){return"string"==typeof e&&parseFloat(e)===parseInt(e,10)&&!isNaN(e)},regex:function(e){var t=!0;try{new RegExp(e)}catch(e){t=!1}return t},style:/\s*(.+?):\s*([^;]+);?/g,phone:/^\+(?:[0-9] ?){6,14}[0-9]$/};m.regexp=m.regex,m.pattern=m.regex,m.ipv4=m["ip-address"],t.isFormat=function(e,t,r){if("string"==typeof e&&void 0!==m[t]){if(m[t]instanceof RegExp)return m[t].test(e);if("function"==typeof m[t])return m[t](e)}else if(r&&r.customFormats&&"function"==typeof r.customFormats[t])return r.customFormats[t](e);return!0};var y=t.makeSuffix=function(e){return e=e.toString(),e.match(/[.\s\[\]]/)||e.match(/^[\d]/)?e.match(/^\d+$/)?"["+e+"]":"["+JSON.stringify(e)+"]":"."+e};t.deepCompareStrict=function e(t,r){if((void 0===t?"undefined":c(t))!==(void 0===r?"undefined":c(r)))return!1;if(t instanceof Array)return r instanceof Array&&(t.length===r.length&&t.every(function(n,o){return e(t[o],r[o])}));if("object"===(void 0===t?"undefined":c(t))){if(!t||!r)return t===r;var n=Object.keys(t),o=Object.keys(r);return n.length===o.length&&n.every(function(n){return e(t[n],r[n])})}return t===r},e.exports.deepMerge=a,t.objectGetPath=function(e,t){for(var r,n=t.split("/").slice(1);"string"==typeof(r=n.shift());){var o=decodeURIComponent(r.replace(/~0/,"~").replace(/~1/g,"/"));if(!(o in e))return;e=e[o]}return e},t.encodePath=function(e){return e.map(u).join("")}},function(e,t,r){"use strict";function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var o,i=r(4).Validator,s=new i,a={id:"/RPCResponse",type:"object",properties:{type:{type:"string"},data:{}},required:["type","data"]},u={id:"/RPCRequest",type:"object",properties:{type:{type:"string"},procedure:{type:"string"},data:{}},required:["type","procedure"]},c={id:"/EventRequestSchema",type:"object",properties:{type:{type:"string"},procedure:{type:"string"},data:{}},required:["type","procedure"]},h={id:"/MasterRPCRequest",type:"object",properties:{type:{type:"string"},procedure:{type:"string"},data:{}},required:["type","procedure"]},f={id:"/InterProcessRPCRequestSchema",type:"object",properties:{type:{type:"string"},procedure:{type:"string"},data:{}},required:["type","procedure"]},p={id:"/MasterConfigRequestSchema",type:"object",properties:{type:{type:"string"},registeredEvents:{type:"array"},config:{type:"object"}},required:["type","registeredEvents","config"]},l=n({},a.id,u.id),d=(o={},n(o,u.id,a.id),n(o,h.id,a.id),o),m=function(e,t){return s.validate(e,t).valid&&e.type===t.id};e.exports={EventRequestSchema:c,RPCRequestSchema:u,RPCResponseSchema:a,InterProcessRPCRequestSchema:f,MasterRPCRequestSchema:h,MasterConfigRequestSchema:p,resToReqMap:l,reqToResMap:d,isValid:m}},function(e,t,r){"use strict";function n(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}function o(e,t,r){if(e&&h.isObject(e)&&e instanceof n)return e;var o=new n;return o.parse(e,t,r),o}function i(e){return h.isString(e)&&(e=o(e)),e instanceof n?e.format():n.prototype.format.call(e)}function s(e,t){return o(e,!1,!0).resolve(t)}function a(e,t){return e?o(e,!1,!0).resolveObject(t):t}var u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c=r(7),h=r(11);t.parse=o,t.resolve=s,t.resolveObject=a,t.format=i,t.Url=n;var f=/^([a-z0-9.+-]+:)/i,p=/:[0-9]*$/,l=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,d=["<",">",'"',"`"," ","\r","\n","\t"],m=["{","}","|","\\","^","`"].concat(d),y=["'"].concat(m),v=["%","/","?",";","#"].concat(y),b=["/","?","#"],g=/^[+a-z0-9A-Z_-]{0,63}$/,S=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,w={javascript:!0,"javascript:":!0},O={javascript:!0,"javascript:":!0},A={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},x=r(10);n.prototype.parse=function(e,t,r){if(!h.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+(void 0===e?"undefined":u(e)));var n=e.indexOf("?"),o=-1!==n&&n127?M+="x":M+=$[z];if(!M.match(g)){var T=I.slice(0,P),_=I.slice(P+1),N=$.match(S);N&&(T.push(N[1]),_.unshift(N[2])),_.length&&(a="/"+_.join(".")+a),this.hostname=T.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),k||(this.hostname=c.toASCII(this.hostname));var U=this.port?":"+this.port:"",V=this.hostname||"";this.host=V+U,this.href+=this.host,k&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==a[0]&&(a="/"+a))}if(!w[m])for(var P=0,F=y.length;P0)&&r.host.split("@");j&&(r.auth=j.shift(),r.host=r.hostname=j.shift())}return r.search=e.search,r.query=e.query,h.isNull(r.pathname)&&h.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r}if(!w.length)return r.pathname=null,r.search?r.path="/"+r.search:r.path=null,r.href=r.format(),r;for(var E=w.slice(-1)[0],P=(r.host||e.host||w.length>1)&&("."===E||".."===E)||""===E,R=0,C=w.length;C>=0;C--)E=w[C],"."===E?w.splice(C,1):".."===E?(w.splice(C,1),R++):R&&(w.splice(C,1),R--);if(!g&&!S)for(;R--;R)w.unshift("..");!g||""===w[0]||w[0]&&"/"===w[0].charAt(0)||w.unshift(""),P&&"/"!==w.join("/").substr(-1)&&w.push("");var q=""===w[0]||w[0]&&"/"===w[0].charAt(0);if(x){r.hostname=r.host=q?"":w.length?w.shift():"";var j=!!(r.host&&r.host.indexOf("@")>0)&&r.host.split("@");j&&(r.auth=j.shift(),r.host=r.hostname=j.shift())}return g=g||r.host&&w.length,g&&!q&&w.unshift(""),w.length?r.pathname=w.join("/"):(r.pathname=null,r.path=null),h.isNull(r.pathname)&&h.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=e.auth||r.auth,r.slashes=r.slashes||e.slashes,r.href=r.format(),r},n.prototype.parseHost=function(){var e=this.host,t=p.exec(e);t&&(t=t[0],":"!==t&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)}},function(e,t){(function(t){e.exports=t}).call(t,{})},function(e,t,r){"use strict";var n=e.exports.Validator=r(6);e.exports.ValidatorResult=r(0).ValidatorResult,e.exports.ValidationError=r(0).ValidationError,e.exports.SchemaError=r(0).SchemaError,e.exports.validate=function(e,t,r){return(new n).validate(e,t,r)}},function(e,t,r){"use strict";function n(e,t,r,n,o){var i=this.validateSchema(e,o,t,r);return!i.valid&&n instanceof Function&&n(i),i.valid}function o(e,t,r,n,o,i){if(!t.properties||void 0===t.properties[o])if(!1===t.additionalProperties)i.addError({name:"additionalProperties",argument:o,message:"additionalProperty "+JSON.stringify(o)+" exists in instance when not allowed"});else{var s=t.additionalProperties||{},a=this.validateSchema(e[o],s,r,n.makeChild(s,o));a.instance!==i.instance[o]&&(i.instance[o]=a.instance),i.importErrors(a)}}function i(e,t,r){var n,o=r.length;for(n=t+1,o;n"||e+""});o.addError({name:"type",argument:s,message:"is not of a type(s) "+s})}return o},f.anyOf=function(e,t,r,o){if(void 0===e)return null;var i=new u(e,t,r,o),s=new u(e,t,r,o);if(!Array.isArray(t.anyOf))throw new c("anyOf must be an array");if(!t.anyOf.some(n.bind(this,e,r,o,function(e){s.importErrors(e)}))){var a=t.anyOf.map(function(e,t){return e.id&&"<"+e.id+">"||e.title&&JSON.stringify(e.title)||e.$ref&&"<"+e.$ref+">"||"[subschema "+t+"]"});r.nestedErrors&&i.importErrors(s),i.addError({name:"anyOf",argument:a,message:"is not any of "+a.join(",")})}return i},f.allOf=function(e,t,r,n){if(void 0===e)return null;if(!Array.isArray(t.allOf))throw new c("allOf must be an array");var o=new u(e,t,r,n),i=this;return t.allOf.forEach(function(t,s){var a=i.validateSchema(e,t,r,n);if(!a.valid){var u=t.id&&"<"+t.id+">"||t.title&&JSON.stringify(t.title)||t.$ref&&"<"+t.$ref+">"||"[subschema "+s+"]";o.addError({name:"allOf",argument:{id:u,length:a.errors.length,valid:a},message:"does not match allOf schema "+u+" with "+a.errors.length+" error[s]:"}),o.importErrors(a)}}),o},f.oneOf=function(e,t,r,o){if(void 0===e)return null;if(!Array.isArray(t.oneOf))throw new c("oneOf must be an array");var i=new u(e,t,r,o),s=new u(e,t,r,o),a=t.oneOf.filter(n.bind(this,e,r,o,function(e){s.importErrors(e)})).length,h=t.oneOf.map(function(e,t){return e.id&&"<"+e.id+">"||e.title&&JSON.stringify(e.title)||e.$ref&&"<"+e.$ref+">"||"[subschema "+t+"]"});return 1!==a&&(r.nestedErrors&&i.importErrors(s),i.addError({name:"oneOf",argument:h,message:"is not exactly one from "+h.join(",")})),i},f.properties=function(e,t,r,n){if(void 0!==e&&e instanceof Object){var o=new u(e,t,r,n),i=t.properties||{};for(var s in i){var a=(e||void 0)&&e[s],c=this.validateSchema(a,i[s],r,n.makeChild(i[s],s));c.instance!==o.instance[s]&&(o.instance[s]=c.instance),o.importErrors(c)}return o}},f.patternProperties=function(e,t,r,n){if(void 0!==e&&this.types.object(e)){var i=new u(e,t,r,n),s=t.patternProperties||{};for(var a in e){var c=!0;for(var h in s){if(new RegExp(h).test(a)){c=!1;var f=this.validateSchema(e[a],s[h],r,n.makeChild(s[h],a));f.instance!==i.instance[a]&&(i.instance[a]=f.instance),i.importErrors(f)}}c&&o.call(this,e,t,r,n,a,i)}return i}},f.additionalProperties=function(e,t,r,n){if(void 0!==e&&this.types.object(e)){if(t.patternProperties)return null;var i=new u(e,t,r,n);for(var s in e)o.call(this,e,t,r,n,s,i);return i}},f.minProperties=function(e,t,r,n){if(!e||"object"!==(void 0===e?"undefined":s(e)))return null;var o=new u(e,t,r,n);return Object.keys(e).length>=t.minProperties||o.addError({name:"minProperties",argument:t.minProperties,message:"does not meet minimum property length of "+t.minProperties}),o},f.maxProperties=function(e,t,r,n){if(!e||"object"!==(void 0===e?"undefined":s(e)))return null;var o=new u(e,t,r,n);return Object.keys(e).length<=t.maxProperties||o.addError({name:"maxProperties",argument:t.maxProperties,message:"does not meet maximum property length of "+t.maxProperties}),o},f.items=function(e,t,r,n){if(!Array.isArray(e))return null;var o=this,i=new u(e,t,r,n);return void 0!==e&&t.items?(e.every(function(e,s){var a=Array.isArray(t.items)?t.items[s]||t.additionalItems:t.items;if(void 0===a)return!0;if(!1===a)return i.addError({name:"items",message:"additionalItems not permitted"}),!1;var u=o.validateSchema(e,a,r,n.makeChild(a,s));return u.instance!==i.instance[s]&&(i.instance[s]=u.instance),i.importErrors(u),!0}),i):i},f.minimum=function(e,t,r,n){if("number"!=typeof e)return null;var o=new u(e,t,r,n),i=!0;return i=t.exclusiveMinimum&&!0===t.exclusiveMinimum?e>t.minimum:e>=t.minimum,i||o.addError({name:"minimum",argument:t.minimum,message:"must have a minimum value of "+t.minimum}),o},f.maximum=function(e,t,r,n){if("number"!=typeof e)return null;var o,i=new u(e,t,r,n);return o=t.exclusiveMaximum&&!0===t.exclusiveMaximum?e=t.minLength||o.addError({name:"minLength",argument:t.minLength,message:"does not meet minimum length of "+t.minLength}),o},f.maxLength=function(e,t,r,n){if("string"!=typeof e)return null;var o=new u(e,t,r,n);return e.length<=t.maxLength||o.addError({name:"maxLength",argument:t.maxLength,message:"does not meet maximum length of "+t.maxLength}),o},f.minItems=function(e,t,r,n){if(!Array.isArray(e))return null;var o=new u(e,t,r,n);return e.length>=t.minItems||o.addError({name:"minItems",argument:t.minItems,message:"does not meet minimum length of "+t.minItems}),o},f.maxItems=function(e,t,r,n){if(!Array.isArray(e))return null;var o=new u(e,t,r,n);return e.length<=t.maxItems||o.addError({name:"maxItems",argument:t.maxItems,message:"does not meet maximum length of "+t.maxItems}),o},f.uniqueItems=function(e,t,r,n){function o(e,t,r){for(var n=t+1;n"||s;i.addError({name:"not",argument:a,message:"is of prohibited type "+a})}}),i):null},e.exports=h},function(e,t,r){"use strict";function n(e){var t="string"==typeof e?e:e.$ref;return"string"==typeof t&&t}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=r(2),s=r(5),a=r(0),u=a.ValidatorResult,c=a.SchemaError,h=a.SchemaContext,f=function e(){this.customFormats=Object.create(e.prototype.customFormats),this.schemas={},this.unresolvedRefs=[],this.types=Object.create(p),this.attributes=Object.create(s.validators)};f.prototype.customFormats={},f.prototype.schemas=null,f.prototype.types=null,f.prototype.attributes=null,f.prototype.unresolvedRefs=null,f.prototype.addSchema=function(e,t){if(!e)return null;var r=t||e.id;return this.addSubSchema(r,e),r&&(this.schemas[r]=e),this.schemas[r]},f.prototype.addSubSchema=function(e,t){if(t&&"object"==(void 0===t?"undefined":o(t))){if(t.$ref){var r=i.resolve(e,t.$ref);return void(void 0===this.schemas[r]&&(this.schemas[r]=null,this.unresolvedRefs.push(r)))}var n=t.id&&i.resolve(e,t.id),s=n||e;if(n){if(this.schemas[n]){if(!a.deepCompareStrict(this.schemas[n],t))throw new Error("Schema <"+t+"> already exists with different definition");return this.schemas[n]}this.schemas[n]=t;var u=n.replace(/^([^#]*)#$/,"$1");this.schemas[u]=t}return this.addSubSchemaArray(s,t.items instanceof Array?t.items:[t.items]),this.addSubSchemaArray(s,t.extends instanceof Array?t.extends:[t.extends]),this.addSubSchema(s,t.additionalItems),this.addSubSchemaObject(s,t.properties),this.addSubSchema(s,t.additionalProperties),this.addSubSchemaObject(s,t.definitions),this.addSubSchemaObject(s,t.patternProperties),this.addSubSchemaObject(s,t.dependencies),this.addSubSchemaArray(s,t.disallow),this.addSubSchemaArray(s,t.allOf),this.addSubSchemaArray(s,t.anyOf),this.addSubSchemaArray(s,t.oneOf),this.addSubSchema(s,t.not),this.schemas[n]}},f.prototype.addSubSchemaArray=function(e,t){if(t instanceof Array)for(var r=0;r",e);var u=a.objectGetPath(r.schemas[s],o.substr(1));if(void 0===u)throw new c("no such schema "+o+" located in <"+s+">",e);return{subschema:u,switchSchema:t}},f.prototype.testType=function(e,t,r,n,i){if("function"==typeof this.types[i])return this.types[i].call(this,e);if(i&&"object"==(void 0===i?"undefined":o(i))){var s=this.validateSchema(e,i,r,n);return void 0===s||!(s&&s.errors.length)}return!0};var p=f.prototype.types={};p.string=function(e){return"string"==typeof e},p.number=function(e){return"number"==typeof e&&isFinite(e)},p.integer=function(e){return"number"==typeof e&&e%1==0},p.boolean=function(e){return"boolean"==typeof e},p.array=function(e){return e instanceof Array},p.null=function(e){return null===e},p.date=function(e){return e instanceof Date},p.any=function(e){return!0},p.object=function(e){return e&&"object"===(void 0===e?"undefined":o(e))&&!(e instanceof Array)&&!(e instanceof Date)},e.exports=f},function(e,t,r){"use strict";(function(e,n){var o,i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(s){function a(e){throw new RangeError(z[e])}function u(e,t){for(var r=e.length,n=[];r--;)n[r]=t(e[r]);return n}function c(e,t){var r=e.split("@"),n="";return r.length>1&&(n=r[0]+"@",e=r[1]),e=e.replace(M,"."),n+u(e.split("."),t).join(".")}function h(e){for(var t,r,n=[],o=0,i=e.length;o=55296&&t<=56319&&o65535&&(e-=65536,t+=_(e>>>10&1023|55296),e=56320|1023&e),t+=_(e)}).join("")}function p(e){return e-48<10?e-22:e-65<26?e-65:e-97<26?e-97:j}function l(e,t){return e+22+75*(e<26)-((0!=t)<<5)}function d(e,t,r){var n=0;for(e=r?T(e/C):e>>1,e+=T(e/t);e>Z*P>>1;n+=j)e=T(e/Z);return T(n+(Z+1)*e/(e+R))}function m(e){var t,r,n,o,i,s,u,c,h,l,m=[],y=e.length,v=0,b=k,g=q;for(r=e.lastIndexOf(I),r<0&&(r=0),n=0;n=128&&a("not-basic"),m.push(e.charCodeAt(n));for(o=r>0?r+1:0;o=y&&a("invalid-input"),c=p(e.charCodeAt(o++)),(c>=j||c>T((x-v)/s))&&a("overflow"),v+=c*s,h=u<=g?E:u>=g+P?P:u-g,!(cT(x/l)&&a("overflow"),s*=l;t=m.length+1,g=d(v-i,t,0==i),T(v/t)>x-b&&a("overflow"),b+=T(v/t),v%=t,m.splice(v++,0,b)}return f(m)}function y(e){var t,r,n,o,i,s,u,c,f,p,m,y,v,b,g,S=[];for(e=h(e),y=e.length,t=k,r=0,i=q,s=0;s=t&&mT((x-r)/v)&&a("overflow"),r+=(u-t)*v,t=u,s=0;sx&&a("overflow"),m==t){for(c=r,f=j;p=f<=i?E:f>=i+P?P:f-i,!(c= 0x80 (not a basic code point)","invalid-input":"Invalid input"},Z=j-E,T=Math.floor,_=String.fromCharCode;if(O={version:"1.4.1",ucs2:{decode:h,encode:f},decode:m,encode:y,toASCII:b,toUnicode:v},"object"==i(r(3))&&r(3))void 0!==(o=function(){return O}.call(t,r,t,e))&&(e.exports=o);else if(g&&S)if(e.exports==g)S.exports=O;else for(A in O)O.hasOwnProperty(A)&&(g[A]=O[A]);else s.punycode=O}(void 0)}).call(t,r(13)(e),r(12))},function(e,t,r){"use strict";function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,r,i){t=t||"&",r=r||"=";var s={};if("string"!=typeof e||0===e.length)return s;var a=/\+/g;e=e.split(t);var u=1e3;i&&"number"==typeof i.maxKeys&&(u=i.maxKeys);var c=e.length;u>0&&c>u&&(c=u);for(var h=0;h=0?(f=m.substr(0,y),p=m.substr(y+1)):(f=m,p=""),l=decodeURIComponent(f),d=decodeURIComponent(p),n(s,l)?o(s[l])?s[l].push(d):s[l]=[s[l],d]:s[l]=d}return s};var o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},function(e,t,r){"use strict";function n(e,t){if(e.map)return e.map(t);for(var r=[],n=0;n2&&void 0!==arguments[2]?arguments[2]:void 0;if("string"!=typeof t)return n;for(var r=t.split("."),o=e,i=0;i1&&void 0!==arguments[1]?arguments[1]:1e4,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){};o(this,t);var u=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return u.worker=e,u.sockets=e.scServer.clients,u.endpoints.slaveRpc={},u.config={},u.internalRequestsTimeoutMs=n,u.worker.on("masterMessage",function(e,t){p.isValid(e,p.MasterConfigRequestSchema)?(u.config=Object.assign({},u.config,e.config),e.registeredEvents&&u.registerEventEndpoints(e.registeredEvents.reduce(function(e,t){return Object.assign(e,r({},t,function(e){u.worker.sendToMaster({data:e,procedure:t,type:p.EventRequestSchema.id})}))},{})),s(null,u),s=function(){}):console.error('Received invalid master message payload of type "'+e.type+'"')}),u}return s(t,e),u(t,[{key:"sendToMaster",value:function(e,t,n){var r={type:p.InterProcessRPCRequestSchema.id,procedure:e,data:t};n?this.worker.sendToMaster(r,function(e,t){return e?n(e):n(null,t.data)}):this.worker.sendToMaster(r)}},{key:"processWAMPRequest",value:function(e,t){d.validate(e,p.RPCRequestSchema).valid&&(this.endpoints.slaveRpc[e.procedure]&&"function"==typeof this.endpoints.slaveRpc[e.procedure]?t?this.endpoints.slaveRpc[e.procedure](e,function(e,n){t(e,{type:p.RPCResponseSchema.id,data:n})}):this.endpoints.slaveRpc[e.procedure](e):(e.type=p.MasterRPCRequestSchema.id,this.worker.sendToMaster(e,t)))}},{key:"reassignRPCSlaveEndpoints",value:function(e){this.endpoints.slaveRpc=e}},{key:"registerRPCSlaveEndpoints",value:function(e){this.endpoints.slaveRpc=Object.assign(this.endpoints.slaveRpc,e)}}]),t}(a);e.exports=f}])}); -------------------------------------------------------------------------------- /dist/WAMPClient.bundle.min.js: -------------------------------------------------------------------------------- 1 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("wampSocketCluster",[],t):"object"==typeof exports?exports.wampSocketCluster=t():e.wampSocketCluster=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=16)}([function(e,t,r){"use strict";function n(e,t){return t+": "+e.toString()+"\n"}function o(e,t,r,n){"object"===(void 0===r?"undefined":c(r))?t[n]=s(e[n],r):-1===e.indexOf(r)&&t.push(r)}function i(e,t,r){t[r]=e[r]}function a(e,t,r,n){"object"===c(t[n])&&t[n]&&e[n]?r[n]=s(e[n],t[n]):r[n]=t[n]}function s(e,t){var r=Array.isArray(t),n=r&&[]||{};return r?(e=e||[],n=n.concat(e),t.forEach(o.bind(null,e,n))):(e&&"object"===(void 0===e?"undefined":c(e))&&Object.keys(e).forEach(i.bind(null,e,n)),Object.keys(t).forEach(a.bind(null,e,t,n))),n}function u(e){return"/"+encodeURIComponent(e).replace(/~/g,"%7E")}var c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},h=r(2),f=t.ValidationError=function(e,t,r,n,o,i){n&&(this.property=n),e&&(this.message=e),r&&(r.id?this.schema=r.id:this.schema=r),t&&(this.instance=t),this.name=o,this.argument=i,this.stack=this.toString()};f.prototype.toString=function(){return this.property+" "+this.message};var l=t.ValidatorResult=function(e,t,r,n){this.instance=e,this.schema=t,this.propertyPath=n.propertyPath,this.errors=[],this.throwError=r&&r.throwError,this.disableFormat=r&&!0===r.disableFormat};l.prototype.addError=function(e){var t;if("string"==typeof e)t=new f(e,this.instance,this.schema,this.propertyPath);else{if(!e)throw new Error("Missing error detail");if(!e.message)throw new Error("Missing error message");if(!e.name)throw new Error("Missing validator type");t=new f(e.message,this.instance,this.schema,this.propertyPath,e.name,e.argument)}if(this.throwError)throw t;return this.errors.push(t),t},l.prototype.importErrors=function(e){"string"==typeof e||e&&e.validatorType?this.addError(e):e&&e.errors&&Array.prototype.push.apply(this.errors,e.errors)},l.prototype.toString=function(e){return this.errors.map(n).join("")},Object.defineProperty(l.prototype,"valid",{get:function(){return!this.errors.length}});var m=t.SchemaError=function e(t,r){this.message=t,this.schema=r,Error.call(this,t),Error.captureStackTrace(this,e)};m.prototype=Object.create(Error.prototype,{constructor:{value:m,enumerable:!1},name:{value:"SchemaError",enumerable:!1}});var p=t.SchemaContext=function(e,t,r,n,o){this.schema=e,this.options=t,this.propertyPath=r,this.base=n,this.schemas=o};p.prototype.resolve=function(e){return h.resolve(this.base,e)},p.prototype.makeChild=function(e,t){var r=void 0===t?this.propertyPath:this.propertyPath+y(t),n=h.resolve(this.base,e.id||""),o=new p(e,this.options,r,n,Object.create(this.schemas));return e.id&&!o.schemas[n]&&(o.schemas[n]=e),o};var d=t.FORMAT_REGEXPS={"date-time":/^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])[tT ](2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])(\.\d+)?([zZ]|[+-]([0-5][0-9]):(60|[0-5][0-9]))$/,date:/^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])$/,time:/^(2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])$/,email:/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/,"ip-address":/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,ipv6:/^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/,uri:/^[a-zA-Z][a-zA-Z0-9+-.]*:[^\s]*$/,color:/^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/,hostname:/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/,"host-name":/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/,alpha:/^[a-zA-Z]+$/,alphanumeric:/^[a-zA-Z0-9]+$/,"utc-millisec":function(e){return"string"==typeof e&&parseFloat(e)===parseInt(e,10)&&!isNaN(e)},regex:function(e){var t=!0;try{new RegExp(e)}catch(e){t=!1}return t},style:/\s*(.+?):\s*([^;]+);?/g,phone:/^\+(?:[0-9] ?){6,14}[0-9]$/};d.regexp=d.regex,d.pattern=d.regex,d.ipv4=d["ip-address"],t.isFormat=function(e,t,r){if("string"==typeof e&&void 0!==d[t]){if(d[t]instanceof RegExp)return d[t].test(e);if("function"==typeof d[t])return d[t](e)}else if(r&&r.customFormats&&"function"==typeof r.customFormats[t])return r.customFormats[t](e);return!0};var y=t.makeSuffix=function(e){return e=e.toString(),e.match(/[.\s\[\]]/)||e.match(/^[\d]/)?e.match(/^\d+$/)?"["+e+"]":"["+JSON.stringify(e)+"]":"."+e};t.deepCompareStrict=function e(t,r){if((void 0===t?"undefined":c(t))!==(void 0===r?"undefined":c(r)))return!1;if(t instanceof Array)return r instanceof Array&&(t.length===r.length&&t.every(function(n,o){return e(t[o],r[o])}));if("object"===(void 0===t?"undefined":c(t))){if(!t||!r)return t===r;var n=Object.keys(t),o=Object.keys(r);return n.length===o.length&&n.every(function(n){return e(t[n],r[n])})}return t===r},e.exports.deepMerge=s,t.objectGetPath=function(e,t){for(var r,n=t.split("/").slice(1);"string"==typeof(r=n.shift());){var o=decodeURIComponent(r.replace(/~0/,"~").replace(/~1/g,"/"));if(!(o in e))return;e=e[o]}return e},t.encodePath=function(e){return e.map(u).join("")}},function(e,t,r){"use strict";function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var o,i=r(4).Validator,a=new i,s={id:"/RPCResponse",type:"object",properties:{type:{type:"string"},data:{}},required:["type","data"]},u={id:"/RPCRequest",type:"object",properties:{type:{type:"string"},procedure:{type:"string"},data:{}},required:["type","procedure"]},c={id:"/EventRequestSchema",type:"object",properties:{type:{type:"string"},procedure:{type:"string"},data:{}},required:["type","procedure"]},h={id:"/MasterRPCRequest",type:"object",properties:{type:{type:"string"},procedure:{type:"string"},data:{}},required:["type","procedure"]},f={id:"/InterProcessRPCRequestSchema",type:"object",properties:{type:{type:"string"},procedure:{type:"string"},data:{}},required:["type","procedure"]},l={id:"/MasterConfigRequestSchema",type:"object",properties:{type:{type:"string"},registeredEvents:{type:"array"},config:{type:"object"}},required:["type","registeredEvents","config"]},m=n({},s.id,u.id),p=(o={},n(o,u.id,s.id),n(o,h.id,s.id),o),d=function(e,t){return a.validate(e,t).valid&&e.type===t.id};e.exports={EventRequestSchema:c,RPCRequestSchema:u,RPCResponseSchema:s,InterProcessRPCRequestSchema:f,MasterRPCRequestSchema:h,MasterConfigRequestSchema:l,resToReqMap:m,reqToResMap:p,isValid:d}},function(e,t,r){"use strict";function n(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}function o(e,t,r){if(e&&h.isObject(e)&&e instanceof n)return e;var o=new n;return o.parse(e,t,r),o}function i(e){return h.isString(e)&&(e=o(e)),e instanceof n?e.format():n.prototype.format.call(e)}function a(e,t){return o(e,!1,!0).resolve(t)}function s(e,t){return e?o(e,!1,!0).resolveObject(t):t}var u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c=r(7),h=r(11);t.parse=o,t.resolve=a,t.resolveObject=s,t.format=i,t.Url=n;var f=/^([a-z0-9.+-]+:)/i,l=/:[0-9]*$/,m=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,p=["<",">",'"',"`"," ","\r","\n","\t"],d=["{","}","|","\\","^","`"].concat(p),y=["'"].concat(d),v=["%","/","?",";","#"].concat(y),b=["/","?","#"],g=/^[+a-z0-9A-Z_-]{0,63}$/,S=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,w={javascript:!0,"javascript:":!0},A={javascript:!0,"javascript:":!0},x={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},O=r(10);n.prototype.parse=function(e,t,r){if(!h.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+(void 0===e?"undefined":u(e)));var n=e.indexOf("?"),o=-1!==n&&n127?z+="x":z+=k[Z];if(!z.match(g)){var N=F.slice(0,P),U=F.slice(P+1),T=k.match(S);T&&(N.push(T[1]),U.unshift(T[2])),U.length&&(s="/"+U.join(".")+s),this.hostname=N.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),I||(this.hostname=c.toASCII(this.hostname));var L=this.port?":"+this.port:"",V=this.hostname||"";this.host=V+L,this.href+=this.host,I&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==s[0]&&(s="/"+s))}if(!w[d])for(var P=0,$=y.length;P<$;P++){var J=y[P];if(-1!==s.indexOf(J)){var B=encodeURIComponent(J);B===J&&(B=escape(J)),s=s.split(J).join(B)}}var _=s.indexOf("#");-1!==_&&(this.hash=s.substr(_),s=s.slice(0,_));var G=s.indexOf("?");if(-1!==G?(this.search=s.substr(G),this.query=s.substr(G+1),t&&(this.query=O.parse(this.query)),s=s.slice(0,G)):t&&(this.search="",this.query={}),s&&(this.pathname=s),x[d]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var L=this.pathname||"",D=this.search||"";this.path=L+D}return this.href=this.format(),this},n.prototype.format=function(){var e=this.auth||"";e&&(e=encodeURIComponent(e),e=e.replace(/%3A/i,":"),e+="@");var t=this.protocol||"",r=this.pathname||"",n=this.hash||"",o=!1,i="";this.host?o=e+this.host:this.hostname&&(o=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(o+=":"+this.port)),this.query&&h.isObject(this.query)&&Object.keys(this.query).length&&(i=O.stringify(this.query));var a=this.search||i&&"?"+i||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||x[t])&&!1!==o?(o="//"+(o||""),r&&"/"!==r.charAt(0)&&(r="/"+r)):o||(o=""),n&&"#"!==n.charAt(0)&&(n="#"+n),a&&"?"!==a.charAt(0)&&(a="?"+a),r=r.replace(/[?#]/g,function(e){return encodeURIComponent(e)}),a=a.replace("#","%23"),t+o+r+a+n},n.prototype.resolve=function(e){return this.resolveObject(o(e,!1,!0)).format()},n.prototype.resolveObject=function(e){if(h.isString(e)){var t=new n;t.parse(e,!1,!0),e=t}for(var r=new n,o=Object.keys(this),i=0;i0)&&r.host.split("@");j&&(r.auth=j.shift(),r.host=r.hostname=j.shift())}return r.search=e.search,r.query=e.query,h.isNull(r.pathname)&&h.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r}if(!w.length)return r.pathname=null,r.search?r.path="/"+r.search:r.path=null,r.href=r.format(),r;for(var E=w.slice(-1)[0],P=(r.host||e.host||w.length>1)&&("."===E||".."===E)||""===E,R=0,q=w.length;q>=0;q--)E=w[q],"."===E?w.splice(q,1):".."===E?(w.splice(q,1),R++):R&&(w.splice(q,1),R--);if(!g&&!S)for(;R--;R)w.unshift("..");!g||""===w[0]||w[0]&&"/"===w[0].charAt(0)||w.unshift(""),P&&"/"!==w.join("/").substr(-1)&&w.push("");var C=""===w[0]||w[0]&&"/"===w[0].charAt(0);if(O){r.hostname=r.host=C?"":w.length?w.shift():"";var j=!!(r.host&&r.host.indexOf("@")>0)&&r.host.split("@");j&&(r.auth=j.shift(),r.host=r.hostname=j.shift())}return g=g||r.host&&w.length,g&&!C&&w.unshift(""),w.length?r.pathname=w.join("/"):(r.pathname=null,r.path=null),h.isNull(r.pathname)&&h.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=e.auth||r.auth,r.slashes=r.slashes||e.slashes,r.href=r.format(),r},n.prototype.parseHost=function(){var e=this.host,t=l.exec(e);t&&(t=t[0],":"!==t&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)}},function(e,t){(function(t){e.exports=t}).call(t,{})},function(e,t,r){"use strict";var n=e.exports.Validator=r(6);e.exports.ValidatorResult=r(0).ValidatorResult,e.exports.ValidationError=r(0).ValidationError,e.exports.SchemaError=r(0).SchemaError,e.exports.validate=function(e,t,r){return(new n).validate(e,t,r)}},function(e,t,r){"use strict";function n(e,t,r,n,o){var i=this.validateSchema(e,o,t,r);return!i.valid&&n instanceof Function&&n(i),i.valid}function o(e,t,r,n,o,i){if(!t.properties||void 0===t.properties[o])if(!1===t.additionalProperties)i.addError({name:"additionalProperties",argument:o,message:"additionalProperty "+JSON.stringify(o)+" exists in instance when not allowed"});else{var a=t.additionalProperties||{},s=this.validateSchema(e[o],a,r,n.makeChild(a,o));s.instance!==i.instance[o]&&(i.instance[o]=s.instance),i.importErrors(s)}}function i(e,t,r){var n,o=r.length;for(n=t+1,o;n"||e+""});o.addError({name:"type",argument:a,message:"is not of a type(s) "+a})}return o},f.anyOf=function(e,t,r,o){if(void 0===e)return null;var i=new u(e,t,r,o),a=new u(e,t,r,o);if(!Array.isArray(t.anyOf))throw new c("anyOf must be an array");if(!t.anyOf.some(n.bind(this,e,r,o,function(e){a.importErrors(e)}))){var s=t.anyOf.map(function(e,t){return e.id&&"<"+e.id+">"||e.title&&JSON.stringify(e.title)||e.$ref&&"<"+e.$ref+">"||"[subschema "+t+"]"});r.nestedErrors&&i.importErrors(a),i.addError({name:"anyOf",argument:s,message:"is not any of "+s.join(",")})}return i},f.allOf=function(e,t,r,n){if(void 0===e)return null;if(!Array.isArray(t.allOf))throw new c("allOf must be an array");var o=new u(e,t,r,n),i=this;return t.allOf.forEach(function(t,a){var s=i.validateSchema(e,t,r,n);if(!s.valid){var u=t.id&&"<"+t.id+">"||t.title&&JSON.stringify(t.title)||t.$ref&&"<"+t.$ref+">"||"[subschema "+a+"]";o.addError({name:"allOf",argument:{id:u,length:s.errors.length,valid:s},message:"does not match allOf schema "+u+" with "+s.errors.length+" error[s]:"}),o.importErrors(s)}}),o},f.oneOf=function(e,t,r,o){if(void 0===e)return null;if(!Array.isArray(t.oneOf))throw new c("oneOf must be an array");var i=new u(e,t,r,o),a=new u(e,t,r,o),s=t.oneOf.filter(n.bind(this,e,r,o,function(e){a.importErrors(e)})).length,h=t.oneOf.map(function(e,t){return e.id&&"<"+e.id+">"||e.title&&JSON.stringify(e.title)||e.$ref&&"<"+e.$ref+">"||"[subschema "+t+"]"});return 1!==s&&(r.nestedErrors&&i.importErrors(a),i.addError({name:"oneOf",argument:h,message:"is not exactly one from "+h.join(",")})),i},f.properties=function(e,t,r,n){if(void 0!==e&&e instanceof Object){var o=new u(e,t,r,n),i=t.properties||{};for(var a in i){var s=(e||void 0)&&e[a],c=this.validateSchema(s,i[a],r,n.makeChild(i[a],a));c.instance!==o.instance[a]&&(o.instance[a]=c.instance),o.importErrors(c)}return o}},f.patternProperties=function(e,t,r,n){if(void 0!==e&&this.types.object(e)){var i=new u(e,t,r,n),a=t.patternProperties||{};for(var s in e){var c=!0;for(var h in a){if(new RegExp(h).test(s)){c=!1;var f=this.validateSchema(e[s],a[h],r,n.makeChild(a[h],s));f.instance!==i.instance[s]&&(i.instance[s]=f.instance),i.importErrors(f)}}c&&o.call(this,e,t,r,n,s,i)}return i}},f.additionalProperties=function(e,t,r,n){if(void 0!==e&&this.types.object(e)){if(t.patternProperties)return null;var i=new u(e,t,r,n);for(var a in e)o.call(this,e,t,r,n,a,i);return i}},f.minProperties=function(e,t,r,n){if(!e||"object"!==(void 0===e?"undefined":a(e)))return null;var o=new u(e,t,r,n);return Object.keys(e).length>=t.minProperties||o.addError({name:"minProperties",argument:t.minProperties,message:"does not meet minimum property length of "+t.minProperties}),o},f.maxProperties=function(e,t,r,n){if(!e||"object"!==(void 0===e?"undefined":a(e)))return null;var o=new u(e,t,r,n);return Object.keys(e).length<=t.maxProperties||o.addError({name:"maxProperties",argument:t.maxProperties,message:"does not meet maximum property length of "+t.maxProperties}),o},f.items=function(e,t,r,n){if(!Array.isArray(e))return null;var o=this,i=new u(e,t,r,n);return void 0!==e&&t.items?(e.every(function(e,a){var s=Array.isArray(t.items)?t.items[a]||t.additionalItems:t.items;if(void 0===s)return!0;if(!1===s)return i.addError({name:"items",message:"additionalItems not permitted"}),!1;var u=o.validateSchema(e,s,r,n.makeChild(s,a));return u.instance!==i.instance[a]&&(i.instance[a]=u.instance),i.importErrors(u),!0}),i):i},f.minimum=function(e,t,r,n){if("number"!=typeof e)return null;var o=new u(e,t,r,n),i=!0;return i=t.exclusiveMinimum&&!0===t.exclusiveMinimum?e>t.minimum:e>=t.minimum,i||o.addError({name:"minimum",argument:t.minimum,message:"must have a minimum value of "+t.minimum}),o},f.maximum=function(e,t,r,n){if("number"!=typeof e)return null;var o,i=new u(e,t,r,n);return o=t.exclusiveMaximum&&!0===t.exclusiveMaximum?e=t.minLength||o.addError({name:"minLength",argument:t.minLength,message:"does not meet minimum length of "+t.minLength}),o},f.maxLength=function(e,t,r,n){if("string"!=typeof e)return null;var o=new u(e,t,r,n);return e.length<=t.maxLength||o.addError({name:"maxLength",argument:t.maxLength,message:"does not meet maximum length of "+t.maxLength}),o},f.minItems=function(e,t,r,n){if(!Array.isArray(e))return null;var o=new u(e,t,r,n);return e.length>=t.minItems||o.addError({name:"minItems",argument:t.minItems,message:"does not meet minimum length of "+t.minItems}),o},f.maxItems=function(e,t,r,n){if(!Array.isArray(e))return null;var o=new u(e,t,r,n);return e.length<=t.maxItems||o.addError({name:"maxItems",argument:t.maxItems,message:"does not meet maximum length of "+t.maxItems}),o},f.uniqueItems=function(e,t,r,n){function o(e,t,r){for(var n=t+1;n"||a;i.addError({name:"not",argument:s,message:"is of prohibited type "+s})}}),i):null},e.exports=h},function(e,t,r){"use strict";function n(e){var t="string"==typeof e?e:e.$ref;return"string"==typeof t&&t}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=r(2),a=r(5),s=r(0),u=s.ValidatorResult,c=s.SchemaError,h=s.SchemaContext,f=function e(){this.customFormats=Object.create(e.prototype.customFormats),this.schemas={},this.unresolvedRefs=[],this.types=Object.create(l),this.attributes=Object.create(a.validators)};f.prototype.customFormats={},f.prototype.schemas=null,f.prototype.types=null,f.prototype.attributes=null,f.prototype.unresolvedRefs=null,f.prototype.addSchema=function(e,t){if(!e)return null;var r=t||e.id;return this.addSubSchema(r,e),r&&(this.schemas[r]=e),this.schemas[r]},f.prototype.addSubSchema=function(e,t){if(t&&"object"==(void 0===t?"undefined":o(t))){if(t.$ref){var r=i.resolve(e,t.$ref);return void(void 0===this.schemas[r]&&(this.schemas[r]=null,this.unresolvedRefs.push(r)))}var n=t.id&&i.resolve(e,t.id),a=n||e;if(n){if(this.schemas[n]){if(!s.deepCompareStrict(this.schemas[n],t))throw new Error("Schema <"+t+"> already exists with different definition");return this.schemas[n]}this.schemas[n]=t;var u=n.replace(/^([^#]*)#$/,"$1");this.schemas[u]=t}return this.addSubSchemaArray(a,t.items instanceof Array?t.items:[t.items]),this.addSubSchemaArray(a,t.extends instanceof Array?t.extends:[t.extends]),this.addSubSchema(a,t.additionalItems),this.addSubSchemaObject(a,t.properties),this.addSubSchema(a,t.additionalProperties),this.addSubSchemaObject(a,t.definitions),this.addSubSchemaObject(a,t.patternProperties),this.addSubSchemaObject(a,t.dependencies),this.addSubSchemaArray(a,t.disallow),this.addSubSchemaArray(a,t.allOf),this.addSubSchemaArray(a,t.anyOf),this.addSubSchemaArray(a,t.oneOf),this.addSubSchema(a,t.not),this.schemas[n]}},f.prototype.addSubSchemaArray=function(e,t){if(t instanceof Array)for(var r=0;r",e);var u=s.objectGetPath(r.schemas[a],o.substr(1));if(void 0===u)throw new c("no such schema "+o+" located in <"+a+">",e);return{subschema:u,switchSchema:t}},f.prototype.testType=function(e,t,r,n,i){if("function"==typeof this.types[i])return this.types[i].call(this,e);if(i&&"object"==(void 0===i?"undefined":o(i))){var a=this.validateSchema(e,i,r,n);return void 0===a||!(a&&a.errors.length)}return!0};var l=f.prototype.types={};l.string=function(e){return"string"==typeof e},l.number=function(e){return"number"==typeof e&&isFinite(e)},l.integer=function(e){return"number"==typeof e&&e%1==0},l.boolean=function(e){return"boolean"==typeof e},l.array=function(e){return e instanceof Array},l.null=function(e){return null===e},l.date=function(e){return e instanceof Date},l.any=function(e){return!0},l.object=function(e){return e&&"object"===(void 0===e?"undefined":o(e))&&!(e instanceof Array)&&!(e instanceof Date)},e.exports=f},function(e,t,r){"use strict";(function(e,n){var o,i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(a){function s(e){throw new RangeError(Z[e])}function u(e,t){for(var r=e.length,n=[];r--;)n[r]=t(e[r]);return n}function c(e,t){var r=e.split("@"),n="";return r.length>1&&(n=r[0]+"@",e=r[1]),e=e.replace(z,"."),n+u(e.split("."),t).join(".")}function h(e){for(var t,r,n=[],o=0,i=e.length;o=55296&&t<=56319&&o65535&&(e-=65536,t+=U(e>>>10&1023|55296),e=56320|1023&e),t+=U(e)}).join("")}function l(e){return e-48<10?e-22:e-65<26?e-65:e-97<26?e-97:j}function m(e,t){return e+22+75*(e<26)-((0!=t)<<5)}function p(e,t,r){var n=0;for(e=r?N(e/q):e>>1,e+=N(e/t);e>M*P>>1;n+=j)e=N(e/M);return N(n+(M+1)*e/(e+R))}function d(e){var t,r,n,o,i,a,u,c,h,m,d=[],y=e.length,v=0,b=I,g=C;for(r=e.lastIndexOf(F),r<0&&(r=0),n=0;n=128&&s("not-basic"),d.push(e.charCodeAt(n));for(o=r>0?r+1:0;o=y&&s("invalid-input"),c=l(e.charCodeAt(o++)),(c>=j||c>N((O-v)/a))&&s("overflow"),v+=c*a,h=u<=g?E:u>=g+P?P:u-g,!(cN(O/m)&&s("overflow"),a*=m;t=d.length+1,g=p(v-i,t,0==i),N(v/t)>O-b&&s("overflow"),b+=N(v/t),v%=t,d.splice(v++,0,b)}return f(d)}function y(e){var t,r,n,o,i,a,u,c,f,l,d,y,v,b,g,S=[];for(e=h(e),y=e.length,t=I,r=0,i=C,a=0;a=t&&dN((O-r)/v)&&s("overflow"),r+=(u-t)*v,t=u,a=0;aO&&s("overflow"),d==t){for(c=r,f=j;l=f<=i?E:f>=i+P?P:f-i,!(c= 0x80 (not a basic code point)","invalid-input":"Invalid input"},M=j-E,N=Math.floor,U=String.fromCharCode;if(A={version:"1.4.1",ucs2:{decode:h,encode:f},decode:d,encode:y,toASCII:b,toUnicode:v},"object"==i(r(3))&&r(3))void 0!==(o=function(){return A}.call(t,r,t,e))&&(e.exports=o);else if(g&&S)if(e.exports==g)S.exports=A;else for(x in A)A.hasOwnProperty(x)&&(g[x]=A[x]);else a.punycode=A}(void 0)}).call(t,r(13)(e),r(12))},function(e,t,r){"use strict";function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,r,i){t=t||"&",r=r||"=";var a={};if("string"!=typeof e||0===e.length)return a;var s=/\+/g;e=e.split(t);var u=1e3;i&&"number"==typeof i.maxKeys&&(u=i.maxKeys);var c=e.length;u>0&&c>u&&(c=u);for(var h=0;h=0?(f=d.substr(0,y),l=d.substr(y+1)):(f=d,l=""),m=decodeURIComponent(f),p=decodeURIComponent(l),n(a,m)?o(a[m])?a[m].push(p):a[m]=[a[m],p]:a[m]=p}return a};var o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},function(e,t,r){"use strict";function n(e,t){if(e.map)return e.map(t);for(var r=[],n=0;n2&&void 0!==arguments[2]?arguments[2]:void 0;if("string"!=typeof t)return r;for(var n=t.split("."),o=e,i=0;i2&&void 0!==arguments[2]?arguments[2]:void 0;if("string"!=typeof t)return r;for(var n=t.split("."),o=e,i=0;i",'"',"`"," ","\r","\n","\t"],d=["{","}","|","\\","^","`"].concat(m),y=["'"].concat(d),v=["%","/","?",";","#"].concat(y),b=["/","?","#"],g=/^[+a-z0-9A-Z_-]{0,63}$/,S=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,w={javascript:!0,"javascript:":!0},A={javascript:!0,"javascript:":!0},x={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},O=r(10);n.prototype.parse=function(e,t,r){if(!h.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+(void 0===e?"undefined":u(e)));var n=e.indexOf("?"),o=-1!==n&&n127?z+="x":z+=$[M];if(!z.match(g)){var N=F.slice(0,P),U=F.slice(P+1),T=$.match(S);T&&(N.push(T[1]),U.unshift(T[2])),U.length&&(a="/"+U.join(".")+a),this.hostname=N.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),I||(this.hostname=c.toASCII(this.hostname));var L=this.port?":"+this.port:"",V=this.hostname||"";this.host=V+L,this.href+=this.host,I&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==a[0]&&(a="/"+a))}if(!w[d])for(var P=0,k=y.length;P0)&&r.host.split("@");j&&(r.auth=j.shift(),r.host=r.hostname=j.shift())}return r.search=e.search,r.query=e.query,h.isNull(r.pathname)&&h.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r}if(!w.length)return r.pathname=null,r.search?r.path="/"+r.search:r.path=null,r.href=r.format(),r;for(var E=w.slice(-1)[0],P=(r.host||e.host||w.length>1)&&("."===E||".."===E)||""===E,R=0,q=w.length;q>=0;q--)E=w[q],"."===E?w.splice(q,1):".."===E?(w.splice(q,1),R++):R&&(w.splice(q,1),R--);if(!g&&!S)for(;R--;R)w.unshift("..");!g||""===w[0]||w[0]&&"/"===w[0].charAt(0)||w.unshift(""),P&&"/"!==w.join("/").substr(-1)&&w.push("");var C=""===w[0]||w[0]&&"/"===w[0].charAt(0);if(O){r.hostname=r.host=C?"":w.length?w.shift():"";var j=!!(r.host&&r.host.indexOf("@")>0)&&r.host.split("@");j&&(r.auth=j.shift(),r.host=r.hostname=j.shift())}return g=g||r.host&&w.length,g&&!C&&w.unshift(""),w.length?r.pathname=w.join("/"):(r.pathname=null,r.path=null),h.isNull(r.pathname)&&h.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=e.auth||r.auth,r.slashes=r.slashes||e.slashes,r.href=r.format(),r},n.prototype.parseHost=function(){var e=this.host,t=p.exec(e);t&&(t=t[0],":"!==t&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)}},function(e,t){(function(t){e.exports=t}).call(t,{})},function(e,t,r){"use strict";var n=e.exports.Validator=r(6);e.exports.ValidatorResult=r(0).ValidatorResult,e.exports.ValidationError=r(0).ValidationError,e.exports.SchemaError=r(0).SchemaError,e.exports.validate=function(e,t,r){return(new n).validate(e,t,r)}},function(e,t,r){"use strict";function n(e,t,r,n,o){var i=this.validateSchema(e,o,t,r);return!i.valid&&n instanceof Function&&n(i),i.valid}function o(e,t,r,n,o,i){if(!t.properties||void 0===t.properties[o])if(!1===t.additionalProperties)i.addError({name:"additionalProperties",argument:o,message:"additionalProperty "+JSON.stringify(o)+" exists in instance when not allowed"});else{var s=t.additionalProperties||{},a=this.validateSchema(e[o],s,r,n.makeChild(s,o));a.instance!==i.instance[o]&&(i.instance[o]=a.instance),i.importErrors(a)}}function i(e,t,r){var n,o=r.length;for(n=t+1,o;n"||e+""});o.addError({name:"type",argument:s,message:"is not of a type(s) "+s})}return o},f.anyOf=function(e,t,r,o){if(void 0===e)return null;var i=new u(e,t,r,o),s=new u(e,t,r,o);if(!Array.isArray(t.anyOf))throw new c("anyOf must be an array");if(!t.anyOf.some(n.bind(this,e,r,o,function(e){s.importErrors(e)}))){var a=t.anyOf.map(function(e,t){return e.id&&"<"+e.id+">"||e.title&&JSON.stringify(e.title)||e.$ref&&"<"+e.$ref+">"||"[subschema "+t+"]"});r.nestedErrors&&i.importErrors(s),i.addError({name:"anyOf",argument:a,message:"is not any of "+a.join(",")})}return i},f.allOf=function(e,t,r,n){if(void 0===e)return null;if(!Array.isArray(t.allOf))throw new c("allOf must be an array");var o=new u(e,t,r,n),i=this;return t.allOf.forEach(function(t,s){var a=i.validateSchema(e,t,r,n);if(!a.valid){var u=t.id&&"<"+t.id+">"||t.title&&JSON.stringify(t.title)||t.$ref&&"<"+t.$ref+">"||"[subschema "+s+"]";o.addError({name:"allOf",argument:{id:u,length:a.errors.length,valid:a},message:"does not match allOf schema "+u+" with "+a.errors.length+" error[s]:"}),o.importErrors(a)}}),o},f.oneOf=function(e,t,r,o){if(void 0===e)return null;if(!Array.isArray(t.oneOf))throw new c("oneOf must be an array");var i=new u(e,t,r,o),s=new u(e,t,r,o),a=t.oneOf.filter(n.bind(this,e,r,o,function(e){s.importErrors(e)})).length,h=t.oneOf.map(function(e,t){return e.id&&"<"+e.id+">"||e.title&&JSON.stringify(e.title)||e.$ref&&"<"+e.$ref+">"||"[subschema "+t+"]"});return 1!==a&&(r.nestedErrors&&i.importErrors(s),i.addError({name:"oneOf",argument:h,message:"is not exactly one from "+h.join(",")})),i},f.properties=function(e,t,r,n){if(void 0!==e&&e instanceof Object){var o=new u(e,t,r,n),i=t.properties||{};for(var s in i){var a=(e||void 0)&&e[s],c=this.validateSchema(a,i[s],r,n.makeChild(i[s],s));c.instance!==o.instance[s]&&(o.instance[s]=c.instance),o.importErrors(c)}return o}},f.patternProperties=function(e,t,r,n){if(void 0!==e&&this.types.object(e)){var i=new u(e,t,r,n),s=t.patternProperties||{};for(var a in e){var c=!0;for(var h in s){if(new RegExp(h).test(a)){c=!1;var f=this.validateSchema(e[a],s[h],r,n.makeChild(s[h],a));f.instance!==i.instance[a]&&(i.instance[a]=f.instance),i.importErrors(f)}}c&&o.call(this,e,t,r,n,a,i)}return i}},f.additionalProperties=function(e,t,r,n){if(void 0!==e&&this.types.object(e)){if(t.patternProperties)return null;var i=new u(e,t,r,n);for(var s in e)o.call(this,e,t,r,n,s,i);return i}},f.minProperties=function(e,t,r,n){if(!e||"object"!==(void 0===e?"undefined":s(e)))return null;var o=new u(e,t,r,n);return Object.keys(e).length>=t.minProperties||o.addError({name:"minProperties",argument:t.minProperties,message:"does not meet minimum property length of "+t.minProperties}),o},f.maxProperties=function(e,t,r,n){if(!e||"object"!==(void 0===e?"undefined":s(e)))return null;var o=new u(e,t,r,n);return Object.keys(e).length<=t.maxProperties||o.addError({name:"maxProperties",argument:t.maxProperties,message:"does not meet maximum property length of "+t.maxProperties}),o},f.items=function(e,t,r,n){if(!Array.isArray(e))return null;var o=this,i=new u(e,t,r,n);return void 0!==e&&t.items?(e.every(function(e,s){var a=Array.isArray(t.items)?t.items[s]||t.additionalItems:t.items;if(void 0===a)return!0;if(!1===a)return i.addError({name:"items",message:"additionalItems not permitted"}),!1;var u=o.validateSchema(e,a,r,n.makeChild(a,s));return u.instance!==i.instance[s]&&(i.instance[s]=u.instance),i.importErrors(u),!0}),i):i},f.minimum=function(e,t,r,n){if("number"!=typeof e)return null;var o=new u(e,t,r,n),i=!0;return i=t.exclusiveMinimum&&!0===t.exclusiveMinimum?e>t.minimum:e>=t.minimum,i||o.addError({name:"minimum",argument:t.minimum,message:"must have a minimum value of "+t.minimum}),o},f.maximum=function(e,t,r,n){if("number"!=typeof e)return null;var o,i=new u(e,t,r,n);return o=t.exclusiveMaximum&&!0===t.exclusiveMaximum?e=t.minLength||o.addError({name:"minLength",argument:t.minLength,message:"does not meet minimum length of "+t.minLength}),o},f.maxLength=function(e,t,r,n){if("string"!=typeof e)return null;var o=new u(e,t,r,n);return e.length<=t.maxLength||o.addError({name:"maxLength",argument:t.maxLength,message:"does not meet maximum length of "+t.maxLength}),o},f.minItems=function(e,t,r,n){if(!Array.isArray(e))return null;var o=new u(e,t,r,n);return e.length>=t.minItems||o.addError({name:"minItems",argument:t.minItems,message:"does not meet minimum length of "+t.minItems}),o},f.maxItems=function(e,t,r,n){if(!Array.isArray(e))return null;var o=new u(e,t,r,n);return e.length<=t.maxItems||o.addError({name:"maxItems",argument:t.maxItems,message:"does not meet maximum length of "+t.maxItems}),o},f.uniqueItems=function(e,t,r,n){function o(e,t,r){for(var n=t+1;n"||s;i.addError({name:"not",argument:a,message:"is of prohibited type "+a})}}),i):null},e.exports=h},function(e,t,r){"use strict";function n(e){var t="string"==typeof e?e:e.$ref;return"string"==typeof t&&t}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=r(2),s=r(5),a=r(0),u=a.ValidatorResult,c=a.SchemaError,h=a.SchemaContext,f=function e(){this.customFormats=Object.create(e.prototype.customFormats),this.schemas={},this.unresolvedRefs=[],this.types=Object.create(p),this.attributes=Object.create(s.validators)};f.prototype.customFormats={},f.prototype.schemas=null,f.prototype.types=null,f.prototype.attributes=null,f.prototype.unresolvedRefs=null,f.prototype.addSchema=function(e,t){if(!e)return null;var r=t||e.id;return this.addSubSchema(r,e),r&&(this.schemas[r]=e),this.schemas[r]},f.prototype.addSubSchema=function(e,t){if(t&&"object"==(void 0===t?"undefined":o(t))){if(t.$ref){var r=i.resolve(e,t.$ref);return void(void 0===this.schemas[r]&&(this.schemas[r]=null,this.unresolvedRefs.push(r)))}var n=t.id&&i.resolve(e,t.id),s=n||e;if(n){if(this.schemas[n]){if(!a.deepCompareStrict(this.schemas[n],t))throw new Error("Schema <"+t+"> already exists with different definition");return this.schemas[n]}this.schemas[n]=t;var u=n.replace(/^([^#]*)#$/,"$1");this.schemas[u]=t}return this.addSubSchemaArray(s,t.items instanceof Array?t.items:[t.items]),this.addSubSchemaArray(s,t.extends instanceof Array?t.extends:[t.extends]),this.addSubSchema(s,t.additionalItems),this.addSubSchemaObject(s,t.properties),this.addSubSchema(s,t.additionalProperties),this.addSubSchemaObject(s,t.definitions),this.addSubSchemaObject(s,t.patternProperties),this.addSubSchemaObject(s,t.dependencies),this.addSubSchemaArray(s,t.disallow),this.addSubSchemaArray(s,t.allOf),this.addSubSchemaArray(s,t.anyOf),this.addSubSchemaArray(s,t.oneOf),this.addSubSchema(s,t.not),this.schemas[n]}},f.prototype.addSubSchemaArray=function(e,t){if(t instanceof Array)for(var r=0;r",e);var u=a.objectGetPath(r.schemas[s],o.substr(1));if(void 0===u)throw new c("no such schema "+o+" located in <"+s+">",e);return{subschema:u,switchSchema:t}},f.prototype.testType=function(e,t,r,n,i){if("function"==typeof this.types[i])return this.types[i].call(this,e);if(i&&"object"==(void 0===i?"undefined":o(i))){var s=this.validateSchema(e,i,r,n);return void 0===s||!(s&&s.errors.length)}return!0};var p=f.prototype.types={};p.string=function(e){return"string"==typeof e},p.number=function(e){return"number"==typeof e&&isFinite(e)},p.integer=function(e){return"number"==typeof e&&e%1==0},p.boolean=function(e){return"boolean"==typeof e},p.array=function(e){return e instanceof Array},p.null=function(e){return null===e},p.date=function(e){return e instanceof Date},p.any=function(e){return!0},p.object=function(e){return e&&"object"===(void 0===e?"undefined":o(e))&&!(e instanceof Array)&&!(e instanceof Date)},e.exports=f},function(e,t,r){"use strict";(function(e,n){var o,i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(s){function a(e){throw new RangeError(M[e])}function u(e,t){for(var r=e.length,n=[];r--;)n[r]=t(e[r]);return n}function c(e,t){var r=e.split("@"),n="";return r.length>1&&(n=r[0]+"@",e=r[1]),e=e.replace(z,"."),n+u(e.split("."),t).join(".")}function h(e){for(var t,r,n=[],o=0,i=e.length;o=55296&&t<=56319&&o65535&&(e-=65536,t+=U(e>>>10&1023|55296),e=56320|1023&e),t+=U(e)}).join("")}function p(e){return e-48<10?e-22:e-65<26?e-65:e-97<26?e-97:j}function l(e,t){return e+22+75*(e<26)-((0!=t)<<5)}function m(e,t,r){var n=0;for(e=r?N(e/q):e>>1,e+=N(e/t);e>Z*P>>1;n+=j)e=N(e/Z);return N(n+(Z+1)*e/(e+R))}function d(e){var t,r,n,o,i,s,u,c,h,l,d=[],y=e.length,v=0,b=I,g=C;for(r=e.lastIndexOf(F),r<0&&(r=0),n=0;n=128&&a("not-basic"),d.push(e.charCodeAt(n));for(o=r>0?r+1:0;o=y&&a("invalid-input"),c=p(e.charCodeAt(o++)),(c>=j||c>N((O-v)/s))&&a("overflow"),v+=c*s,h=u<=g?E:u>=g+P?P:u-g,!(cN(O/l)&&a("overflow"),s*=l;t=d.length+1,g=m(v-i,t,0==i),N(v/t)>O-b&&a("overflow"),b+=N(v/t),v%=t,d.splice(v++,0,b)}return f(d)}function y(e){var t,r,n,o,i,s,u,c,f,p,d,y,v,b,g,S=[];for(e=h(e),y=e.length,t=I,r=0,i=C,s=0;s=t&&dN((O-r)/v)&&a("overflow"),r+=(u-t)*v,t=u,s=0;sO&&a("overflow"),d==t){for(c=r,f=j;p=f<=i?E:f>=i+P?P:f-i,!(c= 0x80 (not a basic code point)","invalid-input":"Invalid input"},Z=j-E,N=Math.floor,U=String.fromCharCode;if(A={version:"1.4.1",ucs2:{decode:h,encode:f},decode:d,encode:y,toASCII:b,toUnicode:v},"object"==i(r(3))&&r(3))void 0!==(o=function(){return A}.call(t,r,t,e))&&(e.exports=o);else if(g&&S)if(e.exports==g)S.exports=A;else for(x in A)A.hasOwnProperty(x)&&(g[x]=A[x]);else s.punycode=A}(void 0)}).call(t,r(13)(e),r(12))},function(e,t,r){"use strict";function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,r,i){t=t||"&",r=r||"=";var s={};if("string"!=typeof e||0===e.length)return s;var a=/\+/g;e=e.split(t);var u=1e3;i&&"number"==typeof i.maxKeys&&(u=i.maxKeys);var c=e.length;u>0&&c>u&&(c=u);for(var h=0;h=0?(f=d.substr(0,y),p=d.substr(y+1)):(f=d,p=""),l=decodeURIComponent(f),m=decodeURIComponent(p),n(s,l)?o(s[l])?s[l].push(m):s[l]=[s[l],m]:s[l]=m}return s};var o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},function(e,t,r){"use strict";function n(e,t){if(e.map)return e.map(t);for(var r=[],n=0;n { 16 | this.socket = scClient.connect(options); 17 | 18 | wampClient.upgradeToWAMP(this.socket); 19 | 20 | this.socket.on('error', (err) => { 21 | throw new Error(`Socket error - ${err}`); 22 | }); 23 | 24 | this.socket.on('connect', () => { 25 | console.info('socket client connected'); 26 | }); 27 | 28 | return this.socket; 29 | }; 30 | 31 | Client.prototype.callRPCInInterval = () => { 32 | const interval = setInterval(() => { 33 | const randNumber = Math.floor(Math.random() * 5); 34 | this.socket.call('multiplyByTwo', randNumber) 35 | .then(result => console.info(`RPC result: ${randNumber} * 2 = ${result}`)) 36 | .catch(err => console.warn('RPC multiply by two error', err)); 37 | 38 | this.socket.emit('multiplyByThree', randNumber); 39 | }, 1000); 40 | 41 | this.socket.on('disconnect', () => { 42 | console.warn('socket client disconnected'); 43 | clearInterval(interval); 44 | }); 45 | }; 46 | 47 | module.exports = Client; 48 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | require('./server').getInstance(); 2 | 3 | const Client = require('./client'); 4 | 5 | setTimeout(() => { 6 | const c = new Client(); 7 | c.connect(); 8 | c.callRPCInInterval(); 9 | }, 1000); 10 | -------------------------------------------------------------------------------- /example/server.js: -------------------------------------------------------------------------------- 1 | const SocketCluster = require('socketcluster'); 2 | 3 | const serverScenarioName = 'serverWorker'; 4 | 5 | const options = { 6 | workers: 1, 7 | port: 8000, 8 | wsEngine: 'uws', 9 | appName: 'wampSocketCluster', 10 | workerController: `${__dirname}/${serverScenarioName}`, 11 | }; 12 | 13 | const SOCKET_CLUSTER_KEY = Symbol.for('App.SocketClusterServer'); 14 | const globalSymbols = Object.getOwnPropertySymbols(global); 15 | const hasSocketCluster = (globalSymbols.indexOf(SOCKET_CLUSTER_KEY) > -1); 16 | 17 | if (!hasSocketCluster) { 18 | global[SOCKET_CLUSTER_KEY] = { 19 | socketCluster: new SocketCluster(options), 20 | }; 21 | } 22 | 23 | const socketClusterSingleton = { 24 | getInstance: () => global[SOCKET_CLUSTER_KEY], 25 | }; 26 | 27 | module.exports = socketClusterSingleton; 28 | -------------------------------------------------------------------------------- /example/serverWorker.js: -------------------------------------------------------------------------------- 1 | let counter = 0; 2 | 3 | /** 4 | * All examples every third time will be: 5 | * - returining valid result 6 | * - returning example error 7 | * - not replying at all causing timeouts 8 | */ 9 | const rpcEndpoints = { 10 | multiplyByTwo: (num, cb) => { 11 | counter += 1; 12 | const randomError = counter % 2 === 0 ? null : 'random occurring error'; 13 | if (counter % 3) { 14 | console.info('For every 3rd call the response is randomly not being returned'); 15 | } else { 16 | cb(randomError, num * 2); 17 | } 18 | }, 19 | }; 20 | 21 | const eventEndpoints = { 22 | multiplyByThree: (num, cb) => { 23 | counter += 1; 24 | const randomError = counter % 2 === 0 ? null : 'random occurring error'; 25 | if (counter % 3) { 26 | console.info('For every 3rd call the response is randomly not being returned'); 27 | } else { 28 | cb(randomError, num * 3); 29 | } 30 | }, 31 | }; 32 | 33 | const SCWorker = require('socketcluster/scworker'); 34 | const WAMPServer = require('../WAMPServer'); 35 | 36 | class Worker extends SCWorker { 37 | run() { 38 | const scServer = this.scServer; 39 | 40 | const wampServer = new WAMPServer(); 41 | wampServer.registerRPCEndpoints(rpcEndpoints); 42 | wampServer.registerEventEndpoints(eventEndpoints); 43 | 44 | scServer.on('connection', (socket) => { 45 | wampServer.upgradeToWAMP(socket); 46 | }); 47 | } 48 | } 49 | module.exports = new Worker(); 50 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const SlaveWAMPServer = require('./SlaveWAMPServer'); 2 | const MasterWAMPServer = require('./MasterWAMPServer'); 3 | const WAMPServer = require('./WAMPServer'); 4 | const WAMPClient = require('./WAMPClient'); 5 | 6 | module.exports = { 7 | SlaveWAMPServer, 8 | MasterWAMPServer, 9 | WAMPClient, 10 | WAMPServer, 11 | }; 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wamp-socket-cluster", 3 | "version": "2.0.0-beta.4", 4 | "description": "", 5 | "main": "dist/index.js", 6 | "scripts": { 7 | "test": "mocha $(find . -name '*.spec.js' ! -ipath '*node_modules*')", 8 | "build": "npm run build:src && npm run build:bundle", 9 | "build:src": "webpack --optimize-minimize", 10 | "build:bundle": "BUNDLE=true webpack --optimize-minimize", 11 | "eslint": "eslint .", 12 | "eslint:fix": "npm run eslint -- --fix" 13 | }, 14 | "author": "Lisk Foundation , lightcurve GmbH ", 15 | "license": "GPLv3", 16 | "dependencies": { 17 | "jsonschema": "=1.1.1" 18 | }, 19 | "devDependencies": { 20 | "babel-core": "=6.24.0", 21 | "babel-loader": "=6.4.1", 22 | "babel-preset-env": "=1.2.2", 23 | "chai": "=4.1.1", 24 | "dirty-chai": "=2.0.1", 25 | "eslint": "=4.3.0", 26 | "eslint-config-airbnb-base": "=11.3.1", 27 | "eslint-config-lisk-base": "=0.1.0", 28 | "eslint-plugin-import": "=2.7.0", 29 | "mocha": "=3.2.0", 30 | "sinon": "=2.1.0", 31 | "socketcluster": "=9.1.10", 32 | "socketcluster-client": "=9.0.2", 33 | "webpack": "=2.3.2", 34 | "webpack-node-externals": "=1.5.4" 35 | }, 36 | "pre-commit": "build" 37 | } 38 | -------------------------------------------------------------------------------- /schemas.js: -------------------------------------------------------------------------------- 1 | const Validator = require('jsonschema').Validator; 2 | 3 | const v = new Validator(); 4 | 5 | const RPCResponseSchema = { 6 | id: '/RPCResponse', 7 | type: 'object', 8 | properties: { 9 | type: { type: 'string' }, 10 | data: {}, 11 | }, 12 | required: ['type', 'data'], 13 | }; 14 | 15 | const RPCRequestSchema = { 16 | id: '/RPCRequest', 17 | type: 'object', 18 | properties: { 19 | type: { type: 'string' }, 20 | procedure: { type: 'string' }, 21 | data: {}, 22 | }, 23 | required: ['type', 'procedure'], 24 | }; 25 | 26 | const EventRequestSchema = { 27 | id: '/EventRequestSchema', 28 | type: 'object', 29 | properties: { 30 | type: { type: 'string' }, 31 | procedure: { type: 'string' }, 32 | data: {}, 33 | }, 34 | required: ['type', 'procedure'], 35 | }; 36 | 37 | const MasterRPCRequestSchema = { 38 | id: '/MasterRPCRequest', 39 | type: 'object', 40 | properties: { 41 | type: { type: 'string' }, 42 | procedure: { type: 'string' }, 43 | data: {}, 44 | }, 45 | required: ['type', 'procedure'], 46 | }; 47 | 48 | const InterProcessRPCRequestSchema = { 49 | id: '/InterProcessRPCRequestSchema', 50 | type: 'object', 51 | properties: { 52 | type: { type: 'string' }, 53 | procedure: { type: 'string' }, 54 | data: {}, 55 | }, 56 | required: ['type', 'procedure'], 57 | }; 58 | 59 | const MasterConfigRequestSchema = { 60 | id: '/MasterConfigRequestSchema', 61 | type: 'object', 62 | properties: { 63 | type: { type: 'string' }, 64 | registeredEvents: { type: 'array' }, 65 | config: { type: 'object' }, 66 | }, 67 | required: ['type', 'registeredEvents', 'config'], 68 | }; 69 | 70 | 71 | const resToReqMap = { 72 | [RPCResponseSchema.id]: RPCRequestSchema.id, 73 | }; 74 | 75 | const reqToResMap = { 76 | [RPCRequestSchema.id]: RPCResponseSchema.id, 77 | [MasterRPCRequestSchema.id]: RPCResponseSchema.id, 78 | }; 79 | 80 | const isValid = (obj, schema) => v.validate(obj, schema).valid && obj.type === schema.id; 81 | 82 | module.exports = { 83 | EventRequestSchema, 84 | RPCRequestSchema, 85 | RPCResponseSchema, 86 | InterProcessRPCRequestSchema, 87 | MasterRPCRequestSchema, 88 | MasterConfigRequestSchema, 89 | resToReqMap, 90 | reqToResMap, 91 | isValid, 92 | }; 93 | -------------------------------------------------------------------------------- /testSetup.spec.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node, mocha */ 2 | 3 | const chai = require('chai'); 4 | const dirtyChai = require('dirty-chai'); 5 | 6 | chai.use(dirtyChai); 7 | module.exports = { expect: chai.expect }; 8 | -------------------------------------------------------------------------------- /utils.js: -------------------------------------------------------------------------------- 1 | const utils = { 2 | get: (obj, deepKeyString, defaultValue = undefined) => { 3 | if (typeof deepKeyString !== 'string') { 4 | return defaultValue; 5 | } 6 | const deepKeyArray = deepKeyString.split('.'); 7 | let currentResult = obj; 8 | 9 | for (let i = 0; i < deepKeyArray.length; i += 1) { 10 | currentResult = currentResult[deepKeyArray[i]]; 11 | if (currentResult === undefined) { 12 | return defaultValue; 13 | } 14 | } 15 | return currentResult; 16 | }, 17 | }; 18 | 19 | module.exports = utils; 20 | -------------------------------------------------------------------------------- /utils.spec.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node, mocha */ 2 | const { expect } = require('./testSetup.spec'); 3 | 4 | const utils = require('./utils'); 5 | 6 | describe('utils', () => { 7 | describe('get', () => { 8 | let validPath; 9 | let validObject; 10 | let validDefaultValue; 11 | 12 | let getResult; 13 | 14 | before(() => { 15 | validPath = ''; 16 | validObject = {}; 17 | validDefaultValue = undefined; 18 | }); 19 | 20 | beforeEach(() => { 21 | getResult = utils.get(validObject, validPath, validDefaultValue); 22 | }); 23 | 24 | describe('when path is not a string', () => { 25 | describe('when path is an object', () => { 26 | before(() => { 27 | validPath = {}; 28 | }); 29 | 30 | it('should return undefined', () => { 31 | expect(getResult).to.be.undefined(); 32 | }); 33 | }); 34 | 35 | describe('when path is an array', () => { 36 | before(() => { 37 | validPath = []; 38 | }); 39 | 40 | it('should return undefined', () => { 41 | expect(getResult).to.be.undefined(); 42 | }); 43 | }); 44 | 45 | describe('when path is a number', () => { 46 | before(() => { 47 | const validNumber = 1; 48 | validPath = validNumber; 49 | }); 50 | 51 | it('should return undefined', () => { 52 | expect(getResult).to.be.undefined(); 53 | }); 54 | }); 55 | 56 | describe('when path is null', () => { 57 | before(() => { 58 | validPath = null; 59 | }); 60 | 61 | it('should return undefined', () => { 62 | expect(getResult).to.be.undefined(); 63 | }); 64 | }); 65 | 66 | describe('when path is undefined', () => { 67 | before(() => { 68 | validPath = undefined; 69 | }); 70 | 71 | it('should return undefined', () => { 72 | expect(getResult).to.be.undefined(); 73 | }); 74 | }); 75 | }); 76 | 77 | describe('when path is a string', () => { 78 | describe('and is empty', () => { 79 | before(() => { 80 | validPath = ''; 81 | }); 82 | 83 | it('should return undefined', () => { 84 | expect(getResult).to.be.undefined(); 85 | }); 86 | }); 87 | 88 | describe('when accessing nested object', () => { 89 | before(() => { 90 | validObject = { 91 | a: { 92 | b: { 93 | c: { 94 | d: 'abcd', 95 | }, 96 | }, 97 | }, 98 | }; 99 | }); 100 | 101 | describe('when accessing property does not exist', () => { 102 | before(() => { 103 | validPath = 'A.B.C.D'; 104 | }); 105 | 106 | it('should return undefined', () => { 107 | expect(getResult).to.be.undefined(); 108 | }); 109 | 110 | describe('when defaultValue = false', () => { 111 | before(() => { 112 | validDefaultValue = false; 113 | }); 114 | 115 | it('should return undefined', () => { 116 | expect(getResult).to.be.false(); 117 | }); 118 | }); 119 | }); 120 | 121 | describe('when accessing property exists', () => { 122 | describe('and points to the middle-path value', () => { 123 | before(() => { 124 | validPath = 'a.b'; 125 | }); 126 | 127 | it('should return {c: {d: "abcd"}}}', () => { 128 | expect(getResult).to.eql({ 129 | c: { 130 | d: 'abcd', 131 | }, 132 | }); 133 | }); 134 | }); 135 | 136 | describe('and points to the final value', () => { 137 | before(() => { 138 | validPath = 'a.b.c.d'; 139 | }); 140 | 141 | it('should return "abcd"', () => { 142 | expect(getResult).to.equal('abcd'); 143 | }); 144 | }); 145 | }); 146 | }); 147 | }); 148 | }); 149 | }); 150 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const webpackNodeExternals = require('webpack-node-externals'); 3 | 4 | const config = { 5 | entry: { 6 | MasterWAMPServer: './MasterWAMPServer.js', 7 | SlaveWAMPServer: './SlaveWAMPServer.js', 8 | WAMPClient: './WAMPClient.js', 9 | WAMPServer: './WAMPServer.js', 10 | }, 11 | module: { 12 | rules: [ 13 | { 14 | test: /\.js$/, 15 | loader: 'babel-loader', 16 | }, 17 | ], 18 | }, 19 | output: { 20 | path: path.join(__dirname, './dist'), 21 | filename: '[name].bundle.js', 22 | library: 'wampSocketCluster', 23 | libraryTarget: 'umd', 24 | umdNamedDefine: true, 25 | }, 26 | }; 27 | 28 | if (process.env.BUNDLE) { 29 | config.output.filename = '[name].bundle.min.js'; 30 | } else { 31 | config.externals = [webpackNodeExternals()]; 32 | config.output.filename = '[name].src.min.js'; 33 | } 34 | 35 | module.exports = config; 36 | --------------------------------------------------------------------------------