ryugi-artifacts 1.12.2 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1 -1
- package/dist/server.cjs +3882 -83
- package/dist/viewer/CloudDocument-DROKEMRI.js +1 -0
- package/dist/viewer/CloudLiveDocument-Crioc8xT.js +1 -0
- package/dist/viewer/{DocumentLayout-CcZ5K5eC.js → DocumentLayout-9ziWsfNL.js} +157 -180
- package/dist/viewer/DocumentPage-BzZQ4dIA.js +1 -0
- package/dist/viewer/{abnfDiagram-VCTEODGH-BwyorJKp.js → abnfDiagram-VCTEODGH-7Snbrgtb.js} +1 -1
- package/dist/viewer/{ar-SA-G6X2FPQ2-DhkEZphc.js → ar-SA-G6X2FPQ2-C4WXmkki.js} +1 -1
- package/dist/viewer/{architecture-7GRP2DOG-Bl5CPsMS.js → architecture-7GRP2DOG-BvGJ2bde.js} +1 -1
- package/dist/viewer/{architectureDiagram-5GKGNRK7-BaHSeQgR.js → architectureDiagram-5GKGNRK7-Dn48oQRa.js} +1 -1
- package/dist/viewer/{az-AZ-76LH7QW2-Dq_pf-jP.js → az-AZ-76LH7QW2-D54gwaxj.js} +1 -1
- package/dist/viewer/{bg-BG-XCXSNQG7-gBZ_kZ5X.js → bg-BG-XCXSNQG7-ba6x7ahJ.js} +1 -1
- package/dist/viewer/{blockDiagram-I7D4REHJ-CEJ7CnVM.js → blockDiagram-I7D4REHJ-DPLSvrPU.js} +3 -3
- package/dist/viewer/{bn-BD-2XOGV67Q-mB4IlJ7X.js → bn-BD-2XOGV67Q-Dx78lDoy.js} +1 -1
- package/dist/viewer/{c4Diagram-7LVT6UL2-DpzymfkJ.js → c4Diagram-7LVT6UL2-D4oNLtMS.js} +1 -1
- package/dist/viewer/{ca-ES-6MX7JW3Y-CHkPol9h.js → ca-ES-6MX7JW3Y-DIzt8Q6T.js} +1 -1
- package/dist/viewer/channel-DNz5iSBO.js +1 -0
- package/dist/viewer/{chunk-4HAMMTFA-B9_yq81j.js → chunk-4HAMMTFA-mI_qOrQp.js} +1 -1
- package/dist/viewer/chunk-75Z2AOVW-CkyZ2k2Y.js +2 -0
- package/dist/viewer/{chunk-DU6HZSFF-CDWc5UBY.js → chunk-DU6HZSFF-BWpgeLJJ.js} +1 -1
- package/dist/viewer/{chunk-EIO257PC-zMzCMW_Z.js → chunk-EIO257PC-D3DH6aJS.js} +1 -1
- package/dist/viewer/{chunk-F27PBJKO-qGDpbSI2.js → chunk-F27PBJKO-Zk52-grf.js} +1 -1
- package/dist/viewer/{chunk-GMAD6QVW-CgQkPOxU.js → chunk-GMAD6QVW-B8OPXGKD.js} +1 -1
- package/dist/viewer/{chunk-GVQU2GXP-DnQ_zZPe.js → chunk-GVQU2GXP-BRPsjMGA.js} +1 -1
- package/dist/viewer/{chunk-IMKFNOWR-CyF3KB4j.js → chunk-IMKFNOWR-C6TSKNHs.js} +1 -1
- package/dist/viewer/{chunk-L3NEJ4N5-CkqFBTrv.js → chunk-L3NEJ4N5-U5fh1b9J.js} +1 -1
- package/dist/viewer/{chunk-OSK3NFVY-B5r6bIZy.js → chunk-OSK3NFVY-BvbdG-aP.js} +1 -1
- package/dist/viewer/{chunk-P2QGCYS3-DJOHCBv0.js → chunk-P2QGCYS3-iklY7skC.js} +1 -1
- package/dist/viewer/{chunk-POPQ4Y6H-at1Afs_1.js → chunk-POPQ4Y6H-B0smFSPK.js} +1 -1
- package/dist/viewer/{chunk-PWAF6VOD-BXwjNm2i.js → chunk-PWAF6VOD-BsgO0tHH.js} +1 -1
- package/dist/viewer/{chunk-SHT3W25Y-_XyeIwHN.js → chunk-SHT3W25Y---6MVIra.js} +1 -1
- package/dist/viewer/{chunk-SVP7TREG-4u1H3mwA.js → chunk-SVP7TREG-pvbG6ia8.js} +1 -1
- package/dist/viewer/{chunk-TICWLB2K-BBSUNz_c.js → chunk-TICWLB2K-QwIBQ5m0.js} +1 -1
- package/dist/viewer/classDiagram-ZZMXUADV-DJCVzIyl.js +1 -0
- package/dist/viewer/classDiagram-v2-VYDZK3BY-DJCVzIyl.js +1 -0
- package/dist/viewer/{cs-CZ-2BRQDIVT-WV9McUKD.js → cs-CZ-2BRQDIVT-D7YMDD9n.js} +1 -1
- package/dist/viewer/{cynefin-OW5HDTMX-B-FRYmfA.js → cynefin-OW5HDTMX-BXlWMzIh.js} +1 -1
- package/dist/viewer/{cynefinDiagram-5FMLGOSQ-BA3QpMlg.js → cynefinDiagram-5FMLGOSQ-PY8aYbCu.js} +1 -1
- package/dist/viewer/{da-DK-5WZEPLOC-BrOMeG39.js → da-DK-5WZEPLOC-CNfuwT_x.js} +1 -1
- package/dist/viewer/{dagre-GXQ25YYZ-CmlnwCJt.js → dagre-GXQ25YYZ-BYwPp6cN.js} +1 -1
- package/dist/viewer/{de-DE-XR44H4JA-CgbNVmyI.js → de-DE-XR44H4JA-BHhzPpeY.js} +1 -1
- package/dist/viewer/{diagram-S7CK7UJ4-Dg_jqdtw.js → diagram-S7CK7UJ4-Hxr5IGEj.js} +1 -1
- package/dist/viewer/{diagram-UQ7AKVKN-CWaIKMB0.js → diagram-UQ7AKVKN-qbe2cy8h.js} +1 -1
- package/dist/viewer/{diagram-VSXAHHWV-MzIJiSe8.js → diagram-VSXAHHWV-DiLlG6yw.js} +1 -1
- package/dist/viewer/{diagram-VX7I27RA-DUhQ4i7u.js → diagram-VX7I27RA-CO8LquuV.js} +1 -1
- package/dist/viewer/{diagram-Z3DM3KII-BS6ObAUC.js → diagram-Z3DM3KII-C6FntHFg.js} +1 -1
- package/dist/viewer/{dist-ZWKcMFTj.js → dist-2-DBqfQz.js} +1 -1
- package/dist/viewer/{dist-9H4K5ix0.js → dist-8fl03Nsj.js} +1 -1
- package/dist/viewer/{dist-CyPmYQaJ.js → dist-BDSLw9q0.js} +1 -1
- package/dist/viewer/{dist-BorQwBNI.js → dist-BFnzZT38.js} +1 -1
- package/dist/viewer/{dist-_uxaiDmU.js → dist-BJtdl9HO.js} +1 -1
- package/dist/viewer/{dist-SM0J-pDO.js → dist-BSpv39WM.js} +1 -1
- package/dist/viewer/dist-CAvp6Xxt.js +6 -0
- package/dist/viewer/{dist-BzJQwmvX.js → dist-CY5J2IzE.js} +1 -1
- package/dist/viewer/{dist-WBFAlCBt.js → dist-CfCrut1-.js} +1 -1
- package/dist/viewer/{dist-BHR2FX7Y.js → dist-ChDLFu8I.js} +1 -1
- package/dist/viewer/{dist-D2BzUUmp.js → dist-CubZ-9at.js} +1 -1
- package/dist/viewer/{dist-DcuqbkdR.js → dist-D1Wa4qrD.js} +1 -1
- package/dist/viewer/{dist-DdzGOsi2.js → dist-DJly3LNR.js} +4 -4
- package/dist/viewer/{dist-Dk4q8Mo3.js → dist-DL_BDhjt.js} +1 -1
- package/dist/viewer/{dist-B8Lv2vMq.js → dist-DkBG6KRP.js} +1 -1
- package/dist/viewer/{dist-DFvgmf_n.js → dist-Dsnv_CF_.js} +1 -1
- package/dist/viewer/{dist-B1eEUuu0.js → dist-DumDK5j7.js} +5 -5
- package/dist/viewer/{dist-Ct5lEZ0N.js → dist-F3v4_2y_.js} +2 -2
- package/dist/viewer/dist-GWGyTSFy.js +23 -0
- package/dist/viewer/{dist-C6yK3pAM.js → dist-KzZE1cs6.js} +1 -1
- package/dist/viewer/{dist-yJDNdV0A.js → dist-L-7q6M9h.js} +1 -1
- package/dist/viewer/{dist-DpPbcj1p.js → dist-RblNtGL7.js} +1 -1
- package/dist/viewer/dist-f2qY_ieJ.js +9 -0
- package/dist/viewer/{dist-BS7l2kYN.js → dist-sUulK2s9.js} +1 -1
- package/dist/viewer/{ebnfDiagram-PWID7BFC-CCSNYB4L.js → ebnfDiagram-PWID7BFC-CRY0N21G.js} +1 -1
- package/dist/viewer/{el-GR-BZB4AONW-C_pXDFW7.js → el-GR-BZB4AONW-DUqgRMTy.js} +1 -1
- package/dist/viewer/{en-B4ZKOASM-C4mmKH41.js → en-B4ZKOASM-CLPoEBEZ.js} +1 -1
- package/dist/viewer/{erDiagram-RLTQ6QDP-PDGWfqA7.js → erDiagram-RLTQ6QDP-B5ION-eU.js} +1 -1
- package/dist/viewer/{es-ES-U4NZUMDT-CIBbeSjd.js → es-ES-U4NZUMDT-DDd8Woe3.js} +1 -1
- package/dist/viewer/{eu-ES-A7QVB2H4-BVJBmDMo.js → eu-ES-A7QVB2H4-BQPiKGQE.js} +1 -1
- package/dist/viewer/{eventmodeling-NTZA5JFV-CUPY4M1x.js → eventmodeling-NTZA5JFV-CATeUuOQ.js} +1 -1
- package/dist/viewer/{fa-IR-HGAKTJCU-BhmiDKan.js → fa-IR-HGAKTJCU-Bns8t3Hw.js} +1 -1
- package/dist/viewer/{fi-FI-Z5N7JZ37-CURbgYPC.js → fi-FI-Z5N7JZ37-C_twvi10.js} +1 -1
- package/dist/viewer/floating-ui.react-dom-CCnwLChu.js +1 -0
- package/dist/viewer/flowDiagram-HODETNUW-DbQx4szb.js +1 -0
- package/dist/viewer/{fr-FR-RHASNOE6-ux_eRdgy.js → fr-FR-RHASNOE6-N6G8JzbU.js} +1 -1
- package/dist/viewer/ganttDiagram-EL5Y4UJY-DC63ZiWI.js +292 -0
- package/dist/viewer/{gitGraph-4MIJSDKK-C3CdCDb5.js → gitGraph-4MIJSDKK-BYZnsBO9.js} +1 -1
- package/dist/viewer/{gitGraphDiagram-WWUBYQGX-BaOtu-F2.js → gitGraphDiagram-WWUBYQGX--dMedsqU.js} +1 -1
- package/dist/viewer/{gl-ES-HMX3MZ6V-Cihuelm2.js → gl-ES-HMX3MZ6V-oxefKHej.js} +1 -1
- package/dist/viewer/{he-IL-6SHJWFNN-Bs35uNZ3.js → he-IL-6SHJWFNN-GB3sULCk.js} +1 -1
- package/dist/viewer/{hi-IN-IWLTKZ5I-Bkks6B5Q.js → hi-IN-IWLTKZ5I-RLz998Fr.js} +1 -1
- package/dist/viewer/{hu-HU-A5ZG7DT2-BnODKUjs.js → hu-HU-A5ZG7DT2-CQSNnwmA.js} +1 -1
- package/dist/viewer/{id-ID-SAP4L64H-BYIP832p.js → id-ID-SAP4L64H-JkWndBOF.js} +1 -1
- package/dist/viewer/{image-GAAHSSAO-CAc-N7rt.js → image-GAAHSSAO-BsOh2Dj5.js} +1 -1
- package/dist/viewer/index.css +1 -1
- package/dist/viewer/index.html +3 -0
- package/dist/viewer/index.js +8 -57
- package/dist/viewer/index2.css +220 -0
- package/dist/viewer/{info-A6RAGUB7-BfTkwG6X.js → info-A6RAGUB7-w-CNJ77m.js} +1 -1
- package/dist/viewer/{infoDiagram-27XIBGKW-DLRYUeUy.js → infoDiagram-27XIBGKW-DHAf1ebP.js} +1 -1
- package/dist/viewer/isObjectLike-DnuJWahO.js +1 -0
- package/dist/viewer/{ishikawaDiagram-5VMMS53U-Bs0ln1Mk.js → ishikawaDiagram-5VMMS53U-BOANZ4my.js} +1 -1
- package/dist/viewer/{it-IT-JPQ66NNP-7rCwp765.js → it-IT-JPQ66NNP-BpUeMeKA.js} +1 -1
- package/dist/viewer/{ja-JP-DBVTYXUO-B86xwKuA.js → ja-JP-DBVTYXUO-AmyJ9Ehh.js} +1 -1
- package/dist/viewer/{journeyDiagram-3NMN7TZE-DIAOPmBd.js → journeyDiagram-3NMN7TZE-d9tXMN6w.js} +1 -1
- package/dist/viewer/{kaa-6HZHGXH3-BTtaFW15.js → kaa-6HZHGXH3-nS9x8k05.js} +1 -1
- package/dist/viewer/{kab-KAB-ZGHBKWFO-YwLYv-FV.js → kab-KAB-ZGHBKWFO-CSlBAp4c.js} +1 -1
- package/dist/viewer/{kanban-definition-UXKFOSKX-DngKNwm_.js → kanban-definition-UXKFOSKX-CN1Z3Ciu.js} +1 -1
- package/dist/viewer/{kk-KZ-P5N5QNE5-BKU0B0Y3.js → kk-KZ-P5N5QNE5-CttFS7-E.js} +1 -1
- package/dist/viewer/{km-KH-HSX4SM5Z-CL5_mtQe.js → km-KH-HSX4SM5Z-D719ESMV.js} +1 -1
- package/dist/viewer/{ko-KR-MTYHY66A-BQSh_Zrz.js → ko-KR-MTYHY66A-BBfeWT-i.js} +1 -1
- package/dist/viewer/{ku-TR-6OUDTVRD-BGZnZD-p.js → ku-TR-6OUDTVRD-CGsGxS1P.js} +1 -1
- package/dist/viewer/{lt-LT-XHIRWOB4-CUr6tXWJ.js → lt-LT-XHIRWOB4-i3RRm6p_.js} +1 -1
- package/dist/viewer/{lv-LV-5QDEKY6T-Cvmn527v.js → lv-LV-5QDEKY6T-ua5VHQIt.js} +1 -1
- package/dist/viewer/{mermaid-parser.core-Cd74p1Qw.js → mermaid-parser.core-eTBicIMn.js} +3 -3
- package/dist/viewer/{mindmap-definition-YA3MSWOX-Bc1SjpoY.js → mindmap-definition-YA3MSWOX-DgcPDhCe.js} +1 -1
- package/dist/viewer/{mr-IN-CRQNXWMA-Bplsagq2.js → mr-IN-CRQNXWMA-BSJ4z3i6.js} +1 -1
- package/dist/viewer/{my-MM-5M5IBNSE-Do1Qj59Y.js → my-MM-5M5IBNSE-BSIuPPdh.js} +1 -1
- package/dist/viewer/{nb-NO-T6EIAALU-Bie5rHOp.js → nb-NO-T6EIAALU-CW82jvNd.js} +1 -1
- package/dist/viewer/{nl-NL-IS3SIHDZ-Dc4FJPqi.js → nl-NL-IS3SIHDZ-CppHkdms.js} +1 -1
- package/dist/viewer/{nn-NO-6E72VCQL-DCW6lwYm.js → nn-NO-6E72VCQL-CsedjQ-N.js} +1 -1
- package/dist/viewer/{oc-FR-POXYY2M6-DMIzMK4T.js → oc-FR-POXYY2M6-BMqr4WHW.js} +1 -1
- package/dist/viewer/{pa-IN-N4M65BXN-41DD7OQe.js → pa-IN-N4M65BXN-BWvaUxU-.js} +1 -1
- package/dist/viewer/{packet-AYTQ26CC-Bu-WAKTD.js → packet-AYTQ26CC-Nm-7d4T7.js} +1 -1
- package/dist/viewer/{pegDiagram-XKGWAZYB-uVPAabVE.js → pegDiagram-XKGWAZYB-Ck2BR5Qb.js} +1 -1
- package/dist/viewer/percentages-BXMCSKIN-50X9K3MT.js +1 -0
- package/dist/viewer/{pie-WAS4IAKB-DQReqHvw.js → pie-WAS4IAKB-DUW05HU3.js} +1 -1
- package/dist/viewer/{pieDiagram-E7YTZNPT-C3oXg-0M.js → pieDiagram-E7YTZNPT-D_R0FEOX.js} +1 -1
- package/dist/viewer/{pl-PL-T2D74RX3-Alwp-N8q.js → pl-PL-T2D74RX3-xZvABOI-.js} +1 -1
- package/dist/viewer/{prod-ySJSNXbS.js → prod-CxvgXXgp.js} +12 -12
- package/dist/viewer/{pt-BR-5N22H2LF-B5hujQ7a.js → pt-BR-5N22H2LF-CSj-mVgR.js} +1 -1
- package/dist/viewer/{pt-PT-UZXXM6DQ-2SfaLzgV.js → pt-PT-UZXXM6DQ-noHR1ql1.js} +1 -1
- package/dist/viewer/{quadrantDiagram-AXDQQJYC-Dq6DcHSL.js → quadrantDiagram-AXDQQJYC-CBWQysk9.js} +1 -1
- package/dist/viewer/{radar-RG4KPBEZ-D_r12v0L.js → radar-RG4KPBEZ-C-qb8AwS.js} +1 -1
- package/dist/viewer/{railroad-74A4TZTK-JLrx94cB.js → railroad-74A4TZTK-CN-vYYIp.js} +1 -1
- package/dist/viewer/{railroad-abnf-HS5TGJTU-zGEQrPX3.js → railroad-abnf-HS5TGJTU-CIbwPEoO.js} +1 -1
- package/dist/viewer/{railroad-ebnf-LZEXJU2U-CwEVA1VE.js → railroad-ebnf-LZEXJU2U-BiGh6OTy.js} +1 -1
- package/dist/viewer/{railroad-peg-WCYAUIDC-aKEE6HSg.js → railroad-peg-WCYAUIDC-Ch799Qw2.js} +1 -1
- package/dist/viewer/{railroadDiagram-O6MQD6OU-DrnlOatY.js → railroadDiagram-O6MQD6OU-Bagb5kRs.js} +1 -1
- package/dist/viewer/{requirementDiagram-BXWQKSXE-DKxY-NWP.js → requirementDiagram-BXWQKSXE-DbDliiGP.js} +1 -1
- package/dist/viewer/{ro-RO-JPDTUUEW-JOyBW8W2.js → ro-RO-JPDTUUEW-DeHkNnfy.js} +1 -1
- package/dist/viewer/{ru-RU-B4JR7IUQ-BLbtgTqp.js → ru-RU-B4JR7IUQ-CHFTZftm.js} +1 -1
- package/dist/viewer/{sankeyDiagram-P5KCCOFB-DO2JtEMk.js → sankeyDiagram-P5KCCOFB-B1FoUvnF.js} +1 -1
- package/dist/viewer/{sequenceDiagram-WJ2MYXX4-C1sYn_3k.js → sequenceDiagram-WJ2MYXX4-YjNUuoUX.js} +1 -1
- package/dist/viewer/{si-LK-N5RQ5JYF-ESFevx_w.js → si-LK-N5RQ5JYF-Dp4ARNRJ.js} +1 -1
- package/dist/viewer/{sk-SK-C5VTKIMK-eDBREo_B.js → sk-SK-C5VTKIMK-AKA_erzT.js} +1 -1
- package/dist/viewer/{sl-SI-NN7IZMDC-BqXM_BeS.js → sl-SI-NN7IZMDC-BDiZjXA1.js} +1 -1
- package/dist/viewer/{stateDiagram-D77RDMKH-CJvvpxuS.js → stateDiagram-D77RDMKH-ATh-w1b3.js} +1 -1
- package/dist/viewer/stateDiagram-v2-MP3YSRHH-wUz1nCet.js +1 -0
- package/dist/viewer/subset-shared.chunk-M2Qq5pRR.js +1 -0
- package/dist/viewer/{subset-worker.chunk-DiOJqdEr.js → subset-worker.chunk-CBUvRfcN.js} +1 -1
- package/dist/viewer/{sv-SE-XGPEYMSR-DpsnI9cb.js → sv-SE-XGPEYMSR-Cj0AcU_6.js} +1 -1
- package/dist/viewer/{swimlanes-42K2YHIH-BlmcmFmq.js → swimlanes-42K2YHIH-C6oPbOc_.js} +1 -1
- package/dist/viewer/swimlanesDiagram-VR7AAH4N-c6uNYsV1.js +8 -0
- package/dist/viewer/{ta-IN-2NMHFXQM-C_0XjBYF.js → ta-IN-2NMHFXQM-8VJaxDdr.js} +1 -1
- package/dist/viewer/{th-TH-HPSO5L25-OjEhQMpS.js → th-TH-HPSO5L25-Czv7oKbg.js} +1 -1
- package/dist/viewer/{timeline-definition-24CTP7MA-pst6amGk.js → timeline-definition-24CTP7MA-DLUP8njF.js} +1 -1
- package/dist/viewer/{tr-TR-DEFEU3FU-Dm4e1xKH.js → tr-TR-DEFEU3FU-cMr0klQe.js} +1 -1
- package/dist/viewer/{treeView-Q6P3EWNA-DaAtai94.js → treeView-Q6P3EWNA-BUR1hhrC.js} +1 -1
- package/dist/viewer/{treemap-WGGIJYW6-BrSC50io.js → treemap-WGGIJYW6-DoZbg1PH.js} +1 -1
- package/dist/viewer/{uk-UA-QMV73CPH-CfLwpRAs.js → uk-UA-QMV73CPH-DtCG1wYk.js} +1 -1
- package/dist/viewer/useSandboxFrame-CqqcCy4p.js +58 -0
- package/dist/viewer/{vennDiagram-4TSXK5OY-BSoX8DTP.js → vennDiagram-4TSXK5OY-CawO2Qt4.js} +1 -1
- package/dist/viewer/{vi-VN-M7AON7JQ-mIsW2M_F.js → vi-VN-M7AON7JQ-BpNbQd8Q.js} +1 -1
- package/dist/viewer/{wardley-WFR3VGLG-CtJjyNRB.js → wardley-WFR3VGLG-QixpmoDn.js} +1 -1
- package/dist/viewer/{wardleyDiagram-VM6X3IG4-B5IWg9e7.js → wardleyDiagram-VM6X3IG4-WPo1rwgF.js} +1 -1
- package/dist/viewer/{xychartDiagram-S5SC5T6Z-DbWncZlG.js → xychartDiagram-S5SC5T6Z-DGBqDGeR.js} +1 -1
- package/dist/viewer/{zh-CN-LNUGB5OW-BHKxQHPI.js → zh-CN-LNUGB5OW-Col_PjC7.js} +1 -1
- package/dist/viewer/{zh-HK-E62DVLB3-C7ow-qQq.js → zh-HK-E62DVLB3-z4YynTvk.js} +1 -1
- package/dist/viewer/{zh-TW-RAJ6MFWO-cMHXP31O.js → zh-TW-RAJ6MFWO-DRUQUZWj.js} +1 -1
- package/package.json +5 -2
- package/dist/viewer/CloudDocument-B2OX6t3e.js +0 -1
- package/dist/viewer/DocumentPage-BIWUFGFf.js +0 -1
- package/dist/viewer/channel-CoY9xRKf.js +0 -1
- package/dist/viewer/chunk-75Z2AOVW-CdsddFLa.js +0 -2
- package/dist/viewer/classDiagram-ZZMXUADV-CWZttORQ.js +0 -1
- package/dist/viewer/classDiagram-v2-VYDZK3BY-CWZttORQ.js +0 -1
- package/dist/viewer/dist-CMIAphY9.js +0 -9
- package/dist/viewer/dist-Ca3ufzBu.js +0 -6
- package/dist/viewer/dist-CikCUJ2t.js +0 -23
- package/dist/viewer/flowDiagram-HODETNUW-MvatQiHP.js +0 -1
- package/dist/viewer/ganttDiagram-EL5Y4UJY-BUm55-xG.js +0 -292
- package/dist/viewer/percentages-BXMCSKIN-J4WEidxJ.js +0 -1
- package/dist/viewer/stateDiagram-v2-MP3YSRHH-dDB6H_u-.js +0 -1
- package/dist/viewer/subset-shared.chunk-ByjcYtUv.js +0 -1
- package/dist/viewer/swimlanesDiagram-VR7AAH4N-BjBtRBuJ.js +0 -8
package/dist/server.cjs
CHANGED
|
@@ -1561,6 +1561,3614 @@ var require_canvas = __commonJS({
|
|
|
1561
1561
|
}
|
|
1562
1562
|
});
|
|
1563
1563
|
|
|
1564
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/constants.js
|
|
1565
|
+
var require_constants = __commonJS({
|
|
1566
|
+
"node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/constants.js"(exports2, module2) {
|
|
1567
|
+
"use strict";
|
|
1568
|
+
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
1569
|
+
var hasBlob = typeof Blob !== "undefined";
|
|
1570
|
+
if (hasBlob) BINARY_TYPES.push("blob");
|
|
1571
|
+
module2.exports = {
|
|
1572
|
+
BINARY_TYPES,
|
|
1573
|
+
EMPTY_BUFFER: Buffer.alloc(0),
|
|
1574
|
+
GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
|
1575
|
+
hasBlob,
|
|
1576
|
+
kForOnEventAttribute: /* @__PURE__ */ Symbol("kIsForOnEventAttribute"),
|
|
1577
|
+
kListener: /* @__PURE__ */ Symbol("kListener"),
|
|
1578
|
+
kStatusCode: /* @__PURE__ */ Symbol("status-code"),
|
|
1579
|
+
kWebSocket: /* @__PURE__ */ Symbol("websocket"),
|
|
1580
|
+
NOOP: () => {
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
});
|
|
1585
|
+
|
|
1586
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/buffer-util.js
|
|
1587
|
+
var require_buffer_util = __commonJS({
|
|
1588
|
+
"node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/buffer-util.js"(exports2, module2) {
|
|
1589
|
+
"use strict";
|
|
1590
|
+
var { EMPTY_BUFFER } = require_constants();
|
|
1591
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
1592
|
+
function concat(list2, totalLength) {
|
|
1593
|
+
if (list2.length === 0) return EMPTY_BUFFER;
|
|
1594
|
+
if (list2.length === 1) return list2[0];
|
|
1595
|
+
const target = Buffer.allocUnsafe(totalLength);
|
|
1596
|
+
let offset = 0;
|
|
1597
|
+
for (let i6 = 0; i6 < list2.length; i6++) {
|
|
1598
|
+
const buf = list2[i6];
|
|
1599
|
+
target.set(buf, offset);
|
|
1600
|
+
offset += buf.length;
|
|
1601
|
+
}
|
|
1602
|
+
if (offset < totalLength) {
|
|
1603
|
+
return new FastBuffer(target.buffer, target.byteOffset, offset);
|
|
1604
|
+
}
|
|
1605
|
+
return target;
|
|
1606
|
+
}
|
|
1607
|
+
function _mask(source, mask, output, offset, length) {
|
|
1608
|
+
for (let i6 = 0; i6 < length; i6++) {
|
|
1609
|
+
output[offset + i6] = source[i6] ^ mask[i6 & 3];
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
function _unmask(buffer, mask) {
|
|
1613
|
+
for (let i6 = 0; i6 < buffer.length; i6++) {
|
|
1614
|
+
buffer[i6] ^= mask[i6 & 3];
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
function toArrayBuffer(buf) {
|
|
1618
|
+
if (buf.length === buf.buffer.byteLength) {
|
|
1619
|
+
return buf.buffer;
|
|
1620
|
+
}
|
|
1621
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
1622
|
+
}
|
|
1623
|
+
function toBuffer(data) {
|
|
1624
|
+
toBuffer.readOnly = true;
|
|
1625
|
+
if (Buffer.isBuffer(data)) return data;
|
|
1626
|
+
let buf;
|
|
1627
|
+
if (data instanceof ArrayBuffer) {
|
|
1628
|
+
buf = new FastBuffer(data);
|
|
1629
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
1630
|
+
buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
|
|
1631
|
+
} else {
|
|
1632
|
+
buf = Buffer.from(data);
|
|
1633
|
+
toBuffer.readOnly = false;
|
|
1634
|
+
}
|
|
1635
|
+
return buf;
|
|
1636
|
+
}
|
|
1637
|
+
module2.exports = {
|
|
1638
|
+
concat,
|
|
1639
|
+
mask: _mask,
|
|
1640
|
+
toArrayBuffer,
|
|
1641
|
+
toBuffer,
|
|
1642
|
+
unmask: _unmask
|
|
1643
|
+
};
|
|
1644
|
+
if (!process.env.WS_NO_BUFFER_UTIL) {
|
|
1645
|
+
try {
|
|
1646
|
+
const bufferUtil = require("bufferutil");
|
|
1647
|
+
module2.exports.mask = function(source, mask, output, offset, length) {
|
|
1648
|
+
if (length < 48) _mask(source, mask, output, offset, length);
|
|
1649
|
+
else bufferUtil.mask(source, mask, output, offset, length);
|
|
1650
|
+
};
|
|
1651
|
+
module2.exports.unmask = function(buffer, mask) {
|
|
1652
|
+
if (buffer.length < 32) _unmask(buffer, mask);
|
|
1653
|
+
else bufferUtil.unmask(buffer, mask);
|
|
1654
|
+
};
|
|
1655
|
+
} catch (e5) {
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
});
|
|
1660
|
+
|
|
1661
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/limiter.js
|
|
1662
|
+
var require_limiter = __commonJS({
|
|
1663
|
+
"node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/limiter.js"(exports2, module2) {
|
|
1664
|
+
"use strict";
|
|
1665
|
+
var kDone = /* @__PURE__ */ Symbol("kDone");
|
|
1666
|
+
var kRun = /* @__PURE__ */ Symbol("kRun");
|
|
1667
|
+
var Limiter = class {
|
|
1668
|
+
/**
|
|
1669
|
+
* Creates a new `Limiter`.
|
|
1670
|
+
*
|
|
1671
|
+
* @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
|
|
1672
|
+
* to run concurrently
|
|
1673
|
+
*/
|
|
1674
|
+
constructor(concurrency) {
|
|
1675
|
+
this[kDone] = () => {
|
|
1676
|
+
this.pending--;
|
|
1677
|
+
this[kRun]();
|
|
1678
|
+
};
|
|
1679
|
+
this.concurrency = concurrency || Infinity;
|
|
1680
|
+
this.jobs = [];
|
|
1681
|
+
this.pending = 0;
|
|
1682
|
+
}
|
|
1683
|
+
/**
|
|
1684
|
+
* Adds a job to the queue.
|
|
1685
|
+
*
|
|
1686
|
+
* @param {Function} job The job to run
|
|
1687
|
+
* @public
|
|
1688
|
+
*/
|
|
1689
|
+
add(job) {
|
|
1690
|
+
this.jobs.push(job);
|
|
1691
|
+
this[kRun]();
|
|
1692
|
+
}
|
|
1693
|
+
/**
|
|
1694
|
+
* Removes a job from the queue and runs it if possible.
|
|
1695
|
+
*
|
|
1696
|
+
* @private
|
|
1697
|
+
*/
|
|
1698
|
+
[kRun]() {
|
|
1699
|
+
if (this.pending === this.concurrency) return;
|
|
1700
|
+
if (this.jobs.length) {
|
|
1701
|
+
const job = this.jobs.shift();
|
|
1702
|
+
this.pending++;
|
|
1703
|
+
job(this[kDone]);
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
};
|
|
1707
|
+
module2.exports = Limiter;
|
|
1708
|
+
}
|
|
1709
|
+
});
|
|
1710
|
+
|
|
1711
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/permessage-deflate.js
|
|
1712
|
+
var require_permessage_deflate = __commonJS({
|
|
1713
|
+
"node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/permessage-deflate.js"(exports2, module2) {
|
|
1714
|
+
"use strict";
|
|
1715
|
+
var zlib = require("zlib");
|
|
1716
|
+
var bufferUtil = require_buffer_util();
|
|
1717
|
+
var Limiter = require_limiter();
|
|
1718
|
+
var { kStatusCode } = require_constants();
|
|
1719
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
1720
|
+
var TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
1721
|
+
var kPerMessageDeflate = /* @__PURE__ */ Symbol("permessage-deflate");
|
|
1722
|
+
var kTotalLength = /* @__PURE__ */ Symbol("total-length");
|
|
1723
|
+
var kCallback = /* @__PURE__ */ Symbol("callback");
|
|
1724
|
+
var kBuffers = /* @__PURE__ */ Symbol("buffers");
|
|
1725
|
+
var kError = /* @__PURE__ */ Symbol("error");
|
|
1726
|
+
var zlibLimiter;
|
|
1727
|
+
var PerMessageDeflate = class {
|
|
1728
|
+
/**
|
|
1729
|
+
* Creates a PerMessageDeflate instance.
|
|
1730
|
+
*
|
|
1731
|
+
* @param {Object} [options] Configuration options
|
|
1732
|
+
* @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
|
|
1733
|
+
* for, or request, a custom client window size
|
|
1734
|
+
* @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
|
|
1735
|
+
* acknowledge disabling of client context takeover
|
|
1736
|
+
* @param {Number} [options.concurrencyLimit=10] The number of concurrent
|
|
1737
|
+
* calls to zlib
|
|
1738
|
+
* @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
|
|
1739
|
+
* use of a custom server window size
|
|
1740
|
+
* @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
|
|
1741
|
+
* disabling of server context takeover
|
|
1742
|
+
* @param {Number} [options.threshold=1024] Size (in bytes) below which
|
|
1743
|
+
* messages should not be compressed if context takeover is disabled
|
|
1744
|
+
* @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
|
|
1745
|
+
* deflate
|
|
1746
|
+
* @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
|
|
1747
|
+
* inflate
|
|
1748
|
+
* @param {Boolean} [isServer=false] Create the instance in either server or
|
|
1749
|
+
* client mode
|
|
1750
|
+
* @param {Number} [maxPayload=0] The maximum allowed message length
|
|
1751
|
+
*/
|
|
1752
|
+
constructor(options, isServer, maxPayload) {
|
|
1753
|
+
this._maxPayload = maxPayload | 0;
|
|
1754
|
+
this._options = options || {};
|
|
1755
|
+
this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
|
|
1756
|
+
this._isServer = !!isServer;
|
|
1757
|
+
this._deflate = null;
|
|
1758
|
+
this._inflate = null;
|
|
1759
|
+
this.params = null;
|
|
1760
|
+
if (!zlibLimiter) {
|
|
1761
|
+
const concurrency = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
|
|
1762
|
+
zlibLimiter = new Limiter(concurrency);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
/**
|
|
1766
|
+
* @type {String}
|
|
1767
|
+
*/
|
|
1768
|
+
static get extensionName() {
|
|
1769
|
+
return "permessage-deflate";
|
|
1770
|
+
}
|
|
1771
|
+
/**
|
|
1772
|
+
* Create an extension negotiation offer.
|
|
1773
|
+
*
|
|
1774
|
+
* @return {Object} Extension parameters
|
|
1775
|
+
* @public
|
|
1776
|
+
*/
|
|
1777
|
+
offer() {
|
|
1778
|
+
const params = {};
|
|
1779
|
+
if (this._options.serverNoContextTakeover) {
|
|
1780
|
+
params.server_no_context_takeover = true;
|
|
1781
|
+
}
|
|
1782
|
+
if (this._options.clientNoContextTakeover) {
|
|
1783
|
+
params.client_no_context_takeover = true;
|
|
1784
|
+
}
|
|
1785
|
+
if (this._options.serverMaxWindowBits) {
|
|
1786
|
+
params.server_max_window_bits = this._options.serverMaxWindowBits;
|
|
1787
|
+
}
|
|
1788
|
+
if (this._options.clientMaxWindowBits) {
|
|
1789
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
1790
|
+
} else if (this._options.clientMaxWindowBits == null) {
|
|
1791
|
+
params.client_max_window_bits = true;
|
|
1792
|
+
}
|
|
1793
|
+
return params;
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Accept an extension negotiation offer/response.
|
|
1797
|
+
*
|
|
1798
|
+
* @param {Array} configurations The extension negotiation offers/reponse
|
|
1799
|
+
* @return {Object} Accepted configuration
|
|
1800
|
+
* @public
|
|
1801
|
+
*/
|
|
1802
|
+
accept(configurations) {
|
|
1803
|
+
configurations = this.normalizeParams(configurations);
|
|
1804
|
+
this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
|
|
1805
|
+
return this.params;
|
|
1806
|
+
}
|
|
1807
|
+
/**
|
|
1808
|
+
* Releases all resources used by the extension.
|
|
1809
|
+
*
|
|
1810
|
+
* @public
|
|
1811
|
+
*/
|
|
1812
|
+
cleanup() {
|
|
1813
|
+
if (this._inflate) {
|
|
1814
|
+
this._inflate.close();
|
|
1815
|
+
this._inflate = null;
|
|
1816
|
+
}
|
|
1817
|
+
if (this._deflate) {
|
|
1818
|
+
const callback = this._deflate[kCallback];
|
|
1819
|
+
this._deflate.close();
|
|
1820
|
+
this._deflate = null;
|
|
1821
|
+
if (callback) {
|
|
1822
|
+
callback(
|
|
1823
|
+
new Error(
|
|
1824
|
+
"The deflate stream was closed while data was being processed"
|
|
1825
|
+
)
|
|
1826
|
+
);
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Accept an extension negotiation offer.
|
|
1832
|
+
*
|
|
1833
|
+
* @param {Array} offers The extension negotiation offers
|
|
1834
|
+
* @return {Object} Accepted configuration
|
|
1835
|
+
* @private
|
|
1836
|
+
*/
|
|
1837
|
+
acceptAsServer(offers) {
|
|
1838
|
+
const opts = this._options;
|
|
1839
|
+
const accepted = offers.find((params) => {
|
|
1840
|
+
if (opts.serverNoContextTakeover === false && params.server_no_context_takeover || params.server_max_window_bits && (opts.serverMaxWindowBits === false || typeof opts.serverMaxWindowBits === "number" && opts.serverMaxWindowBits > params.server_max_window_bits) || typeof opts.clientMaxWindowBits === "number" && !params.client_max_window_bits) {
|
|
1841
|
+
return false;
|
|
1842
|
+
}
|
|
1843
|
+
return true;
|
|
1844
|
+
});
|
|
1845
|
+
if (!accepted) {
|
|
1846
|
+
throw new Error("None of the extension offers can be accepted");
|
|
1847
|
+
}
|
|
1848
|
+
if (opts.serverNoContextTakeover) {
|
|
1849
|
+
accepted.server_no_context_takeover = true;
|
|
1850
|
+
}
|
|
1851
|
+
if (opts.clientNoContextTakeover) {
|
|
1852
|
+
accepted.client_no_context_takeover = true;
|
|
1853
|
+
}
|
|
1854
|
+
if (typeof opts.serverMaxWindowBits === "number") {
|
|
1855
|
+
accepted.server_max_window_bits = opts.serverMaxWindowBits;
|
|
1856
|
+
}
|
|
1857
|
+
if (typeof opts.clientMaxWindowBits === "number") {
|
|
1858
|
+
accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
|
1859
|
+
} else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
|
|
1860
|
+
delete accepted.client_max_window_bits;
|
|
1861
|
+
}
|
|
1862
|
+
return accepted;
|
|
1863
|
+
}
|
|
1864
|
+
/**
|
|
1865
|
+
* Accept the extension negotiation response.
|
|
1866
|
+
*
|
|
1867
|
+
* @param {Array} response The extension negotiation response
|
|
1868
|
+
* @return {Object} Accepted configuration
|
|
1869
|
+
* @private
|
|
1870
|
+
*/
|
|
1871
|
+
acceptAsClient(response) {
|
|
1872
|
+
const params = response[0];
|
|
1873
|
+
if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
|
|
1874
|
+
throw new Error('Unexpected parameter "client_no_context_takeover"');
|
|
1875
|
+
}
|
|
1876
|
+
if (!params.client_max_window_bits) {
|
|
1877
|
+
if (typeof this._options.clientMaxWindowBits === "number") {
|
|
1878
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
1879
|
+
}
|
|
1880
|
+
} else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
|
|
1881
|
+
throw new Error(
|
|
1882
|
+
'Unexpected or invalid parameter "client_max_window_bits"'
|
|
1883
|
+
);
|
|
1884
|
+
}
|
|
1885
|
+
return params;
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* Normalize parameters.
|
|
1889
|
+
*
|
|
1890
|
+
* @param {Array} configurations The extension negotiation offers/reponse
|
|
1891
|
+
* @return {Array} The offers/response with normalized parameters
|
|
1892
|
+
* @private
|
|
1893
|
+
*/
|
|
1894
|
+
normalizeParams(configurations) {
|
|
1895
|
+
configurations.forEach((params) => {
|
|
1896
|
+
Object.keys(params).forEach((key2) => {
|
|
1897
|
+
let value = params[key2];
|
|
1898
|
+
if (value.length > 1) {
|
|
1899
|
+
throw new Error(`Parameter "${key2}" must have only a single value`);
|
|
1900
|
+
}
|
|
1901
|
+
value = value[0];
|
|
1902
|
+
if (key2 === "client_max_window_bits") {
|
|
1903
|
+
if (value !== true) {
|
|
1904
|
+
const num7 = +value;
|
|
1905
|
+
if (!Number.isInteger(num7) || num7 < 8 || num7 > 15) {
|
|
1906
|
+
throw new TypeError(
|
|
1907
|
+
`Invalid value for parameter "${key2}": ${value}`
|
|
1908
|
+
);
|
|
1909
|
+
}
|
|
1910
|
+
value = num7;
|
|
1911
|
+
} else if (!this._isServer) {
|
|
1912
|
+
throw new TypeError(
|
|
1913
|
+
`Invalid value for parameter "${key2}": ${value}`
|
|
1914
|
+
);
|
|
1915
|
+
}
|
|
1916
|
+
} else if (key2 === "server_max_window_bits") {
|
|
1917
|
+
const num7 = +value;
|
|
1918
|
+
if (!Number.isInteger(num7) || num7 < 8 || num7 > 15) {
|
|
1919
|
+
throw new TypeError(
|
|
1920
|
+
`Invalid value for parameter "${key2}": ${value}`
|
|
1921
|
+
);
|
|
1922
|
+
}
|
|
1923
|
+
value = num7;
|
|
1924
|
+
} else if (key2 === "client_no_context_takeover" || key2 === "server_no_context_takeover") {
|
|
1925
|
+
if (value !== true) {
|
|
1926
|
+
throw new TypeError(
|
|
1927
|
+
`Invalid value for parameter "${key2}": ${value}`
|
|
1928
|
+
);
|
|
1929
|
+
}
|
|
1930
|
+
} else {
|
|
1931
|
+
throw new Error(`Unknown parameter "${key2}"`);
|
|
1932
|
+
}
|
|
1933
|
+
params[key2] = value;
|
|
1934
|
+
});
|
|
1935
|
+
});
|
|
1936
|
+
return configurations;
|
|
1937
|
+
}
|
|
1938
|
+
/**
|
|
1939
|
+
* Decompress data. Concurrency limited.
|
|
1940
|
+
*
|
|
1941
|
+
* @param {Buffer} data Compressed data
|
|
1942
|
+
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
1943
|
+
* @param {Function} callback Callback
|
|
1944
|
+
* @public
|
|
1945
|
+
*/
|
|
1946
|
+
decompress(data, fin, callback) {
|
|
1947
|
+
zlibLimiter.add((done) => {
|
|
1948
|
+
this._decompress(data, fin, (err, result) => {
|
|
1949
|
+
done();
|
|
1950
|
+
callback(err, result);
|
|
1951
|
+
});
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
/**
|
|
1955
|
+
* Compress data. Concurrency limited.
|
|
1956
|
+
*
|
|
1957
|
+
* @param {(Buffer|String)} data Data to compress
|
|
1958
|
+
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
1959
|
+
* @param {Function} callback Callback
|
|
1960
|
+
* @public
|
|
1961
|
+
*/
|
|
1962
|
+
compress(data, fin, callback) {
|
|
1963
|
+
zlibLimiter.add((done) => {
|
|
1964
|
+
this._compress(data, fin, (err, result) => {
|
|
1965
|
+
done();
|
|
1966
|
+
callback(err, result);
|
|
1967
|
+
});
|
|
1968
|
+
});
|
|
1969
|
+
}
|
|
1970
|
+
/**
|
|
1971
|
+
* Decompress data.
|
|
1972
|
+
*
|
|
1973
|
+
* @param {Buffer} data Compressed data
|
|
1974
|
+
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
1975
|
+
* @param {Function} callback Callback
|
|
1976
|
+
* @private
|
|
1977
|
+
*/
|
|
1978
|
+
_decompress(data, fin, callback) {
|
|
1979
|
+
const endpoint = this._isServer ? "client" : "server";
|
|
1980
|
+
if (!this._inflate) {
|
|
1981
|
+
const key2 = `${endpoint}_max_window_bits`;
|
|
1982
|
+
const windowBits = typeof this.params[key2] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key2];
|
|
1983
|
+
this._inflate = zlib.createInflateRaw({
|
|
1984
|
+
...this._options.zlibInflateOptions,
|
|
1985
|
+
windowBits
|
|
1986
|
+
});
|
|
1987
|
+
this._inflate[kPerMessageDeflate] = this;
|
|
1988
|
+
this._inflate[kTotalLength] = 0;
|
|
1989
|
+
this._inflate[kBuffers] = [];
|
|
1990
|
+
this._inflate.on("error", inflateOnError);
|
|
1991
|
+
this._inflate.on("data", inflateOnData);
|
|
1992
|
+
}
|
|
1993
|
+
this._inflate[kCallback] = callback;
|
|
1994
|
+
this._inflate.write(data);
|
|
1995
|
+
if (fin) this._inflate.write(TRAILER);
|
|
1996
|
+
this._inflate.flush(() => {
|
|
1997
|
+
const err = this._inflate[kError];
|
|
1998
|
+
if (err) {
|
|
1999
|
+
this._inflate.close();
|
|
2000
|
+
this._inflate = null;
|
|
2001
|
+
callback(err);
|
|
2002
|
+
return;
|
|
2003
|
+
}
|
|
2004
|
+
const data2 = bufferUtil.concat(
|
|
2005
|
+
this._inflate[kBuffers],
|
|
2006
|
+
this._inflate[kTotalLength]
|
|
2007
|
+
);
|
|
2008
|
+
if (this._inflate._readableState.endEmitted) {
|
|
2009
|
+
this._inflate.close();
|
|
2010
|
+
this._inflate = null;
|
|
2011
|
+
} else {
|
|
2012
|
+
this._inflate[kTotalLength] = 0;
|
|
2013
|
+
this._inflate[kBuffers] = [];
|
|
2014
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
2015
|
+
this._inflate.reset();
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
callback(null, data2);
|
|
2019
|
+
});
|
|
2020
|
+
}
|
|
2021
|
+
/**
|
|
2022
|
+
* Compress data.
|
|
2023
|
+
*
|
|
2024
|
+
* @param {(Buffer|String)} data Data to compress
|
|
2025
|
+
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
2026
|
+
* @param {Function} callback Callback
|
|
2027
|
+
* @private
|
|
2028
|
+
*/
|
|
2029
|
+
_compress(data, fin, callback) {
|
|
2030
|
+
const endpoint = this._isServer ? "server" : "client";
|
|
2031
|
+
if (!this._deflate) {
|
|
2032
|
+
const key2 = `${endpoint}_max_window_bits`;
|
|
2033
|
+
const windowBits = typeof this.params[key2] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key2];
|
|
2034
|
+
this._deflate = zlib.createDeflateRaw({
|
|
2035
|
+
...this._options.zlibDeflateOptions,
|
|
2036
|
+
windowBits
|
|
2037
|
+
});
|
|
2038
|
+
this._deflate[kTotalLength] = 0;
|
|
2039
|
+
this._deflate[kBuffers] = [];
|
|
2040
|
+
this._deflate.on("data", deflateOnData);
|
|
2041
|
+
}
|
|
2042
|
+
this._deflate[kCallback] = callback;
|
|
2043
|
+
this._deflate.write(data);
|
|
2044
|
+
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
|
|
2045
|
+
if (!this._deflate) {
|
|
2046
|
+
return;
|
|
2047
|
+
}
|
|
2048
|
+
let data2 = bufferUtil.concat(
|
|
2049
|
+
this._deflate[kBuffers],
|
|
2050
|
+
this._deflate[kTotalLength]
|
|
2051
|
+
);
|
|
2052
|
+
if (fin) {
|
|
2053
|
+
data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
|
|
2054
|
+
}
|
|
2055
|
+
this._deflate[kCallback] = null;
|
|
2056
|
+
this._deflate[kTotalLength] = 0;
|
|
2057
|
+
this._deflate[kBuffers] = [];
|
|
2058
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
2059
|
+
this._deflate.reset();
|
|
2060
|
+
}
|
|
2061
|
+
callback(null, data2);
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
};
|
|
2065
|
+
module2.exports = PerMessageDeflate;
|
|
2066
|
+
function deflateOnData(chunk) {
|
|
2067
|
+
this[kBuffers].push(chunk);
|
|
2068
|
+
this[kTotalLength] += chunk.length;
|
|
2069
|
+
}
|
|
2070
|
+
function inflateOnData(chunk) {
|
|
2071
|
+
this[kTotalLength] += chunk.length;
|
|
2072
|
+
if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
|
|
2073
|
+
this[kBuffers].push(chunk);
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
this[kError] = new RangeError("Max payload size exceeded");
|
|
2077
|
+
this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
|
|
2078
|
+
this[kError][kStatusCode] = 1009;
|
|
2079
|
+
this.removeListener("data", inflateOnData);
|
|
2080
|
+
this.reset();
|
|
2081
|
+
}
|
|
2082
|
+
function inflateOnError(err) {
|
|
2083
|
+
this[kPerMessageDeflate]._inflate = null;
|
|
2084
|
+
if (this[kError]) {
|
|
2085
|
+
this[kCallback](this[kError]);
|
|
2086
|
+
return;
|
|
2087
|
+
}
|
|
2088
|
+
err[kStatusCode] = 1007;
|
|
2089
|
+
this[kCallback](err);
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
});
|
|
2093
|
+
|
|
2094
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/validation.js
|
|
2095
|
+
var require_validation = __commonJS({
|
|
2096
|
+
"node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/validation.js"(exports2, module2) {
|
|
2097
|
+
"use strict";
|
|
2098
|
+
var { isUtf8 } = require("buffer");
|
|
2099
|
+
var { hasBlob } = require_constants();
|
|
2100
|
+
var tokenChars = [
|
|
2101
|
+
0,
|
|
2102
|
+
0,
|
|
2103
|
+
0,
|
|
2104
|
+
0,
|
|
2105
|
+
0,
|
|
2106
|
+
0,
|
|
2107
|
+
0,
|
|
2108
|
+
0,
|
|
2109
|
+
0,
|
|
2110
|
+
0,
|
|
2111
|
+
0,
|
|
2112
|
+
0,
|
|
2113
|
+
0,
|
|
2114
|
+
0,
|
|
2115
|
+
0,
|
|
2116
|
+
0,
|
|
2117
|
+
// 0 - 15
|
|
2118
|
+
0,
|
|
2119
|
+
0,
|
|
2120
|
+
0,
|
|
2121
|
+
0,
|
|
2122
|
+
0,
|
|
2123
|
+
0,
|
|
2124
|
+
0,
|
|
2125
|
+
0,
|
|
2126
|
+
0,
|
|
2127
|
+
0,
|
|
2128
|
+
0,
|
|
2129
|
+
0,
|
|
2130
|
+
0,
|
|
2131
|
+
0,
|
|
2132
|
+
0,
|
|
2133
|
+
0,
|
|
2134
|
+
// 16 - 31
|
|
2135
|
+
0,
|
|
2136
|
+
1,
|
|
2137
|
+
0,
|
|
2138
|
+
1,
|
|
2139
|
+
1,
|
|
2140
|
+
1,
|
|
2141
|
+
1,
|
|
2142
|
+
1,
|
|
2143
|
+
0,
|
|
2144
|
+
0,
|
|
2145
|
+
1,
|
|
2146
|
+
1,
|
|
2147
|
+
0,
|
|
2148
|
+
1,
|
|
2149
|
+
1,
|
|
2150
|
+
0,
|
|
2151
|
+
// 32 - 47
|
|
2152
|
+
1,
|
|
2153
|
+
1,
|
|
2154
|
+
1,
|
|
2155
|
+
1,
|
|
2156
|
+
1,
|
|
2157
|
+
1,
|
|
2158
|
+
1,
|
|
2159
|
+
1,
|
|
2160
|
+
1,
|
|
2161
|
+
1,
|
|
2162
|
+
0,
|
|
2163
|
+
0,
|
|
2164
|
+
0,
|
|
2165
|
+
0,
|
|
2166
|
+
0,
|
|
2167
|
+
0,
|
|
2168
|
+
// 48 - 63
|
|
2169
|
+
0,
|
|
2170
|
+
1,
|
|
2171
|
+
1,
|
|
2172
|
+
1,
|
|
2173
|
+
1,
|
|
2174
|
+
1,
|
|
2175
|
+
1,
|
|
2176
|
+
1,
|
|
2177
|
+
1,
|
|
2178
|
+
1,
|
|
2179
|
+
1,
|
|
2180
|
+
1,
|
|
2181
|
+
1,
|
|
2182
|
+
1,
|
|
2183
|
+
1,
|
|
2184
|
+
1,
|
|
2185
|
+
// 64 - 79
|
|
2186
|
+
1,
|
|
2187
|
+
1,
|
|
2188
|
+
1,
|
|
2189
|
+
1,
|
|
2190
|
+
1,
|
|
2191
|
+
1,
|
|
2192
|
+
1,
|
|
2193
|
+
1,
|
|
2194
|
+
1,
|
|
2195
|
+
1,
|
|
2196
|
+
1,
|
|
2197
|
+
0,
|
|
2198
|
+
0,
|
|
2199
|
+
0,
|
|
2200
|
+
1,
|
|
2201
|
+
1,
|
|
2202
|
+
// 80 - 95
|
|
2203
|
+
1,
|
|
2204
|
+
1,
|
|
2205
|
+
1,
|
|
2206
|
+
1,
|
|
2207
|
+
1,
|
|
2208
|
+
1,
|
|
2209
|
+
1,
|
|
2210
|
+
1,
|
|
2211
|
+
1,
|
|
2212
|
+
1,
|
|
2213
|
+
1,
|
|
2214
|
+
1,
|
|
2215
|
+
1,
|
|
2216
|
+
1,
|
|
2217
|
+
1,
|
|
2218
|
+
1,
|
|
2219
|
+
// 96 - 111
|
|
2220
|
+
1,
|
|
2221
|
+
1,
|
|
2222
|
+
1,
|
|
2223
|
+
1,
|
|
2224
|
+
1,
|
|
2225
|
+
1,
|
|
2226
|
+
1,
|
|
2227
|
+
1,
|
|
2228
|
+
1,
|
|
2229
|
+
1,
|
|
2230
|
+
1,
|
|
2231
|
+
0,
|
|
2232
|
+
1,
|
|
2233
|
+
0,
|
|
2234
|
+
1,
|
|
2235
|
+
0
|
|
2236
|
+
// 112 - 127
|
|
2237
|
+
];
|
|
2238
|
+
function isValidStatusCode(code) {
|
|
2239
|
+
return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
|
|
2240
|
+
}
|
|
2241
|
+
function _isValidUTF8(buf) {
|
|
2242
|
+
const len = buf.length;
|
|
2243
|
+
let i6 = 0;
|
|
2244
|
+
while (i6 < len) {
|
|
2245
|
+
if ((buf[i6] & 128) === 0) {
|
|
2246
|
+
i6++;
|
|
2247
|
+
} else if ((buf[i6] & 224) === 192) {
|
|
2248
|
+
if (i6 + 1 === len || (buf[i6 + 1] & 192) !== 128 || (buf[i6] & 254) === 192) {
|
|
2249
|
+
return false;
|
|
2250
|
+
}
|
|
2251
|
+
i6 += 2;
|
|
2252
|
+
} else if ((buf[i6] & 240) === 224) {
|
|
2253
|
+
if (i6 + 2 >= len || (buf[i6 + 1] & 192) !== 128 || (buf[i6 + 2] & 192) !== 128 || buf[i6] === 224 && (buf[i6 + 1] & 224) === 128 || // Overlong
|
|
2254
|
+
buf[i6] === 237 && (buf[i6 + 1] & 224) === 160) {
|
|
2255
|
+
return false;
|
|
2256
|
+
}
|
|
2257
|
+
i6 += 3;
|
|
2258
|
+
} else if ((buf[i6] & 248) === 240) {
|
|
2259
|
+
if (i6 + 3 >= len || (buf[i6 + 1] & 192) !== 128 || (buf[i6 + 2] & 192) !== 128 || (buf[i6 + 3] & 192) !== 128 || buf[i6] === 240 && (buf[i6 + 1] & 240) === 128 || // Overlong
|
|
2260
|
+
buf[i6] === 244 && buf[i6 + 1] > 143 || buf[i6] > 244) {
|
|
2261
|
+
return false;
|
|
2262
|
+
}
|
|
2263
|
+
i6 += 4;
|
|
2264
|
+
} else {
|
|
2265
|
+
return false;
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
return true;
|
|
2269
|
+
}
|
|
2270
|
+
function isBlob(value) {
|
|
2271
|
+
return hasBlob && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && (value[Symbol.toStringTag] === "Blob" || value[Symbol.toStringTag] === "File");
|
|
2272
|
+
}
|
|
2273
|
+
module2.exports = {
|
|
2274
|
+
isBlob,
|
|
2275
|
+
isValidStatusCode,
|
|
2276
|
+
isValidUTF8: _isValidUTF8,
|
|
2277
|
+
tokenChars
|
|
2278
|
+
};
|
|
2279
|
+
if (isUtf8) {
|
|
2280
|
+
module2.exports.isValidUTF8 = function(buf) {
|
|
2281
|
+
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
|
2282
|
+
};
|
|
2283
|
+
} else if (!process.env.WS_NO_UTF_8_VALIDATE) {
|
|
2284
|
+
try {
|
|
2285
|
+
const isValidUTF8 = require("utf-8-validate");
|
|
2286
|
+
module2.exports.isValidUTF8 = function(buf) {
|
|
2287
|
+
return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
|
|
2288
|
+
};
|
|
2289
|
+
} catch (e5) {
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
});
|
|
2294
|
+
|
|
2295
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/receiver.js
|
|
2296
|
+
var require_receiver = __commonJS({
|
|
2297
|
+
"node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/receiver.js"(exports2, module2) {
|
|
2298
|
+
"use strict";
|
|
2299
|
+
var { Writable } = require("stream");
|
|
2300
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
2301
|
+
var {
|
|
2302
|
+
BINARY_TYPES,
|
|
2303
|
+
EMPTY_BUFFER,
|
|
2304
|
+
kStatusCode,
|
|
2305
|
+
kWebSocket
|
|
2306
|
+
} = require_constants();
|
|
2307
|
+
var { concat, toArrayBuffer, unmask } = require_buffer_util();
|
|
2308
|
+
var { isValidStatusCode, isValidUTF8 } = require_validation();
|
|
2309
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
2310
|
+
var GET_INFO = 0;
|
|
2311
|
+
var GET_PAYLOAD_LENGTH_16 = 1;
|
|
2312
|
+
var GET_PAYLOAD_LENGTH_64 = 2;
|
|
2313
|
+
var GET_MASK = 3;
|
|
2314
|
+
var GET_DATA = 4;
|
|
2315
|
+
var INFLATING = 5;
|
|
2316
|
+
var DEFER_EVENT = 6;
|
|
2317
|
+
var Receiver2 = class extends Writable {
|
|
2318
|
+
/**
|
|
2319
|
+
* Creates a Receiver instance.
|
|
2320
|
+
*
|
|
2321
|
+
* @param {Object} [options] Options object
|
|
2322
|
+
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
|
|
2323
|
+
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
2324
|
+
* multiple times in the same tick
|
|
2325
|
+
* @param {String} [options.binaryType=nodebuffer] The type for binary data
|
|
2326
|
+
* @param {Object} [options.extensions] An object containing the negotiated
|
|
2327
|
+
* extensions
|
|
2328
|
+
* @param {Boolean} [options.isServer=false] Specifies whether to operate in
|
|
2329
|
+
* client or server mode
|
|
2330
|
+
* @param {Number} [options.maxPayload=0] The maximum allowed message length
|
|
2331
|
+
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
2332
|
+
* not to skip UTF-8 validation for text and close messages
|
|
2333
|
+
*/
|
|
2334
|
+
constructor(options = {}) {
|
|
2335
|
+
super();
|
|
2336
|
+
this._allowSynchronousEvents = options.allowSynchronousEvents !== void 0 ? options.allowSynchronousEvents : true;
|
|
2337
|
+
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
|
2338
|
+
this._extensions = options.extensions || {};
|
|
2339
|
+
this._isServer = !!options.isServer;
|
|
2340
|
+
this._maxPayload = options.maxPayload | 0;
|
|
2341
|
+
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
2342
|
+
this[kWebSocket] = void 0;
|
|
2343
|
+
this._bufferedBytes = 0;
|
|
2344
|
+
this._buffers = [];
|
|
2345
|
+
this._compressed = false;
|
|
2346
|
+
this._payloadLength = 0;
|
|
2347
|
+
this._mask = void 0;
|
|
2348
|
+
this._fragmented = 0;
|
|
2349
|
+
this._masked = false;
|
|
2350
|
+
this._fin = false;
|
|
2351
|
+
this._opcode = 0;
|
|
2352
|
+
this._totalPayloadLength = 0;
|
|
2353
|
+
this._messageLength = 0;
|
|
2354
|
+
this._fragments = [];
|
|
2355
|
+
this._errored = false;
|
|
2356
|
+
this._loop = false;
|
|
2357
|
+
this._state = GET_INFO;
|
|
2358
|
+
}
|
|
2359
|
+
/**
|
|
2360
|
+
* Implements `Writable.prototype._write()`.
|
|
2361
|
+
*
|
|
2362
|
+
* @param {Buffer} chunk The chunk of data to write
|
|
2363
|
+
* @param {String} encoding The character encoding of `chunk`
|
|
2364
|
+
* @param {Function} cb Callback
|
|
2365
|
+
* @private
|
|
2366
|
+
*/
|
|
2367
|
+
_write(chunk, encoding, cb) {
|
|
2368
|
+
if (this._opcode === 8 && this._state == GET_INFO) return cb();
|
|
2369
|
+
this._bufferedBytes += chunk.length;
|
|
2370
|
+
this._buffers.push(chunk);
|
|
2371
|
+
this.startLoop(cb);
|
|
2372
|
+
}
|
|
2373
|
+
/**
|
|
2374
|
+
* Consumes `n` bytes from the buffered data.
|
|
2375
|
+
*
|
|
2376
|
+
* @param {Number} n The number of bytes to consume
|
|
2377
|
+
* @return {Buffer} The consumed bytes
|
|
2378
|
+
* @private
|
|
2379
|
+
*/
|
|
2380
|
+
consume(n7) {
|
|
2381
|
+
this._bufferedBytes -= n7;
|
|
2382
|
+
if (n7 === this._buffers[0].length) return this._buffers.shift();
|
|
2383
|
+
if (n7 < this._buffers[0].length) {
|
|
2384
|
+
const buf = this._buffers[0];
|
|
2385
|
+
this._buffers[0] = new FastBuffer(
|
|
2386
|
+
buf.buffer,
|
|
2387
|
+
buf.byteOffset + n7,
|
|
2388
|
+
buf.length - n7
|
|
2389
|
+
);
|
|
2390
|
+
return new FastBuffer(buf.buffer, buf.byteOffset, n7);
|
|
2391
|
+
}
|
|
2392
|
+
const dst = Buffer.allocUnsafe(n7);
|
|
2393
|
+
do {
|
|
2394
|
+
const buf = this._buffers[0];
|
|
2395
|
+
const offset = dst.length - n7;
|
|
2396
|
+
if (n7 >= buf.length) {
|
|
2397
|
+
dst.set(this._buffers.shift(), offset);
|
|
2398
|
+
} else {
|
|
2399
|
+
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n7), offset);
|
|
2400
|
+
this._buffers[0] = new FastBuffer(
|
|
2401
|
+
buf.buffer,
|
|
2402
|
+
buf.byteOffset + n7,
|
|
2403
|
+
buf.length - n7
|
|
2404
|
+
);
|
|
2405
|
+
}
|
|
2406
|
+
n7 -= buf.length;
|
|
2407
|
+
} while (n7 > 0);
|
|
2408
|
+
return dst;
|
|
2409
|
+
}
|
|
2410
|
+
/**
|
|
2411
|
+
* Starts the parsing loop.
|
|
2412
|
+
*
|
|
2413
|
+
* @param {Function} cb Callback
|
|
2414
|
+
* @private
|
|
2415
|
+
*/
|
|
2416
|
+
startLoop(cb) {
|
|
2417
|
+
this._loop = true;
|
|
2418
|
+
do {
|
|
2419
|
+
switch (this._state) {
|
|
2420
|
+
case GET_INFO:
|
|
2421
|
+
this.getInfo(cb);
|
|
2422
|
+
break;
|
|
2423
|
+
case GET_PAYLOAD_LENGTH_16:
|
|
2424
|
+
this.getPayloadLength16(cb);
|
|
2425
|
+
break;
|
|
2426
|
+
case GET_PAYLOAD_LENGTH_64:
|
|
2427
|
+
this.getPayloadLength64(cb);
|
|
2428
|
+
break;
|
|
2429
|
+
case GET_MASK:
|
|
2430
|
+
this.getMask();
|
|
2431
|
+
break;
|
|
2432
|
+
case GET_DATA:
|
|
2433
|
+
this.getData(cb);
|
|
2434
|
+
break;
|
|
2435
|
+
case INFLATING:
|
|
2436
|
+
case DEFER_EVENT:
|
|
2437
|
+
this._loop = false;
|
|
2438
|
+
return;
|
|
2439
|
+
}
|
|
2440
|
+
} while (this._loop);
|
|
2441
|
+
if (!this._errored) cb();
|
|
2442
|
+
}
|
|
2443
|
+
/**
|
|
2444
|
+
* Reads the first two bytes of a frame.
|
|
2445
|
+
*
|
|
2446
|
+
* @param {Function} cb Callback
|
|
2447
|
+
* @private
|
|
2448
|
+
*/
|
|
2449
|
+
getInfo(cb) {
|
|
2450
|
+
if (this._bufferedBytes < 2) {
|
|
2451
|
+
this._loop = false;
|
|
2452
|
+
return;
|
|
2453
|
+
}
|
|
2454
|
+
const buf = this.consume(2);
|
|
2455
|
+
if ((buf[0] & 48) !== 0) {
|
|
2456
|
+
const error = this.createError(
|
|
2457
|
+
RangeError,
|
|
2458
|
+
"RSV2 and RSV3 must be clear",
|
|
2459
|
+
true,
|
|
2460
|
+
1002,
|
|
2461
|
+
"WS_ERR_UNEXPECTED_RSV_2_3"
|
|
2462
|
+
);
|
|
2463
|
+
cb(error);
|
|
2464
|
+
return;
|
|
2465
|
+
}
|
|
2466
|
+
const compressed = (buf[0] & 64) === 64;
|
|
2467
|
+
if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
|
|
2468
|
+
const error = this.createError(
|
|
2469
|
+
RangeError,
|
|
2470
|
+
"RSV1 must be clear",
|
|
2471
|
+
true,
|
|
2472
|
+
1002,
|
|
2473
|
+
"WS_ERR_UNEXPECTED_RSV_1"
|
|
2474
|
+
);
|
|
2475
|
+
cb(error);
|
|
2476
|
+
return;
|
|
2477
|
+
}
|
|
2478
|
+
this._fin = (buf[0] & 128) === 128;
|
|
2479
|
+
this._opcode = buf[0] & 15;
|
|
2480
|
+
this._payloadLength = buf[1] & 127;
|
|
2481
|
+
if (this._opcode === 0) {
|
|
2482
|
+
if (compressed) {
|
|
2483
|
+
const error = this.createError(
|
|
2484
|
+
RangeError,
|
|
2485
|
+
"RSV1 must be clear",
|
|
2486
|
+
true,
|
|
2487
|
+
1002,
|
|
2488
|
+
"WS_ERR_UNEXPECTED_RSV_1"
|
|
2489
|
+
);
|
|
2490
|
+
cb(error);
|
|
2491
|
+
return;
|
|
2492
|
+
}
|
|
2493
|
+
if (!this._fragmented) {
|
|
2494
|
+
const error = this.createError(
|
|
2495
|
+
RangeError,
|
|
2496
|
+
"invalid opcode 0",
|
|
2497
|
+
true,
|
|
2498
|
+
1002,
|
|
2499
|
+
"WS_ERR_INVALID_OPCODE"
|
|
2500
|
+
);
|
|
2501
|
+
cb(error);
|
|
2502
|
+
return;
|
|
2503
|
+
}
|
|
2504
|
+
this._opcode = this._fragmented;
|
|
2505
|
+
} else if (this._opcode === 1 || this._opcode === 2) {
|
|
2506
|
+
if (this._fragmented) {
|
|
2507
|
+
const error = this.createError(
|
|
2508
|
+
RangeError,
|
|
2509
|
+
`invalid opcode ${this._opcode}`,
|
|
2510
|
+
true,
|
|
2511
|
+
1002,
|
|
2512
|
+
"WS_ERR_INVALID_OPCODE"
|
|
2513
|
+
);
|
|
2514
|
+
cb(error);
|
|
2515
|
+
return;
|
|
2516
|
+
}
|
|
2517
|
+
this._compressed = compressed;
|
|
2518
|
+
} else if (this._opcode > 7 && this._opcode < 11) {
|
|
2519
|
+
if (!this._fin) {
|
|
2520
|
+
const error = this.createError(
|
|
2521
|
+
RangeError,
|
|
2522
|
+
"FIN must be set",
|
|
2523
|
+
true,
|
|
2524
|
+
1002,
|
|
2525
|
+
"WS_ERR_EXPECTED_FIN"
|
|
2526
|
+
);
|
|
2527
|
+
cb(error);
|
|
2528
|
+
return;
|
|
2529
|
+
}
|
|
2530
|
+
if (compressed) {
|
|
2531
|
+
const error = this.createError(
|
|
2532
|
+
RangeError,
|
|
2533
|
+
"RSV1 must be clear",
|
|
2534
|
+
true,
|
|
2535
|
+
1002,
|
|
2536
|
+
"WS_ERR_UNEXPECTED_RSV_1"
|
|
2537
|
+
);
|
|
2538
|
+
cb(error);
|
|
2539
|
+
return;
|
|
2540
|
+
}
|
|
2541
|
+
if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
|
|
2542
|
+
const error = this.createError(
|
|
2543
|
+
RangeError,
|
|
2544
|
+
`invalid payload length ${this._payloadLength}`,
|
|
2545
|
+
true,
|
|
2546
|
+
1002,
|
|
2547
|
+
"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
|
|
2548
|
+
);
|
|
2549
|
+
cb(error);
|
|
2550
|
+
return;
|
|
2551
|
+
}
|
|
2552
|
+
} else {
|
|
2553
|
+
const error = this.createError(
|
|
2554
|
+
RangeError,
|
|
2555
|
+
`invalid opcode ${this._opcode}`,
|
|
2556
|
+
true,
|
|
2557
|
+
1002,
|
|
2558
|
+
"WS_ERR_INVALID_OPCODE"
|
|
2559
|
+
);
|
|
2560
|
+
cb(error);
|
|
2561
|
+
return;
|
|
2562
|
+
}
|
|
2563
|
+
if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
|
|
2564
|
+
this._masked = (buf[1] & 128) === 128;
|
|
2565
|
+
if (this._isServer) {
|
|
2566
|
+
if (!this._masked) {
|
|
2567
|
+
const error = this.createError(
|
|
2568
|
+
RangeError,
|
|
2569
|
+
"MASK must be set",
|
|
2570
|
+
true,
|
|
2571
|
+
1002,
|
|
2572
|
+
"WS_ERR_EXPECTED_MASK"
|
|
2573
|
+
);
|
|
2574
|
+
cb(error);
|
|
2575
|
+
return;
|
|
2576
|
+
}
|
|
2577
|
+
} else if (this._masked) {
|
|
2578
|
+
const error = this.createError(
|
|
2579
|
+
RangeError,
|
|
2580
|
+
"MASK must be clear",
|
|
2581
|
+
true,
|
|
2582
|
+
1002,
|
|
2583
|
+
"WS_ERR_UNEXPECTED_MASK"
|
|
2584
|
+
);
|
|
2585
|
+
cb(error);
|
|
2586
|
+
return;
|
|
2587
|
+
}
|
|
2588
|
+
if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
|
|
2589
|
+
else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
|
|
2590
|
+
else this.haveLength(cb);
|
|
2591
|
+
}
|
|
2592
|
+
/**
|
|
2593
|
+
* Gets extended payload length (7+16).
|
|
2594
|
+
*
|
|
2595
|
+
* @param {Function} cb Callback
|
|
2596
|
+
* @private
|
|
2597
|
+
*/
|
|
2598
|
+
getPayloadLength16(cb) {
|
|
2599
|
+
if (this._bufferedBytes < 2) {
|
|
2600
|
+
this._loop = false;
|
|
2601
|
+
return;
|
|
2602
|
+
}
|
|
2603
|
+
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
2604
|
+
this.haveLength(cb);
|
|
2605
|
+
}
|
|
2606
|
+
/**
|
|
2607
|
+
* Gets extended payload length (7+64).
|
|
2608
|
+
*
|
|
2609
|
+
* @param {Function} cb Callback
|
|
2610
|
+
* @private
|
|
2611
|
+
*/
|
|
2612
|
+
getPayloadLength64(cb) {
|
|
2613
|
+
if (this._bufferedBytes < 8) {
|
|
2614
|
+
this._loop = false;
|
|
2615
|
+
return;
|
|
2616
|
+
}
|
|
2617
|
+
const buf = this.consume(8);
|
|
2618
|
+
const num7 = buf.readUInt32BE(0);
|
|
2619
|
+
if (num7 > Math.pow(2, 53 - 32) - 1) {
|
|
2620
|
+
const error = this.createError(
|
|
2621
|
+
RangeError,
|
|
2622
|
+
"Unsupported WebSocket frame: payload length > 2^53 - 1",
|
|
2623
|
+
false,
|
|
2624
|
+
1009,
|
|
2625
|
+
"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
|
|
2626
|
+
);
|
|
2627
|
+
cb(error);
|
|
2628
|
+
return;
|
|
2629
|
+
}
|
|
2630
|
+
this._payloadLength = num7 * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
2631
|
+
this.haveLength(cb);
|
|
2632
|
+
}
|
|
2633
|
+
/**
|
|
2634
|
+
* Payload length has been read.
|
|
2635
|
+
*
|
|
2636
|
+
* @param {Function} cb Callback
|
|
2637
|
+
* @private
|
|
2638
|
+
*/
|
|
2639
|
+
haveLength(cb) {
|
|
2640
|
+
if (this._payloadLength && this._opcode < 8) {
|
|
2641
|
+
this._totalPayloadLength += this._payloadLength;
|
|
2642
|
+
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
|
2643
|
+
const error = this.createError(
|
|
2644
|
+
RangeError,
|
|
2645
|
+
"Max payload size exceeded",
|
|
2646
|
+
false,
|
|
2647
|
+
1009,
|
|
2648
|
+
"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
|
|
2649
|
+
);
|
|
2650
|
+
cb(error);
|
|
2651
|
+
return;
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
if (this._masked) this._state = GET_MASK;
|
|
2655
|
+
else this._state = GET_DATA;
|
|
2656
|
+
}
|
|
2657
|
+
/**
|
|
2658
|
+
* Reads mask bytes.
|
|
2659
|
+
*
|
|
2660
|
+
* @private
|
|
2661
|
+
*/
|
|
2662
|
+
getMask() {
|
|
2663
|
+
if (this._bufferedBytes < 4) {
|
|
2664
|
+
this._loop = false;
|
|
2665
|
+
return;
|
|
2666
|
+
}
|
|
2667
|
+
this._mask = this.consume(4);
|
|
2668
|
+
this._state = GET_DATA;
|
|
2669
|
+
}
|
|
2670
|
+
/**
|
|
2671
|
+
* Reads data bytes.
|
|
2672
|
+
*
|
|
2673
|
+
* @param {Function} cb Callback
|
|
2674
|
+
* @private
|
|
2675
|
+
*/
|
|
2676
|
+
getData(cb) {
|
|
2677
|
+
let data = EMPTY_BUFFER;
|
|
2678
|
+
if (this._payloadLength) {
|
|
2679
|
+
if (this._bufferedBytes < this._payloadLength) {
|
|
2680
|
+
this._loop = false;
|
|
2681
|
+
return;
|
|
2682
|
+
}
|
|
2683
|
+
data = this.consume(this._payloadLength);
|
|
2684
|
+
if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
|
|
2685
|
+
unmask(data, this._mask);
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
if (this._opcode > 7) {
|
|
2689
|
+
this.controlMessage(data, cb);
|
|
2690
|
+
return;
|
|
2691
|
+
}
|
|
2692
|
+
if (this._compressed) {
|
|
2693
|
+
this._state = INFLATING;
|
|
2694
|
+
this.decompress(data, cb);
|
|
2695
|
+
return;
|
|
2696
|
+
}
|
|
2697
|
+
if (data.length) {
|
|
2698
|
+
this._messageLength = this._totalPayloadLength;
|
|
2699
|
+
this._fragments.push(data);
|
|
2700
|
+
}
|
|
2701
|
+
this.dataMessage(cb);
|
|
2702
|
+
}
|
|
2703
|
+
/**
|
|
2704
|
+
* Decompresses data.
|
|
2705
|
+
*
|
|
2706
|
+
* @param {Buffer} data Compressed data
|
|
2707
|
+
* @param {Function} cb Callback
|
|
2708
|
+
* @private
|
|
2709
|
+
*/
|
|
2710
|
+
decompress(data, cb) {
|
|
2711
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
2712
|
+
perMessageDeflate.decompress(data, this._fin, (err, buf) => {
|
|
2713
|
+
if (err) return cb(err);
|
|
2714
|
+
if (buf.length) {
|
|
2715
|
+
this._messageLength += buf.length;
|
|
2716
|
+
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
|
2717
|
+
const error = this.createError(
|
|
2718
|
+
RangeError,
|
|
2719
|
+
"Max payload size exceeded",
|
|
2720
|
+
false,
|
|
2721
|
+
1009,
|
|
2722
|
+
"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
|
|
2723
|
+
);
|
|
2724
|
+
cb(error);
|
|
2725
|
+
return;
|
|
2726
|
+
}
|
|
2727
|
+
this._fragments.push(buf);
|
|
2728
|
+
}
|
|
2729
|
+
this.dataMessage(cb);
|
|
2730
|
+
if (this._state === GET_INFO) this.startLoop(cb);
|
|
2731
|
+
});
|
|
2732
|
+
}
|
|
2733
|
+
/**
|
|
2734
|
+
* Handles a data message.
|
|
2735
|
+
*
|
|
2736
|
+
* @param {Function} cb Callback
|
|
2737
|
+
* @private
|
|
2738
|
+
*/
|
|
2739
|
+
dataMessage(cb) {
|
|
2740
|
+
if (!this._fin) {
|
|
2741
|
+
this._state = GET_INFO;
|
|
2742
|
+
return;
|
|
2743
|
+
}
|
|
2744
|
+
const messageLength = this._messageLength;
|
|
2745
|
+
const fragments = this._fragments;
|
|
2746
|
+
this._totalPayloadLength = 0;
|
|
2747
|
+
this._messageLength = 0;
|
|
2748
|
+
this._fragmented = 0;
|
|
2749
|
+
this._fragments = [];
|
|
2750
|
+
if (this._opcode === 2) {
|
|
2751
|
+
let data;
|
|
2752
|
+
if (this._binaryType === "nodebuffer") {
|
|
2753
|
+
data = concat(fragments, messageLength);
|
|
2754
|
+
} else if (this._binaryType === "arraybuffer") {
|
|
2755
|
+
data = toArrayBuffer(concat(fragments, messageLength));
|
|
2756
|
+
} else if (this._binaryType === "blob") {
|
|
2757
|
+
data = new Blob(fragments);
|
|
2758
|
+
} else {
|
|
2759
|
+
data = fragments;
|
|
2760
|
+
}
|
|
2761
|
+
if (this._allowSynchronousEvents) {
|
|
2762
|
+
this.emit("message", data, true);
|
|
2763
|
+
this._state = GET_INFO;
|
|
2764
|
+
} else {
|
|
2765
|
+
this._state = DEFER_EVENT;
|
|
2766
|
+
setImmediate(() => {
|
|
2767
|
+
this.emit("message", data, true);
|
|
2768
|
+
this._state = GET_INFO;
|
|
2769
|
+
this.startLoop(cb);
|
|
2770
|
+
});
|
|
2771
|
+
}
|
|
2772
|
+
} else {
|
|
2773
|
+
const buf = concat(fragments, messageLength);
|
|
2774
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
2775
|
+
const error = this.createError(
|
|
2776
|
+
Error,
|
|
2777
|
+
"invalid UTF-8 sequence",
|
|
2778
|
+
true,
|
|
2779
|
+
1007,
|
|
2780
|
+
"WS_ERR_INVALID_UTF8"
|
|
2781
|
+
);
|
|
2782
|
+
cb(error);
|
|
2783
|
+
return;
|
|
2784
|
+
}
|
|
2785
|
+
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
|
2786
|
+
this.emit("message", buf, false);
|
|
2787
|
+
this._state = GET_INFO;
|
|
2788
|
+
} else {
|
|
2789
|
+
this._state = DEFER_EVENT;
|
|
2790
|
+
setImmediate(() => {
|
|
2791
|
+
this.emit("message", buf, false);
|
|
2792
|
+
this._state = GET_INFO;
|
|
2793
|
+
this.startLoop(cb);
|
|
2794
|
+
});
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
/**
|
|
2799
|
+
* Handles a control message.
|
|
2800
|
+
*
|
|
2801
|
+
* @param {Buffer} data Data to handle
|
|
2802
|
+
* @return {(Error|RangeError|undefined)} A possible error
|
|
2803
|
+
* @private
|
|
2804
|
+
*/
|
|
2805
|
+
controlMessage(data, cb) {
|
|
2806
|
+
if (this._opcode === 8) {
|
|
2807
|
+
if (data.length === 0) {
|
|
2808
|
+
this._loop = false;
|
|
2809
|
+
this.emit("conclude", 1005, EMPTY_BUFFER);
|
|
2810
|
+
this.end();
|
|
2811
|
+
} else {
|
|
2812
|
+
const code = data.readUInt16BE(0);
|
|
2813
|
+
if (!isValidStatusCode(code)) {
|
|
2814
|
+
const error = this.createError(
|
|
2815
|
+
RangeError,
|
|
2816
|
+
`invalid status code ${code}`,
|
|
2817
|
+
true,
|
|
2818
|
+
1002,
|
|
2819
|
+
"WS_ERR_INVALID_CLOSE_CODE"
|
|
2820
|
+
);
|
|
2821
|
+
cb(error);
|
|
2822
|
+
return;
|
|
2823
|
+
}
|
|
2824
|
+
const buf = new FastBuffer(
|
|
2825
|
+
data.buffer,
|
|
2826
|
+
data.byteOffset + 2,
|
|
2827
|
+
data.length - 2
|
|
2828
|
+
);
|
|
2829
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
2830
|
+
const error = this.createError(
|
|
2831
|
+
Error,
|
|
2832
|
+
"invalid UTF-8 sequence",
|
|
2833
|
+
true,
|
|
2834
|
+
1007,
|
|
2835
|
+
"WS_ERR_INVALID_UTF8"
|
|
2836
|
+
);
|
|
2837
|
+
cb(error);
|
|
2838
|
+
return;
|
|
2839
|
+
}
|
|
2840
|
+
this._loop = false;
|
|
2841
|
+
this.emit("conclude", code, buf);
|
|
2842
|
+
this.end();
|
|
2843
|
+
}
|
|
2844
|
+
this._state = GET_INFO;
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2847
|
+
if (this._allowSynchronousEvents) {
|
|
2848
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
2849
|
+
this._state = GET_INFO;
|
|
2850
|
+
} else {
|
|
2851
|
+
this._state = DEFER_EVENT;
|
|
2852
|
+
setImmediate(() => {
|
|
2853
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
2854
|
+
this._state = GET_INFO;
|
|
2855
|
+
this.startLoop(cb);
|
|
2856
|
+
});
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
/**
|
|
2860
|
+
* Builds an error object.
|
|
2861
|
+
*
|
|
2862
|
+
* @param {function(new:Error|RangeError)} ErrorCtor The error constructor
|
|
2863
|
+
* @param {String} message The error message
|
|
2864
|
+
* @param {Boolean} prefix Specifies whether or not to add a default prefix to
|
|
2865
|
+
* `message`
|
|
2866
|
+
* @param {Number} statusCode The status code
|
|
2867
|
+
* @param {String} errorCode The exposed error code
|
|
2868
|
+
* @return {(Error|RangeError)} The error
|
|
2869
|
+
* @private
|
|
2870
|
+
*/
|
|
2871
|
+
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
2872
|
+
this._loop = false;
|
|
2873
|
+
this._errored = true;
|
|
2874
|
+
const err = new ErrorCtor(
|
|
2875
|
+
prefix ? `Invalid WebSocket frame: ${message}` : message
|
|
2876
|
+
);
|
|
2877
|
+
Error.captureStackTrace(err, this.createError);
|
|
2878
|
+
err.code = errorCode;
|
|
2879
|
+
err[kStatusCode] = statusCode;
|
|
2880
|
+
return err;
|
|
2881
|
+
}
|
|
2882
|
+
};
|
|
2883
|
+
module2.exports = Receiver2;
|
|
2884
|
+
}
|
|
2885
|
+
});
|
|
2886
|
+
|
|
2887
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/sender.js
|
|
2888
|
+
var require_sender = __commonJS({
|
|
2889
|
+
"node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/sender.js"(exports2, module2) {
|
|
2890
|
+
"use strict";
|
|
2891
|
+
var { Duplex } = require("stream");
|
|
2892
|
+
var { randomFillSync } = require("crypto");
|
|
2893
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
2894
|
+
var { EMPTY_BUFFER, kWebSocket, NOOP: NOOP2 } = require_constants();
|
|
2895
|
+
var { isBlob, isValidStatusCode } = require_validation();
|
|
2896
|
+
var { mask: applyMask, toBuffer } = require_buffer_util();
|
|
2897
|
+
var kByteLength = /* @__PURE__ */ Symbol("kByteLength");
|
|
2898
|
+
var maskBuffer = Buffer.alloc(4);
|
|
2899
|
+
var RANDOM_POOL_SIZE = 8 * 1024;
|
|
2900
|
+
var randomPool;
|
|
2901
|
+
var randomPoolPointer = RANDOM_POOL_SIZE;
|
|
2902
|
+
var DEFAULT = 0;
|
|
2903
|
+
var DEFLATING = 1;
|
|
2904
|
+
var GET_BLOB_DATA = 2;
|
|
2905
|
+
var Sender2 = class _Sender {
|
|
2906
|
+
/**
|
|
2907
|
+
* Creates a Sender instance.
|
|
2908
|
+
*
|
|
2909
|
+
* @param {Duplex} socket The connection socket
|
|
2910
|
+
* @param {Object} [extensions] An object containing the negotiated extensions
|
|
2911
|
+
* @param {Function} [generateMask] The function used to generate the masking
|
|
2912
|
+
* key
|
|
2913
|
+
*/
|
|
2914
|
+
constructor(socket, extensions, generateMask) {
|
|
2915
|
+
this._extensions = extensions || {};
|
|
2916
|
+
if (generateMask) {
|
|
2917
|
+
this._generateMask = generateMask;
|
|
2918
|
+
this._maskBuffer = Buffer.alloc(4);
|
|
2919
|
+
}
|
|
2920
|
+
this._socket = socket;
|
|
2921
|
+
this._firstFragment = true;
|
|
2922
|
+
this._compress = false;
|
|
2923
|
+
this._bufferedBytes = 0;
|
|
2924
|
+
this._queue = [];
|
|
2925
|
+
this._state = DEFAULT;
|
|
2926
|
+
this.onerror = NOOP2;
|
|
2927
|
+
this[kWebSocket] = void 0;
|
|
2928
|
+
}
|
|
2929
|
+
/**
|
|
2930
|
+
* Frames a piece of data according to the HyBi WebSocket protocol.
|
|
2931
|
+
*
|
|
2932
|
+
* @param {(Buffer|String)} data The data to frame
|
|
2933
|
+
* @param {Object} options Options object
|
|
2934
|
+
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
|
2935
|
+
* FIN bit
|
|
2936
|
+
* @param {Function} [options.generateMask] The function used to generate the
|
|
2937
|
+
* masking key
|
|
2938
|
+
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
2939
|
+
* `data`
|
|
2940
|
+
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
|
2941
|
+
* key
|
|
2942
|
+
* @param {Number} options.opcode The opcode
|
|
2943
|
+
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
|
2944
|
+
* modified
|
|
2945
|
+
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
|
2946
|
+
* RSV1 bit
|
|
2947
|
+
* @return {(Buffer|String)[]} The framed data
|
|
2948
|
+
* @public
|
|
2949
|
+
*/
|
|
2950
|
+
static frame(data, options) {
|
|
2951
|
+
let mask;
|
|
2952
|
+
let merge = false;
|
|
2953
|
+
let offset = 2;
|
|
2954
|
+
let skipMasking = false;
|
|
2955
|
+
if (options.mask) {
|
|
2956
|
+
mask = options.maskBuffer || maskBuffer;
|
|
2957
|
+
if (options.generateMask) {
|
|
2958
|
+
options.generateMask(mask);
|
|
2959
|
+
} else {
|
|
2960
|
+
if (randomPoolPointer === RANDOM_POOL_SIZE) {
|
|
2961
|
+
if (randomPool === void 0) {
|
|
2962
|
+
randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
|
|
2963
|
+
}
|
|
2964
|
+
randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
|
|
2965
|
+
randomPoolPointer = 0;
|
|
2966
|
+
}
|
|
2967
|
+
mask[0] = randomPool[randomPoolPointer++];
|
|
2968
|
+
mask[1] = randomPool[randomPoolPointer++];
|
|
2969
|
+
mask[2] = randomPool[randomPoolPointer++];
|
|
2970
|
+
mask[3] = randomPool[randomPoolPointer++];
|
|
2971
|
+
}
|
|
2972
|
+
skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
|
|
2973
|
+
offset = 6;
|
|
2974
|
+
}
|
|
2975
|
+
let dataLength;
|
|
2976
|
+
if (typeof data === "string") {
|
|
2977
|
+
if ((!options.mask || skipMasking) && options[kByteLength] !== void 0) {
|
|
2978
|
+
dataLength = options[kByteLength];
|
|
2979
|
+
} else {
|
|
2980
|
+
data = Buffer.from(data);
|
|
2981
|
+
dataLength = data.length;
|
|
2982
|
+
}
|
|
2983
|
+
} else {
|
|
2984
|
+
dataLength = data.length;
|
|
2985
|
+
merge = options.mask && options.readOnly && !skipMasking;
|
|
2986
|
+
}
|
|
2987
|
+
let payloadLength = dataLength;
|
|
2988
|
+
if (dataLength >= 65536) {
|
|
2989
|
+
offset += 8;
|
|
2990
|
+
payloadLength = 127;
|
|
2991
|
+
} else if (dataLength > 125) {
|
|
2992
|
+
offset += 2;
|
|
2993
|
+
payloadLength = 126;
|
|
2994
|
+
}
|
|
2995
|
+
const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
|
|
2996
|
+
target[0] = options.fin ? options.opcode | 128 : options.opcode;
|
|
2997
|
+
if (options.rsv1) target[0] |= 64;
|
|
2998
|
+
target[1] = payloadLength;
|
|
2999
|
+
if (payloadLength === 126) {
|
|
3000
|
+
target.writeUInt16BE(dataLength, 2);
|
|
3001
|
+
} else if (payloadLength === 127) {
|
|
3002
|
+
target[2] = target[3] = 0;
|
|
3003
|
+
target.writeUIntBE(dataLength, 4, 6);
|
|
3004
|
+
}
|
|
3005
|
+
if (!options.mask) return [target, data];
|
|
3006
|
+
target[1] |= 128;
|
|
3007
|
+
target[offset - 4] = mask[0];
|
|
3008
|
+
target[offset - 3] = mask[1];
|
|
3009
|
+
target[offset - 2] = mask[2];
|
|
3010
|
+
target[offset - 1] = mask[3];
|
|
3011
|
+
if (skipMasking) return [target, data];
|
|
3012
|
+
if (merge) {
|
|
3013
|
+
applyMask(data, mask, target, offset, dataLength);
|
|
3014
|
+
return [target];
|
|
3015
|
+
}
|
|
3016
|
+
applyMask(data, mask, data, 0, dataLength);
|
|
3017
|
+
return [target, data];
|
|
3018
|
+
}
|
|
3019
|
+
/**
|
|
3020
|
+
* Sends a close message to the other peer.
|
|
3021
|
+
*
|
|
3022
|
+
* @param {Number} [code] The status code component of the body
|
|
3023
|
+
* @param {(String|Buffer)} [data] The message component of the body
|
|
3024
|
+
* @param {Boolean} [mask=false] Specifies whether or not to mask the message
|
|
3025
|
+
* @param {Function} [cb] Callback
|
|
3026
|
+
* @public
|
|
3027
|
+
*/
|
|
3028
|
+
close(code, data, mask, cb) {
|
|
3029
|
+
let buf;
|
|
3030
|
+
if (code === void 0) {
|
|
3031
|
+
buf = EMPTY_BUFFER;
|
|
3032
|
+
} else if (typeof code !== "number" || !isValidStatusCode(code)) {
|
|
3033
|
+
throw new TypeError("First argument must be a valid error code number");
|
|
3034
|
+
} else if (data === void 0 || !data.length) {
|
|
3035
|
+
buf = Buffer.allocUnsafe(2);
|
|
3036
|
+
buf.writeUInt16BE(code, 0);
|
|
3037
|
+
} else {
|
|
3038
|
+
const length = Buffer.byteLength(data);
|
|
3039
|
+
if (length > 123) {
|
|
3040
|
+
throw new RangeError("The message must not be greater than 123 bytes");
|
|
3041
|
+
}
|
|
3042
|
+
buf = Buffer.allocUnsafe(2 + length);
|
|
3043
|
+
buf.writeUInt16BE(code, 0);
|
|
3044
|
+
if (typeof data === "string") {
|
|
3045
|
+
buf.write(data, 2);
|
|
3046
|
+
} else {
|
|
3047
|
+
buf.set(data, 2);
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
const options = {
|
|
3051
|
+
[kByteLength]: buf.length,
|
|
3052
|
+
fin: true,
|
|
3053
|
+
generateMask: this._generateMask,
|
|
3054
|
+
mask,
|
|
3055
|
+
maskBuffer: this._maskBuffer,
|
|
3056
|
+
opcode: 8,
|
|
3057
|
+
readOnly: false,
|
|
3058
|
+
rsv1: false
|
|
3059
|
+
};
|
|
3060
|
+
if (this._state !== DEFAULT) {
|
|
3061
|
+
this.enqueue([this.dispatch, buf, false, options, cb]);
|
|
3062
|
+
} else {
|
|
3063
|
+
this.sendFrame(_Sender.frame(buf, options), cb);
|
|
3064
|
+
}
|
|
3065
|
+
}
|
|
3066
|
+
/**
|
|
3067
|
+
* Sends a ping message to the other peer.
|
|
3068
|
+
*
|
|
3069
|
+
* @param {*} data The message to send
|
|
3070
|
+
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
|
|
3071
|
+
* @param {Function} [cb] Callback
|
|
3072
|
+
* @public
|
|
3073
|
+
*/
|
|
3074
|
+
ping(data, mask, cb) {
|
|
3075
|
+
let byteLength;
|
|
3076
|
+
let readOnly;
|
|
3077
|
+
if (typeof data === "string") {
|
|
3078
|
+
byteLength = Buffer.byteLength(data);
|
|
3079
|
+
readOnly = false;
|
|
3080
|
+
} else if (isBlob(data)) {
|
|
3081
|
+
byteLength = data.size;
|
|
3082
|
+
readOnly = false;
|
|
3083
|
+
} else {
|
|
3084
|
+
data = toBuffer(data);
|
|
3085
|
+
byteLength = data.length;
|
|
3086
|
+
readOnly = toBuffer.readOnly;
|
|
3087
|
+
}
|
|
3088
|
+
if (byteLength > 125) {
|
|
3089
|
+
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
3090
|
+
}
|
|
3091
|
+
const options = {
|
|
3092
|
+
[kByteLength]: byteLength,
|
|
3093
|
+
fin: true,
|
|
3094
|
+
generateMask: this._generateMask,
|
|
3095
|
+
mask,
|
|
3096
|
+
maskBuffer: this._maskBuffer,
|
|
3097
|
+
opcode: 9,
|
|
3098
|
+
readOnly,
|
|
3099
|
+
rsv1: false
|
|
3100
|
+
};
|
|
3101
|
+
if (isBlob(data)) {
|
|
3102
|
+
if (this._state !== DEFAULT) {
|
|
3103
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
3104
|
+
} else {
|
|
3105
|
+
this.getBlobData(data, false, options, cb);
|
|
3106
|
+
}
|
|
3107
|
+
} else if (this._state !== DEFAULT) {
|
|
3108
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
3109
|
+
} else {
|
|
3110
|
+
this.sendFrame(_Sender.frame(data, options), cb);
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
/**
|
|
3114
|
+
* Sends a pong message to the other peer.
|
|
3115
|
+
*
|
|
3116
|
+
* @param {*} data The message to send
|
|
3117
|
+
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
|
|
3118
|
+
* @param {Function} [cb] Callback
|
|
3119
|
+
* @public
|
|
3120
|
+
*/
|
|
3121
|
+
pong(data, mask, cb) {
|
|
3122
|
+
let byteLength;
|
|
3123
|
+
let readOnly;
|
|
3124
|
+
if (typeof data === "string") {
|
|
3125
|
+
byteLength = Buffer.byteLength(data);
|
|
3126
|
+
readOnly = false;
|
|
3127
|
+
} else if (isBlob(data)) {
|
|
3128
|
+
byteLength = data.size;
|
|
3129
|
+
readOnly = false;
|
|
3130
|
+
} else {
|
|
3131
|
+
data = toBuffer(data);
|
|
3132
|
+
byteLength = data.length;
|
|
3133
|
+
readOnly = toBuffer.readOnly;
|
|
3134
|
+
}
|
|
3135
|
+
if (byteLength > 125) {
|
|
3136
|
+
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
3137
|
+
}
|
|
3138
|
+
const options = {
|
|
3139
|
+
[kByteLength]: byteLength,
|
|
3140
|
+
fin: true,
|
|
3141
|
+
generateMask: this._generateMask,
|
|
3142
|
+
mask,
|
|
3143
|
+
maskBuffer: this._maskBuffer,
|
|
3144
|
+
opcode: 10,
|
|
3145
|
+
readOnly,
|
|
3146
|
+
rsv1: false
|
|
3147
|
+
};
|
|
3148
|
+
if (isBlob(data)) {
|
|
3149
|
+
if (this._state !== DEFAULT) {
|
|
3150
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
3151
|
+
} else {
|
|
3152
|
+
this.getBlobData(data, false, options, cb);
|
|
3153
|
+
}
|
|
3154
|
+
} else if (this._state !== DEFAULT) {
|
|
3155
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
3156
|
+
} else {
|
|
3157
|
+
this.sendFrame(_Sender.frame(data, options), cb);
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3160
|
+
/**
|
|
3161
|
+
* Sends a data message to the other peer.
|
|
3162
|
+
*
|
|
3163
|
+
* @param {*} data The message to send
|
|
3164
|
+
* @param {Object} options Options object
|
|
3165
|
+
* @param {Boolean} [options.binary=false] Specifies whether `data` is binary
|
|
3166
|
+
* or text
|
|
3167
|
+
* @param {Boolean} [options.compress=false] Specifies whether or not to
|
|
3168
|
+
* compress `data`
|
|
3169
|
+
* @param {Boolean} [options.fin=false] Specifies whether the fragment is the
|
|
3170
|
+
* last one
|
|
3171
|
+
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
3172
|
+
* `data`
|
|
3173
|
+
* @param {Function} [cb] Callback
|
|
3174
|
+
* @public
|
|
3175
|
+
*/
|
|
3176
|
+
send(data, options, cb) {
|
|
3177
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
3178
|
+
let opcode = options.binary ? 2 : 1;
|
|
3179
|
+
let rsv1 = options.compress;
|
|
3180
|
+
let byteLength;
|
|
3181
|
+
let readOnly;
|
|
3182
|
+
if (typeof data === "string") {
|
|
3183
|
+
byteLength = Buffer.byteLength(data);
|
|
3184
|
+
readOnly = false;
|
|
3185
|
+
} else if (isBlob(data)) {
|
|
3186
|
+
byteLength = data.size;
|
|
3187
|
+
readOnly = false;
|
|
3188
|
+
} else {
|
|
3189
|
+
data = toBuffer(data);
|
|
3190
|
+
byteLength = data.length;
|
|
3191
|
+
readOnly = toBuffer.readOnly;
|
|
3192
|
+
}
|
|
3193
|
+
if (this._firstFragment) {
|
|
3194
|
+
this._firstFragment = false;
|
|
3195
|
+
if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
|
|
3196
|
+
rsv1 = byteLength >= perMessageDeflate._threshold;
|
|
3197
|
+
}
|
|
3198
|
+
this._compress = rsv1;
|
|
3199
|
+
} else {
|
|
3200
|
+
rsv1 = false;
|
|
3201
|
+
opcode = 0;
|
|
3202
|
+
}
|
|
3203
|
+
if (options.fin) this._firstFragment = true;
|
|
3204
|
+
const opts = {
|
|
3205
|
+
[kByteLength]: byteLength,
|
|
3206
|
+
fin: options.fin,
|
|
3207
|
+
generateMask: this._generateMask,
|
|
3208
|
+
mask: options.mask,
|
|
3209
|
+
maskBuffer: this._maskBuffer,
|
|
3210
|
+
opcode,
|
|
3211
|
+
readOnly,
|
|
3212
|
+
rsv1
|
|
3213
|
+
};
|
|
3214
|
+
if (isBlob(data)) {
|
|
3215
|
+
if (this._state !== DEFAULT) {
|
|
3216
|
+
this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
|
|
3217
|
+
} else {
|
|
3218
|
+
this.getBlobData(data, this._compress, opts, cb);
|
|
3219
|
+
}
|
|
3220
|
+
} else if (this._state !== DEFAULT) {
|
|
3221
|
+
this.enqueue([this.dispatch, data, this._compress, opts, cb]);
|
|
3222
|
+
} else {
|
|
3223
|
+
this.dispatch(data, this._compress, opts, cb);
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
/**
|
|
3227
|
+
* Gets the contents of a blob as binary data.
|
|
3228
|
+
*
|
|
3229
|
+
* @param {Blob} blob The blob
|
|
3230
|
+
* @param {Boolean} [compress=false] Specifies whether or not to compress
|
|
3231
|
+
* the data
|
|
3232
|
+
* @param {Object} options Options object
|
|
3233
|
+
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
|
3234
|
+
* FIN bit
|
|
3235
|
+
* @param {Function} [options.generateMask] The function used to generate the
|
|
3236
|
+
* masking key
|
|
3237
|
+
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
3238
|
+
* `data`
|
|
3239
|
+
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
|
3240
|
+
* key
|
|
3241
|
+
* @param {Number} options.opcode The opcode
|
|
3242
|
+
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
|
3243
|
+
* modified
|
|
3244
|
+
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
|
3245
|
+
* RSV1 bit
|
|
3246
|
+
* @param {Function} [cb] Callback
|
|
3247
|
+
* @private
|
|
3248
|
+
*/
|
|
3249
|
+
getBlobData(blob, compress, options, cb) {
|
|
3250
|
+
this._bufferedBytes += options[kByteLength];
|
|
3251
|
+
this._state = GET_BLOB_DATA;
|
|
3252
|
+
blob.arrayBuffer().then((arrayBuffer) => {
|
|
3253
|
+
if (this._socket.destroyed) {
|
|
3254
|
+
const err = new Error(
|
|
3255
|
+
"The socket was closed while the blob was being read"
|
|
3256
|
+
);
|
|
3257
|
+
process.nextTick(callCallbacks, this, err, cb);
|
|
3258
|
+
return;
|
|
3259
|
+
}
|
|
3260
|
+
this._bufferedBytes -= options[kByteLength];
|
|
3261
|
+
const data = toBuffer(arrayBuffer);
|
|
3262
|
+
if (!compress) {
|
|
3263
|
+
this._state = DEFAULT;
|
|
3264
|
+
this.sendFrame(_Sender.frame(data, options), cb);
|
|
3265
|
+
this.dequeue();
|
|
3266
|
+
} else {
|
|
3267
|
+
this.dispatch(data, compress, options, cb);
|
|
3268
|
+
}
|
|
3269
|
+
}).catch((err) => {
|
|
3270
|
+
process.nextTick(onError, this, err, cb);
|
|
3271
|
+
});
|
|
3272
|
+
}
|
|
3273
|
+
/**
|
|
3274
|
+
* Dispatches a message.
|
|
3275
|
+
*
|
|
3276
|
+
* @param {(Buffer|String)} data The message to send
|
|
3277
|
+
* @param {Boolean} [compress=false] Specifies whether or not to compress
|
|
3278
|
+
* `data`
|
|
3279
|
+
* @param {Object} options Options object
|
|
3280
|
+
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
|
3281
|
+
* FIN bit
|
|
3282
|
+
* @param {Function} [options.generateMask] The function used to generate the
|
|
3283
|
+
* masking key
|
|
3284
|
+
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
3285
|
+
* `data`
|
|
3286
|
+
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
|
3287
|
+
* key
|
|
3288
|
+
* @param {Number} options.opcode The opcode
|
|
3289
|
+
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
|
3290
|
+
* modified
|
|
3291
|
+
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
|
3292
|
+
* RSV1 bit
|
|
3293
|
+
* @param {Function} [cb] Callback
|
|
3294
|
+
* @private
|
|
3295
|
+
*/
|
|
3296
|
+
dispatch(data, compress, options, cb) {
|
|
3297
|
+
if (!compress) {
|
|
3298
|
+
this.sendFrame(_Sender.frame(data, options), cb);
|
|
3299
|
+
return;
|
|
3300
|
+
}
|
|
3301
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
3302
|
+
this._bufferedBytes += options[kByteLength];
|
|
3303
|
+
this._state = DEFLATING;
|
|
3304
|
+
perMessageDeflate.compress(data, options.fin, (_5, buf) => {
|
|
3305
|
+
if (this._socket.destroyed) {
|
|
3306
|
+
const err = new Error(
|
|
3307
|
+
"The socket was closed while data was being compressed"
|
|
3308
|
+
);
|
|
3309
|
+
callCallbacks(this, err, cb);
|
|
3310
|
+
return;
|
|
3311
|
+
}
|
|
3312
|
+
this._bufferedBytes -= options[kByteLength];
|
|
3313
|
+
this._state = DEFAULT;
|
|
3314
|
+
options.readOnly = false;
|
|
3315
|
+
this.sendFrame(_Sender.frame(buf, options), cb);
|
|
3316
|
+
this.dequeue();
|
|
3317
|
+
});
|
|
3318
|
+
}
|
|
3319
|
+
/**
|
|
3320
|
+
* Executes queued send operations.
|
|
3321
|
+
*
|
|
3322
|
+
* @private
|
|
3323
|
+
*/
|
|
3324
|
+
dequeue() {
|
|
3325
|
+
while (this._state === DEFAULT && this._queue.length) {
|
|
3326
|
+
const params = this._queue.shift();
|
|
3327
|
+
this._bufferedBytes -= params[3][kByteLength];
|
|
3328
|
+
Reflect.apply(params[0], this, params.slice(1));
|
|
3329
|
+
}
|
|
3330
|
+
}
|
|
3331
|
+
/**
|
|
3332
|
+
* Enqueues a send operation.
|
|
3333
|
+
*
|
|
3334
|
+
* @param {Array} params Send operation parameters.
|
|
3335
|
+
* @private
|
|
3336
|
+
*/
|
|
3337
|
+
enqueue(params) {
|
|
3338
|
+
this._bufferedBytes += params[3][kByteLength];
|
|
3339
|
+
this._queue.push(params);
|
|
3340
|
+
}
|
|
3341
|
+
/**
|
|
3342
|
+
* Sends a frame.
|
|
3343
|
+
*
|
|
3344
|
+
* @param {(Buffer | String)[]} list The frame to send
|
|
3345
|
+
* @param {Function} [cb] Callback
|
|
3346
|
+
* @private
|
|
3347
|
+
*/
|
|
3348
|
+
sendFrame(list2, cb) {
|
|
3349
|
+
if (list2.length === 2) {
|
|
3350
|
+
this._socket.cork();
|
|
3351
|
+
this._socket.write(list2[0]);
|
|
3352
|
+
this._socket.write(list2[1], cb);
|
|
3353
|
+
this._socket.uncork();
|
|
3354
|
+
} else {
|
|
3355
|
+
this._socket.write(list2[0], cb);
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
};
|
|
3359
|
+
module2.exports = Sender2;
|
|
3360
|
+
function callCallbacks(sender, err, cb) {
|
|
3361
|
+
if (typeof cb === "function") cb(err);
|
|
3362
|
+
for (let i6 = 0; i6 < sender._queue.length; i6++) {
|
|
3363
|
+
const params = sender._queue[i6];
|
|
3364
|
+
const callback = params[params.length - 1];
|
|
3365
|
+
if (typeof callback === "function") callback(err);
|
|
3366
|
+
}
|
|
3367
|
+
}
|
|
3368
|
+
function onError(sender, err, cb) {
|
|
3369
|
+
callCallbacks(sender, err, cb);
|
|
3370
|
+
sender.onerror(err);
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
});
|
|
3374
|
+
|
|
3375
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/event-target.js
|
|
3376
|
+
var require_event_target = __commonJS({
|
|
3377
|
+
"node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/event-target.js"(exports2, module2) {
|
|
3378
|
+
"use strict";
|
|
3379
|
+
var { kForOnEventAttribute, kListener } = require_constants();
|
|
3380
|
+
var kCode = /* @__PURE__ */ Symbol("kCode");
|
|
3381
|
+
var kData = /* @__PURE__ */ Symbol("kData");
|
|
3382
|
+
var kError = /* @__PURE__ */ Symbol("kError");
|
|
3383
|
+
var kMessage = /* @__PURE__ */ Symbol("kMessage");
|
|
3384
|
+
var kReason = /* @__PURE__ */ Symbol("kReason");
|
|
3385
|
+
var kTarget = /* @__PURE__ */ Symbol("kTarget");
|
|
3386
|
+
var kType = /* @__PURE__ */ Symbol("kType");
|
|
3387
|
+
var kWasClean = /* @__PURE__ */ Symbol("kWasClean");
|
|
3388
|
+
var Event = class {
|
|
3389
|
+
/**
|
|
3390
|
+
* Create a new `Event`.
|
|
3391
|
+
*
|
|
3392
|
+
* @param {String} type The name of the event
|
|
3393
|
+
* @throws {TypeError} If the `type` argument is not specified
|
|
3394
|
+
*/
|
|
3395
|
+
constructor(type) {
|
|
3396
|
+
this[kTarget] = null;
|
|
3397
|
+
this[kType] = type;
|
|
3398
|
+
}
|
|
3399
|
+
/**
|
|
3400
|
+
* @type {*}
|
|
3401
|
+
*/
|
|
3402
|
+
get target() {
|
|
3403
|
+
return this[kTarget];
|
|
3404
|
+
}
|
|
3405
|
+
/**
|
|
3406
|
+
* @type {String}
|
|
3407
|
+
*/
|
|
3408
|
+
get type() {
|
|
3409
|
+
return this[kType];
|
|
3410
|
+
}
|
|
3411
|
+
};
|
|
3412
|
+
Object.defineProperty(Event.prototype, "target", { enumerable: true });
|
|
3413
|
+
Object.defineProperty(Event.prototype, "type", { enumerable: true });
|
|
3414
|
+
var CloseEvent = class extends Event {
|
|
3415
|
+
/**
|
|
3416
|
+
* Create a new `CloseEvent`.
|
|
3417
|
+
*
|
|
3418
|
+
* @param {String} type The name of the event
|
|
3419
|
+
* @param {Object} [options] A dictionary object that allows for setting
|
|
3420
|
+
* attributes via object members of the same name
|
|
3421
|
+
* @param {Number} [options.code=0] The status code explaining why the
|
|
3422
|
+
* connection was closed
|
|
3423
|
+
* @param {String} [options.reason=''] A human-readable string explaining why
|
|
3424
|
+
* the connection was closed
|
|
3425
|
+
* @param {Boolean} [options.wasClean=false] Indicates whether or not the
|
|
3426
|
+
* connection was cleanly closed
|
|
3427
|
+
*/
|
|
3428
|
+
constructor(type, options = {}) {
|
|
3429
|
+
super(type);
|
|
3430
|
+
this[kCode] = options.code === void 0 ? 0 : options.code;
|
|
3431
|
+
this[kReason] = options.reason === void 0 ? "" : options.reason;
|
|
3432
|
+
this[kWasClean] = options.wasClean === void 0 ? false : options.wasClean;
|
|
3433
|
+
}
|
|
3434
|
+
/**
|
|
3435
|
+
* @type {Number}
|
|
3436
|
+
*/
|
|
3437
|
+
get code() {
|
|
3438
|
+
return this[kCode];
|
|
3439
|
+
}
|
|
3440
|
+
/**
|
|
3441
|
+
* @type {String}
|
|
3442
|
+
*/
|
|
3443
|
+
get reason() {
|
|
3444
|
+
return this[kReason];
|
|
3445
|
+
}
|
|
3446
|
+
/**
|
|
3447
|
+
* @type {Boolean}
|
|
3448
|
+
*/
|
|
3449
|
+
get wasClean() {
|
|
3450
|
+
return this[kWasClean];
|
|
3451
|
+
}
|
|
3452
|
+
};
|
|
3453
|
+
Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
|
|
3454
|
+
Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
|
|
3455
|
+
Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
|
|
3456
|
+
var ErrorEvent = class extends Event {
|
|
3457
|
+
/**
|
|
3458
|
+
* Create a new `ErrorEvent`.
|
|
3459
|
+
*
|
|
3460
|
+
* @param {String} type The name of the event
|
|
3461
|
+
* @param {Object} [options] A dictionary object that allows for setting
|
|
3462
|
+
* attributes via object members of the same name
|
|
3463
|
+
* @param {*} [options.error=null] The error that generated this event
|
|
3464
|
+
* @param {String} [options.message=''] The error message
|
|
3465
|
+
*/
|
|
3466
|
+
constructor(type, options = {}) {
|
|
3467
|
+
super(type);
|
|
3468
|
+
this[kError] = options.error === void 0 ? null : options.error;
|
|
3469
|
+
this[kMessage] = options.message === void 0 ? "" : options.message;
|
|
3470
|
+
}
|
|
3471
|
+
/**
|
|
3472
|
+
* @type {*}
|
|
3473
|
+
*/
|
|
3474
|
+
get error() {
|
|
3475
|
+
return this[kError];
|
|
3476
|
+
}
|
|
3477
|
+
/**
|
|
3478
|
+
* @type {String}
|
|
3479
|
+
*/
|
|
3480
|
+
get message() {
|
|
3481
|
+
return this[kMessage];
|
|
3482
|
+
}
|
|
3483
|
+
};
|
|
3484
|
+
Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
|
|
3485
|
+
Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
|
|
3486
|
+
var MessageEvent = class extends Event {
|
|
3487
|
+
/**
|
|
3488
|
+
* Create a new `MessageEvent`.
|
|
3489
|
+
*
|
|
3490
|
+
* @param {String} type The name of the event
|
|
3491
|
+
* @param {Object} [options] A dictionary object that allows for setting
|
|
3492
|
+
* attributes via object members of the same name
|
|
3493
|
+
* @param {*} [options.data=null] The message content
|
|
3494
|
+
*/
|
|
3495
|
+
constructor(type, options = {}) {
|
|
3496
|
+
super(type);
|
|
3497
|
+
this[kData] = options.data === void 0 ? null : options.data;
|
|
3498
|
+
}
|
|
3499
|
+
/**
|
|
3500
|
+
* @type {*}
|
|
3501
|
+
*/
|
|
3502
|
+
get data() {
|
|
3503
|
+
return this[kData];
|
|
3504
|
+
}
|
|
3505
|
+
};
|
|
3506
|
+
Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
|
|
3507
|
+
var EventTarget = {
|
|
3508
|
+
/**
|
|
3509
|
+
* Register an event listener.
|
|
3510
|
+
*
|
|
3511
|
+
* @param {String} type A string representing the event type to listen for
|
|
3512
|
+
* @param {(Function|Object)} handler The listener to add
|
|
3513
|
+
* @param {Object} [options] An options object specifies characteristics about
|
|
3514
|
+
* the event listener
|
|
3515
|
+
* @param {Boolean} [options.once=false] A `Boolean` indicating that the
|
|
3516
|
+
* listener should be invoked at most once after being added. If `true`,
|
|
3517
|
+
* the listener would be automatically removed when invoked.
|
|
3518
|
+
* @public
|
|
3519
|
+
*/
|
|
3520
|
+
addEventListener(type, handler4, options = {}) {
|
|
3521
|
+
for (const listener of this.listeners(type)) {
|
|
3522
|
+
if (!options[kForOnEventAttribute] && listener[kListener] === handler4 && !listener[kForOnEventAttribute]) {
|
|
3523
|
+
return;
|
|
3524
|
+
}
|
|
3525
|
+
}
|
|
3526
|
+
let wrapper;
|
|
3527
|
+
if (type === "message") {
|
|
3528
|
+
wrapper = function onMessage(data, isBinary) {
|
|
3529
|
+
const event = new MessageEvent("message", {
|
|
3530
|
+
data: isBinary ? data : data.toString()
|
|
3531
|
+
});
|
|
3532
|
+
event[kTarget] = this;
|
|
3533
|
+
callListener(handler4, this, event);
|
|
3534
|
+
};
|
|
3535
|
+
} else if (type === "close") {
|
|
3536
|
+
wrapper = function onClose(code, message) {
|
|
3537
|
+
const event = new CloseEvent("close", {
|
|
3538
|
+
code,
|
|
3539
|
+
reason: message.toString(),
|
|
3540
|
+
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
3541
|
+
});
|
|
3542
|
+
event[kTarget] = this;
|
|
3543
|
+
callListener(handler4, this, event);
|
|
3544
|
+
};
|
|
3545
|
+
} else if (type === "error") {
|
|
3546
|
+
wrapper = function onError(error) {
|
|
3547
|
+
const event = new ErrorEvent("error", {
|
|
3548
|
+
error,
|
|
3549
|
+
message: error.message
|
|
3550
|
+
});
|
|
3551
|
+
event[kTarget] = this;
|
|
3552
|
+
callListener(handler4, this, event);
|
|
3553
|
+
};
|
|
3554
|
+
} else if (type === "open") {
|
|
3555
|
+
wrapper = function onOpen() {
|
|
3556
|
+
const event = new Event("open");
|
|
3557
|
+
event[kTarget] = this;
|
|
3558
|
+
callListener(handler4, this, event);
|
|
3559
|
+
};
|
|
3560
|
+
} else {
|
|
3561
|
+
return;
|
|
3562
|
+
}
|
|
3563
|
+
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
|
|
3564
|
+
wrapper[kListener] = handler4;
|
|
3565
|
+
if (options.once) {
|
|
3566
|
+
this.once(type, wrapper);
|
|
3567
|
+
} else {
|
|
3568
|
+
this.on(type, wrapper);
|
|
3569
|
+
}
|
|
3570
|
+
},
|
|
3571
|
+
/**
|
|
3572
|
+
* Remove an event listener.
|
|
3573
|
+
*
|
|
3574
|
+
* @param {String} type A string representing the event type to remove
|
|
3575
|
+
* @param {(Function|Object)} handler The listener to remove
|
|
3576
|
+
* @public
|
|
3577
|
+
*/
|
|
3578
|
+
removeEventListener(type, handler4) {
|
|
3579
|
+
for (const listener of this.listeners(type)) {
|
|
3580
|
+
if (listener[kListener] === handler4 && !listener[kForOnEventAttribute]) {
|
|
3581
|
+
this.removeListener(type, listener);
|
|
3582
|
+
break;
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
};
|
|
3587
|
+
module2.exports = {
|
|
3588
|
+
CloseEvent,
|
|
3589
|
+
ErrorEvent,
|
|
3590
|
+
Event,
|
|
3591
|
+
EventTarget,
|
|
3592
|
+
MessageEvent
|
|
3593
|
+
};
|
|
3594
|
+
function callListener(listener, thisArg, event) {
|
|
3595
|
+
if (typeof listener === "object" && listener.handleEvent) {
|
|
3596
|
+
listener.handleEvent.call(listener, event);
|
|
3597
|
+
} else {
|
|
3598
|
+
listener.call(thisArg, event);
|
|
3599
|
+
}
|
|
3600
|
+
}
|
|
3601
|
+
}
|
|
3602
|
+
});
|
|
3603
|
+
|
|
3604
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/extension.js
|
|
3605
|
+
var require_extension = __commonJS({
|
|
3606
|
+
"node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/extension.js"(exports2, module2) {
|
|
3607
|
+
"use strict";
|
|
3608
|
+
var { tokenChars } = require_validation();
|
|
3609
|
+
function push2(dest, name, elem) {
|
|
3610
|
+
if (dest[name] === void 0) dest[name] = [elem];
|
|
3611
|
+
else dest[name].push(elem);
|
|
3612
|
+
}
|
|
3613
|
+
function parse5(header) {
|
|
3614
|
+
const offers = /* @__PURE__ */ Object.create(null);
|
|
3615
|
+
let params = /* @__PURE__ */ Object.create(null);
|
|
3616
|
+
let mustUnescape = false;
|
|
3617
|
+
let isEscaping = false;
|
|
3618
|
+
let inQuotes = false;
|
|
3619
|
+
let extensionName;
|
|
3620
|
+
let paramName;
|
|
3621
|
+
let start = -1;
|
|
3622
|
+
let code = -1;
|
|
3623
|
+
let end = -1;
|
|
3624
|
+
let i6 = 0;
|
|
3625
|
+
for (; i6 < header.length; i6++) {
|
|
3626
|
+
code = header.charCodeAt(i6);
|
|
3627
|
+
if (extensionName === void 0) {
|
|
3628
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
3629
|
+
if (start === -1) start = i6;
|
|
3630
|
+
} else if (i6 !== 0 && (code === 32 || code === 9)) {
|
|
3631
|
+
if (end === -1 && start !== -1) end = i6;
|
|
3632
|
+
} else if (code === 59 || code === 44) {
|
|
3633
|
+
if (start === -1) {
|
|
3634
|
+
throw new SyntaxError(`Unexpected character at index ${i6}`);
|
|
3635
|
+
}
|
|
3636
|
+
if (end === -1) end = i6;
|
|
3637
|
+
const name = header.slice(start, end);
|
|
3638
|
+
if (code === 44) {
|
|
3639
|
+
push2(offers, name, params);
|
|
3640
|
+
params = /* @__PURE__ */ Object.create(null);
|
|
3641
|
+
} else {
|
|
3642
|
+
extensionName = name;
|
|
3643
|
+
}
|
|
3644
|
+
start = end = -1;
|
|
3645
|
+
} else {
|
|
3646
|
+
throw new SyntaxError(`Unexpected character at index ${i6}`);
|
|
3647
|
+
}
|
|
3648
|
+
} else if (paramName === void 0) {
|
|
3649
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
3650
|
+
if (start === -1) start = i6;
|
|
3651
|
+
} else if (code === 32 || code === 9) {
|
|
3652
|
+
if (end === -1 && start !== -1) end = i6;
|
|
3653
|
+
} else if (code === 59 || code === 44) {
|
|
3654
|
+
if (start === -1) {
|
|
3655
|
+
throw new SyntaxError(`Unexpected character at index ${i6}`);
|
|
3656
|
+
}
|
|
3657
|
+
if (end === -1) end = i6;
|
|
3658
|
+
push2(params, header.slice(start, end), true);
|
|
3659
|
+
if (code === 44) {
|
|
3660
|
+
push2(offers, extensionName, params);
|
|
3661
|
+
params = /* @__PURE__ */ Object.create(null);
|
|
3662
|
+
extensionName = void 0;
|
|
3663
|
+
}
|
|
3664
|
+
start = end = -1;
|
|
3665
|
+
} else if (code === 61 && start !== -1 && end === -1) {
|
|
3666
|
+
paramName = header.slice(start, i6);
|
|
3667
|
+
start = end = -1;
|
|
3668
|
+
} else {
|
|
3669
|
+
throw new SyntaxError(`Unexpected character at index ${i6}`);
|
|
3670
|
+
}
|
|
3671
|
+
} else {
|
|
3672
|
+
if (isEscaping) {
|
|
3673
|
+
if (tokenChars[code] !== 1) {
|
|
3674
|
+
throw new SyntaxError(`Unexpected character at index ${i6}`);
|
|
3675
|
+
}
|
|
3676
|
+
if (start === -1) start = i6;
|
|
3677
|
+
else if (!mustUnescape) mustUnescape = true;
|
|
3678
|
+
isEscaping = false;
|
|
3679
|
+
} else if (inQuotes) {
|
|
3680
|
+
if (tokenChars[code] === 1) {
|
|
3681
|
+
if (start === -1) start = i6;
|
|
3682
|
+
} else if (code === 34 && start !== -1) {
|
|
3683
|
+
inQuotes = false;
|
|
3684
|
+
end = i6;
|
|
3685
|
+
} else if (code === 92) {
|
|
3686
|
+
isEscaping = true;
|
|
3687
|
+
} else {
|
|
3688
|
+
throw new SyntaxError(`Unexpected character at index ${i6}`);
|
|
3689
|
+
}
|
|
3690
|
+
} else if (code === 34 && header.charCodeAt(i6 - 1) === 61) {
|
|
3691
|
+
inQuotes = true;
|
|
3692
|
+
} else if (end === -1 && tokenChars[code] === 1) {
|
|
3693
|
+
if (start === -1) start = i6;
|
|
3694
|
+
} else if (start !== -1 && (code === 32 || code === 9)) {
|
|
3695
|
+
if (end === -1) end = i6;
|
|
3696
|
+
} else if (code === 59 || code === 44) {
|
|
3697
|
+
if (start === -1) {
|
|
3698
|
+
throw new SyntaxError(`Unexpected character at index ${i6}`);
|
|
3699
|
+
}
|
|
3700
|
+
if (end === -1) end = i6;
|
|
3701
|
+
let value = header.slice(start, end);
|
|
3702
|
+
if (mustUnescape) {
|
|
3703
|
+
value = value.replace(/\\/g, "");
|
|
3704
|
+
mustUnescape = false;
|
|
3705
|
+
}
|
|
3706
|
+
push2(params, paramName, value);
|
|
3707
|
+
if (code === 44) {
|
|
3708
|
+
push2(offers, extensionName, params);
|
|
3709
|
+
params = /* @__PURE__ */ Object.create(null);
|
|
3710
|
+
extensionName = void 0;
|
|
3711
|
+
}
|
|
3712
|
+
paramName = void 0;
|
|
3713
|
+
start = end = -1;
|
|
3714
|
+
} else {
|
|
3715
|
+
throw new SyntaxError(`Unexpected character at index ${i6}`);
|
|
3716
|
+
}
|
|
3717
|
+
}
|
|
3718
|
+
}
|
|
3719
|
+
if (start === -1 || inQuotes || code === 32 || code === 9) {
|
|
3720
|
+
throw new SyntaxError("Unexpected end of input");
|
|
3721
|
+
}
|
|
3722
|
+
if (end === -1) end = i6;
|
|
3723
|
+
const token = header.slice(start, end);
|
|
3724
|
+
if (extensionName === void 0) {
|
|
3725
|
+
push2(offers, token, params);
|
|
3726
|
+
} else {
|
|
3727
|
+
if (paramName === void 0) {
|
|
3728
|
+
push2(params, token, true);
|
|
3729
|
+
} else if (mustUnescape) {
|
|
3730
|
+
push2(params, paramName, token.replace(/\\/g, ""));
|
|
3731
|
+
} else {
|
|
3732
|
+
push2(params, paramName, token);
|
|
3733
|
+
}
|
|
3734
|
+
push2(offers, extensionName, params);
|
|
3735
|
+
}
|
|
3736
|
+
return offers;
|
|
3737
|
+
}
|
|
3738
|
+
function format(extensions) {
|
|
3739
|
+
return Object.keys(extensions).map((extension) => {
|
|
3740
|
+
let configurations = extensions[extension];
|
|
3741
|
+
if (!Array.isArray(configurations)) configurations = [configurations];
|
|
3742
|
+
return configurations.map((params) => {
|
|
3743
|
+
return [extension].concat(
|
|
3744
|
+
Object.keys(params).map((k5) => {
|
|
3745
|
+
let values = params[k5];
|
|
3746
|
+
if (!Array.isArray(values)) values = [values];
|
|
3747
|
+
return values.map((v6) => v6 === true ? k5 : `${k5}=${v6}`).join("; ");
|
|
3748
|
+
})
|
|
3749
|
+
).join("; ");
|
|
3750
|
+
}).join(", ");
|
|
3751
|
+
}).join(", ");
|
|
3752
|
+
}
|
|
3753
|
+
module2.exports = { format, parse: parse5 };
|
|
3754
|
+
}
|
|
3755
|
+
});
|
|
3756
|
+
|
|
3757
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket.js
|
|
3758
|
+
var require_websocket = __commonJS({
|
|
3759
|
+
"node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket.js"(exports2, module2) {
|
|
3760
|
+
"use strict";
|
|
3761
|
+
var EventEmitter = require("events");
|
|
3762
|
+
var https = require("https");
|
|
3763
|
+
var http2 = require("http");
|
|
3764
|
+
var net = require("net");
|
|
3765
|
+
var tls = require("tls");
|
|
3766
|
+
var { randomBytes, createHash: createHash2 } = require("crypto");
|
|
3767
|
+
var { Duplex, Readable } = require("stream");
|
|
3768
|
+
var { URL: URL2 } = require("url");
|
|
3769
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
3770
|
+
var Receiver2 = require_receiver();
|
|
3771
|
+
var Sender2 = require_sender();
|
|
3772
|
+
var { isBlob } = require_validation();
|
|
3773
|
+
var {
|
|
3774
|
+
BINARY_TYPES,
|
|
3775
|
+
EMPTY_BUFFER,
|
|
3776
|
+
GUID,
|
|
3777
|
+
kForOnEventAttribute,
|
|
3778
|
+
kListener,
|
|
3779
|
+
kStatusCode,
|
|
3780
|
+
kWebSocket,
|
|
3781
|
+
NOOP: NOOP2
|
|
3782
|
+
} = require_constants();
|
|
3783
|
+
var {
|
|
3784
|
+
EventTarget: { addEventListener, removeEventListener }
|
|
3785
|
+
} = require_event_target();
|
|
3786
|
+
var { format, parse: parse5 } = require_extension();
|
|
3787
|
+
var { toBuffer } = require_buffer_util();
|
|
3788
|
+
var closeTimeout = 30 * 1e3;
|
|
3789
|
+
var kAborted = /* @__PURE__ */ Symbol("kAborted");
|
|
3790
|
+
var protocolVersions = [8, 13];
|
|
3791
|
+
var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
|
|
3792
|
+
var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
3793
|
+
var WebSocket2 = class _WebSocket extends EventEmitter {
|
|
3794
|
+
/**
|
|
3795
|
+
* Create a new `WebSocket`.
|
|
3796
|
+
*
|
|
3797
|
+
* @param {(String|URL)} address The URL to which to connect
|
|
3798
|
+
* @param {(String|String[])} [protocols] The subprotocols
|
|
3799
|
+
* @param {Object} [options] Connection options
|
|
3800
|
+
*/
|
|
3801
|
+
constructor(address, protocols, options) {
|
|
3802
|
+
super();
|
|
3803
|
+
this._binaryType = BINARY_TYPES[0];
|
|
3804
|
+
this._closeCode = 1006;
|
|
3805
|
+
this._closeFrameReceived = false;
|
|
3806
|
+
this._closeFrameSent = false;
|
|
3807
|
+
this._closeMessage = EMPTY_BUFFER;
|
|
3808
|
+
this._closeTimer = null;
|
|
3809
|
+
this._errorEmitted = false;
|
|
3810
|
+
this._extensions = {};
|
|
3811
|
+
this._paused = false;
|
|
3812
|
+
this._protocol = "";
|
|
3813
|
+
this._readyState = _WebSocket.CONNECTING;
|
|
3814
|
+
this._receiver = null;
|
|
3815
|
+
this._sender = null;
|
|
3816
|
+
this._socket = null;
|
|
3817
|
+
if (address !== null) {
|
|
3818
|
+
this._bufferedAmount = 0;
|
|
3819
|
+
this._isServer = false;
|
|
3820
|
+
this._redirects = 0;
|
|
3821
|
+
if (protocols === void 0) {
|
|
3822
|
+
protocols = [];
|
|
3823
|
+
} else if (!Array.isArray(protocols)) {
|
|
3824
|
+
if (typeof protocols === "object" && protocols !== null) {
|
|
3825
|
+
options = protocols;
|
|
3826
|
+
protocols = [];
|
|
3827
|
+
} else {
|
|
3828
|
+
protocols = [protocols];
|
|
3829
|
+
}
|
|
3830
|
+
}
|
|
3831
|
+
initAsClient(this, address, protocols, options);
|
|
3832
|
+
} else {
|
|
3833
|
+
this._autoPong = options.autoPong;
|
|
3834
|
+
this._isServer = true;
|
|
3835
|
+
}
|
|
3836
|
+
}
|
|
3837
|
+
/**
|
|
3838
|
+
* For historical reasons, the custom "nodebuffer" type is used by the default
|
|
3839
|
+
* instead of "blob".
|
|
3840
|
+
*
|
|
3841
|
+
* @type {String}
|
|
3842
|
+
*/
|
|
3843
|
+
get binaryType() {
|
|
3844
|
+
return this._binaryType;
|
|
3845
|
+
}
|
|
3846
|
+
set binaryType(type) {
|
|
3847
|
+
if (!BINARY_TYPES.includes(type)) return;
|
|
3848
|
+
this._binaryType = type;
|
|
3849
|
+
if (this._receiver) this._receiver._binaryType = type;
|
|
3850
|
+
}
|
|
3851
|
+
/**
|
|
3852
|
+
* @type {Number}
|
|
3853
|
+
*/
|
|
3854
|
+
get bufferedAmount() {
|
|
3855
|
+
if (!this._socket) return this._bufferedAmount;
|
|
3856
|
+
return this._socket._writableState.length + this._sender._bufferedBytes;
|
|
3857
|
+
}
|
|
3858
|
+
/**
|
|
3859
|
+
* @type {String}
|
|
3860
|
+
*/
|
|
3861
|
+
get extensions() {
|
|
3862
|
+
return Object.keys(this._extensions).join();
|
|
3863
|
+
}
|
|
3864
|
+
/**
|
|
3865
|
+
* @type {Boolean}
|
|
3866
|
+
*/
|
|
3867
|
+
get isPaused() {
|
|
3868
|
+
return this._paused;
|
|
3869
|
+
}
|
|
3870
|
+
/**
|
|
3871
|
+
* @type {Function}
|
|
3872
|
+
*/
|
|
3873
|
+
/* istanbul ignore next */
|
|
3874
|
+
get onclose() {
|
|
3875
|
+
return null;
|
|
3876
|
+
}
|
|
3877
|
+
/**
|
|
3878
|
+
* @type {Function}
|
|
3879
|
+
*/
|
|
3880
|
+
/* istanbul ignore next */
|
|
3881
|
+
get onerror() {
|
|
3882
|
+
return null;
|
|
3883
|
+
}
|
|
3884
|
+
/**
|
|
3885
|
+
* @type {Function}
|
|
3886
|
+
*/
|
|
3887
|
+
/* istanbul ignore next */
|
|
3888
|
+
get onopen() {
|
|
3889
|
+
return null;
|
|
3890
|
+
}
|
|
3891
|
+
/**
|
|
3892
|
+
* @type {Function}
|
|
3893
|
+
*/
|
|
3894
|
+
/* istanbul ignore next */
|
|
3895
|
+
get onmessage() {
|
|
3896
|
+
return null;
|
|
3897
|
+
}
|
|
3898
|
+
/**
|
|
3899
|
+
* @type {String}
|
|
3900
|
+
*/
|
|
3901
|
+
get protocol() {
|
|
3902
|
+
return this._protocol;
|
|
3903
|
+
}
|
|
3904
|
+
/**
|
|
3905
|
+
* @type {Number}
|
|
3906
|
+
*/
|
|
3907
|
+
get readyState() {
|
|
3908
|
+
return this._readyState;
|
|
3909
|
+
}
|
|
3910
|
+
/**
|
|
3911
|
+
* @type {String}
|
|
3912
|
+
*/
|
|
3913
|
+
get url() {
|
|
3914
|
+
return this._url;
|
|
3915
|
+
}
|
|
3916
|
+
/**
|
|
3917
|
+
* Set up the socket and the internal resources.
|
|
3918
|
+
*
|
|
3919
|
+
* @param {Duplex} socket The network socket between the server and client
|
|
3920
|
+
* @param {Buffer} head The first packet of the upgraded stream
|
|
3921
|
+
* @param {Object} options Options object
|
|
3922
|
+
* @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
|
|
3923
|
+
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
3924
|
+
* multiple times in the same tick
|
|
3925
|
+
* @param {Function} [options.generateMask] The function used to generate the
|
|
3926
|
+
* masking key
|
|
3927
|
+
* @param {Number} [options.maxPayload=0] The maximum allowed message size
|
|
3928
|
+
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
3929
|
+
* not to skip UTF-8 validation for text and close messages
|
|
3930
|
+
* @private
|
|
3931
|
+
*/
|
|
3932
|
+
setSocket(socket, head, options) {
|
|
3933
|
+
const receiver = new Receiver2({
|
|
3934
|
+
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
3935
|
+
binaryType: this.binaryType,
|
|
3936
|
+
extensions: this._extensions,
|
|
3937
|
+
isServer: this._isServer,
|
|
3938
|
+
maxPayload: options.maxPayload,
|
|
3939
|
+
skipUTF8Validation: options.skipUTF8Validation
|
|
3940
|
+
});
|
|
3941
|
+
const sender = new Sender2(socket, this._extensions, options.generateMask);
|
|
3942
|
+
this._receiver = receiver;
|
|
3943
|
+
this._sender = sender;
|
|
3944
|
+
this._socket = socket;
|
|
3945
|
+
receiver[kWebSocket] = this;
|
|
3946
|
+
sender[kWebSocket] = this;
|
|
3947
|
+
socket[kWebSocket] = this;
|
|
3948
|
+
receiver.on("conclude", receiverOnConclude);
|
|
3949
|
+
receiver.on("drain", receiverOnDrain);
|
|
3950
|
+
receiver.on("error", receiverOnError);
|
|
3951
|
+
receiver.on("message", receiverOnMessage);
|
|
3952
|
+
receiver.on("ping", receiverOnPing);
|
|
3953
|
+
receiver.on("pong", receiverOnPong);
|
|
3954
|
+
sender.onerror = senderOnError;
|
|
3955
|
+
if (socket.setTimeout) socket.setTimeout(0);
|
|
3956
|
+
if (socket.setNoDelay) socket.setNoDelay();
|
|
3957
|
+
if (head.length > 0) socket.unshift(head);
|
|
3958
|
+
socket.on("close", socketOnClose);
|
|
3959
|
+
socket.on("data", socketOnData);
|
|
3960
|
+
socket.on("end", socketOnEnd);
|
|
3961
|
+
socket.on("error", socketOnError);
|
|
3962
|
+
this._readyState = _WebSocket.OPEN;
|
|
3963
|
+
this.emit("open");
|
|
3964
|
+
}
|
|
3965
|
+
/**
|
|
3966
|
+
* Emit the `'close'` event.
|
|
3967
|
+
*
|
|
3968
|
+
* @private
|
|
3969
|
+
*/
|
|
3970
|
+
emitClose() {
|
|
3971
|
+
if (!this._socket) {
|
|
3972
|
+
this._readyState = _WebSocket.CLOSED;
|
|
3973
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
3974
|
+
return;
|
|
3975
|
+
}
|
|
3976
|
+
if (this._extensions[PerMessageDeflate.extensionName]) {
|
|
3977
|
+
this._extensions[PerMessageDeflate.extensionName].cleanup();
|
|
3978
|
+
}
|
|
3979
|
+
this._receiver.removeAllListeners();
|
|
3980
|
+
this._readyState = _WebSocket.CLOSED;
|
|
3981
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
3982
|
+
}
|
|
3983
|
+
/**
|
|
3984
|
+
* Start a closing handshake.
|
|
3985
|
+
*
|
|
3986
|
+
* +----------+ +-----------+ +----------+
|
|
3987
|
+
* - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
|
|
3988
|
+
* | +----------+ +-----------+ +----------+ |
|
|
3989
|
+
* +----------+ +-----------+ |
|
|
3990
|
+
* CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
|
|
3991
|
+
* +----------+ +-----------+ |
|
|
3992
|
+
* | | | +---+ |
|
|
3993
|
+
* +------------------------+-->|fin| - - - -
|
|
3994
|
+
* | +---+ | +---+
|
|
3995
|
+
* - - - - -|fin|<---------------------+
|
|
3996
|
+
* +---+
|
|
3997
|
+
*
|
|
3998
|
+
* @param {Number} [code] Status code explaining why the connection is closing
|
|
3999
|
+
* @param {(String|Buffer)} [data] The reason why the connection is
|
|
4000
|
+
* closing
|
|
4001
|
+
* @public
|
|
4002
|
+
*/
|
|
4003
|
+
close(code, data) {
|
|
4004
|
+
if (this.readyState === _WebSocket.CLOSED) return;
|
|
4005
|
+
if (this.readyState === _WebSocket.CONNECTING) {
|
|
4006
|
+
const msg = "WebSocket was closed before the connection was established";
|
|
4007
|
+
abortHandshake(this, this._req, msg);
|
|
4008
|
+
return;
|
|
4009
|
+
}
|
|
4010
|
+
if (this.readyState === _WebSocket.CLOSING) {
|
|
4011
|
+
if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
|
|
4012
|
+
this._socket.end();
|
|
4013
|
+
}
|
|
4014
|
+
return;
|
|
4015
|
+
}
|
|
4016
|
+
this._readyState = _WebSocket.CLOSING;
|
|
4017
|
+
this._sender.close(code, data, !this._isServer, (err) => {
|
|
4018
|
+
if (err) return;
|
|
4019
|
+
this._closeFrameSent = true;
|
|
4020
|
+
if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
|
|
4021
|
+
this._socket.end();
|
|
4022
|
+
}
|
|
4023
|
+
});
|
|
4024
|
+
setCloseTimer(this);
|
|
4025
|
+
}
|
|
4026
|
+
/**
|
|
4027
|
+
* Pause the socket.
|
|
4028
|
+
*
|
|
4029
|
+
* @public
|
|
4030
|
+
*/
|
|
4031
|
+
pause() {
|
|
4032
|
+
if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
|
|
4033
|
+
return;
|
|
4034
|
+
}
|
|
4035
|
+
this._paused = true;
|
|
4036
|
+
this._socket.pause();
|
|
4037
|
+
}
|
|
4038
|
+
/**
|
|
4039
|
+
* Send a ping.
|
|
4040
|
+
*
|
|
4041
|
+
* @param {*} [data] The data to send
|
|
4042
|
+
* @param {Boolean} [mask] Indicates whether or not to mask `data`
|
|
4043
|
+
* @param {Function} [cb] Callback which is executed when the ping is sent
|
|
4044
|
+
* @public
|
|
4045
|
+
*/
|
|
4046
|
+
ping(data, mask, cb) {
|
|
4047
|
+
if (this.readyState === _WebSocket.CONNECTING) {
|
|
4048
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
4049
|
+
}
|
|
4050
|
+
if (typeof data === "function") {
|
|
4051
|
+
cb = data;
|
|
4052
|
+
data = mask = void 0;
|
|
4053
|
+
} else if (typeof mask === "function") {
|
|
4054
|
+
cb = mask;
|
|
4055
|
+
mask = void 0;
|
|
4056
|
+
}
|
|
4057
|
+
if (typeof data === "number") data = data.toString();
|
|
4058
|
+
if (this.readyState !== _WebSocket.OPEN) {
|
|
4059
|
+
sendAfterClose(this, data, cb);
|
|
4060
|
+
return;
|
|
4061
|
+
}
|
|
4062
|
+
if (mask === void 0) mask = !this._isServer;
|
|
4063
|
+
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
|
4064
|
+
}
|
|
4065
|
+
/**
|
|
4066
|
+
* Send a pong.
|
|
4067
|
+
*
|
|
4068
|
+
* @param {*} [data] The data to send
|
|
4069
|
+
* @param {Boolean} [mask] Indicates whether or not to mask `data`
|
|
4070
|
+
* @param {Function} [cb] Callback which is executed when the pong is sent
|
|
4071
|
+
* @public
|
|
4072
|
+
*/
|
|
4073
|
+
pong(data, mask, cb) {
|
|
4074
|
+
if (this.readyState === _WebSocket.CONNECTING) {
|
|
4075
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
4076
|
+
}
|
|
4077
|
+
if (typeof data === "function") {
|
|
4078
|
+
cb = data;
|
|
4079
|
+
data = mask = void 0;
|
|
4080
|
+
} else if (typeof mask === "function") {
|
|
4081
|
+
cb = mask;
|
|
4082
|
+
mask = void 0;
|
|
4083
|
+
}
|
|
4084
|
+
if (typeof data === "number") data = data.toString();
|
|
4085
|
+
if (this.readyState !== _WebSocket.OPEN) {
|
|
4086
|
+
sendAfterClose(this, data, cb);
|
|
4087
|
+
return;
|
|
4088
|
+
}
|
|
4089
|
+
if (mask === void 0) mask = !this._isServer;
|
|
4090
|
+
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
|
4091
|
+
}
|
|
4092
|
+
/**
|
|
4093
|
+
* Resume the socket.
|
|
4094
|
+
*
|
|
4095
|
+
* @public
|
|
4096
|
+
*/
|
|
4097
|
+
resume() {
|
|
4098
|
+
if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
|
|
4099
|
+
return;
|
|
4100
|
+
}
|
|
4101
|
+
this._paused = false;
|
|
4102
|
+
if (!this._receiver._writableState.needDrain) this._socket.resume();
|
|
4103
|
+
}
|
|
4104
|
+
/**
|
|
4105
|
+
* Send a data message.
|
|
4106
|
+
*
|
|
4107
|
+
* @param {*} data The message to send
|
|
4108
|
+
* @param {Object} [options] Options object
|
|
4109
|
+
* @param {Boolean} [options.binary] Specifies whether `data` is binary or
|
|
4110
|
+
* text
|
|
4111
|
+
* @param {Boolean} [options.compress] Specifies whether or not to compress
|
|
4112
|
+
* `data`
|
|
4113
|
+
* @param {Boolean} [options.fin=true] Specifies whether the fragment is the
|
|
4114
|
+
* last one
|
|
4115
|
+
* @param {Boolean} [options.mask] Specifies whether or not to mask `data`
|
|
4116
|
+
* @param {Function} [cb] Callback which is executed when data is written out
|
|
4117
|
+
* @public
|
|
4118
|
+
*/
|
|
4119
|
+
send(data, options, cb) {
|
|
4120
|
+
if (this.readyState === _WebSocket.CONNECTING) {
|
|
4121
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
4122
|
+
}
|
|
4123
|
+
if (typeof options === "function") {
|
|
4124
|
+
cb = options;
|
|
4125
|
+
options = {};
|
|
4126
|
+
}
|
|
4127
|
+
if (typeof data === "number") data = data.toString();
|
|
4128
|
+
if (this.readyState !== _WebSocket.OPEN) {
|
|
4129
|
+
sendAfterClose(this, data, cb);
|
|
4130
|
+
return;
|
|
4131
|
+
}
|
|
4132
|
+
const opts = {
|
|
4133
|
+
binary: typeof data !== "string",
|
|
4134
|
+
mask: !this._isServer,
|
|
4135
|
+
compress: true,
|
|
4136
|
+
fin: true,
|
|
4137
|
+
...options
|
|
4138
|
+
};
|
|
4139
|
+
if (!this._extensions[PerMessageDeflate.extensionName]) {
|
|
4140
|
+
opts.compress = false;
|
|
4141
|
+
}
|
|
4142
|
+
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
4143
|
+
}
|
|
4144
|
+
/**
|
|
4145
|
+
* Forcibly close the connection.
|
|
4146
|
+
*
|
|
4147
|
+
* @public
|
|
4148
|
+
*/
|
|
4149
|
+
terminate() {
|
|
4150
|
+
if (this.readyState === _WebSocket.CLOSED) return;
|
|
4151
|
+
if (this.readyState === _WebSocket.CONNECTING) {
|
|
4152
|
+
const msg = "WebSocket was closed before the connection was established";
|
|
4153
|
+
abortHandshake(this, this._req, msg);
|
|
4154
|
+
return;
|
|
4155
|
+
}
|
|
4156
|
+
if (this._socket) {
|
|
4157
|
+
this._readyState = _WebSocket.CLOSING;
|
|
4158
|
+
this._socket.destroy();
|
|
4159
|
+
}
|
|
4160
|
+
}
|
|
4161
|
+
};
|
|
4162
|
+
Object.defineProperty(WebSocket2, "CONNECTING", {
|
|
4163
|
+
enumerable: true,
|
|
4164
|
+
value: readyStates.indexOf("CONNECTING")
|
|
4165
|
+
});
|
|
4166
|
+
Object.defineProperty(WebSocket2.prototype, "CONNECTING", {
|
|
4167
|
+
enumerable: true,
|
|
4168
|
+
value: readyStates.indexOf("CONNECTING")
|
|
4169
|
+
});
|
|
4170
|
+
Object.defineProperty(WebSocket2, "OPEN", {
|
|
4171
|
+
enumerable: true,
|
|
4172
|
+
value: readyStates.indexOf("OPEN")
|
|
4173
|
+
});
|
|
4174
|
+
Object.defineProperty(WebSocket2.prototype, "OPEN", {
|
|
4175
|
+
enumerable: true,
|
|
4176
|
+
value: readyStates.indexOf("OPEN")
|
|
4177
|
+
});
|
|
4178
|
+
Object.defineProperty(WebSocket2, "CLOSING", {
|
|
4179
|
+
enumerable: true,
|
|
4180
|
+
value: readyStates.indexOf("CLOSING")
|
|
4181
|
+
});
|
|
4182
|
+
Object.defineProperty(WebSocket2.prototype, "CLOSING", {
|
|
4183
|
+
enumerable: true,
|
|
4184
|
+
value: readyStates.indexOf("CLOSING")
|
|
4185
|
+
});
|
|
4186
|
+
Object.defineProperty(WebSocket2, "CLOSED", {
|
|
4187
|
+
enumerable: true,
|
|
4188
|
+
value: readyStates.indexOf("CLOSED")
|
|
4189
|
+
});
|
|
4190
|
+
Object.defineProperty(WebSocket2.prototype, "CLOSED", {
|
|
4191
|
+
enumerable: true,
|
|
4192
|
+
value: readyStates.indexOf("CLOSED")
|
|
4193
|
+
});
|
|
4194
|
+
[
|
|
4195
|
+
"binaryType",
|
|
4196
|
+
"bufferedAmount",
|
|
4197
|
+
"extensions",
|
|
4198
|
+
"isPaused",
|
|
4199
|
+
"protocol",
|
|
4200
|
+
"readyState",
|
|
4201
|
+
"url"
|
|
4202
|
+
].forEach((property2) => {
|
|
4203
|
+
Object.defineProperty(WebSocket2.prototype, property2, { enumerable: true });
|
|
4204
|
+
});
|
|
4205
|
+
["open", "error", "close", "message"].forEach((method) => {
|
|
4206
|
+
Object.defineProperty(WebSocket2.prototype, `on${method}`, {
|
|
4207
|
+
enumerable: true,
|
|
4208
|
+
get() {
|
|
4209
|
+
for (const listener of this.listeners(method)) {
|
|
4210
|
+
if (listener[kForOnEventAttribute]) return listener[kListener];
|
|
4211
|
+
}
|
|
4212
|
+
return null;
|
|
4213
|
+
},
|
|
4214
|
+
set(handler4) {
|
|
4215
|
+
for (const listener of this.listeners(method)) {
|
|
4216
|
+
if (listener[kForOnEventAttribute]) {
|
|
4217
|
+
this.removeListener(method, listener);
|
|
4218
|
+
break;
|
|
4219
|
+
}
|
|
4220
|
+
}
|
|
4221
|
+
if (typeof handler4 !== "function") return;
|
|
4222
|
+
this.addEventListener(method, handler4, {
|
|
4223
|
+
[kForOnEventAttribute]: true
|
|
4224
|
+
});
|
|
4225
|
+
}
|
|
4226
|
+
});
|
|
4227
|
+
});
|
|
4228
|
+
WebSocket2.prototype.addEventListener = addEventListener;
|
|
4229
|
+
WebSocket2.prototype.removeEventListener = removeEventListener;
|
|
4230
|
+
module2.exports = WebSocket2;
|
|
4231
|
+
function initAsClient(websocket, address, protocols, options) {
|
|
4232
|
+
const opts = {
|
|
4233
|
+
allowSynchronousEvents: true,
|
|
4234
|
+
autoPong: true,
|
|
4235
|
+
protocolVersion: protocolVersions[1],
|
|
4236
|
+
maxPayload: 100 * 1024 * 1024,
|
|
4237
|
+
skipUTF8Validation: false,
|
|
4238
|
+
perMessageDeflate: true,
|
|
4239
|
+
followRedirects: false,
|
|
4240
|
+
maxRedirects: 10,
|
|
4241
|
+
...options,
|
|
4242
|
+
socketPath: void 0,
|
|
4243
|
+
hostname: void 0,
|
|
4244
|
+
protocol: void 0,
|
|
4245
|
+
timeout: void 0,
|
|
4246
|
+
method: "GET",
|
|
4247
|
+
host: void 0,
|
|
4248
|
+
path: void 0,
|
|
4249
|
+
port: void 0
|
|
4250
|
+
};
|
|
4251
|
+
websocket._autoPong = opts.autoPong;
|
|
4252
|
+
if (!protocolVersions.includes(opts.protocolVersion)) {
|
|
4253
|
+
throw new RangeError(
|
|
4254
|
+
`Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`
|
|
4255
|
+
);
|
|
4256
|
+
}
|
|
4257
|
+
let parsedUrl;
|
|
4258
|
+
if (address instanceof URL2) {
|
|
4259
|
+
parsedUrl = address;
|
|
4260
|
+
} else {
|
|
4261
|
+
try {
|
|
4262
|
+
parsedUrl = new URL2(address);
|
|
4263
|
+
} catch (e5) {
|
|
4264
|
+
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
4265
|
+
}
|
|
4266
|
+
}
|
|
4267
|
+
if (parsedUrl.protocol === "http:") {
|
|
4268
|
+
parsedUrl.protocol = "ws:";
|
|
4269
|
+
} else if (parsedUrl.protocol === "https:") {
|
|
4270
|
+
parsedUrl.protocol = "wss:";
|
|
4271
|
+
}
|
|
4272
|
+
websocket._url = parsedUrl.href;
|
|
4273
|
+
const isSecure = parsedUrl.protocol === "wss:";
|
|
4274
|
+
const isIpcUrl = parsedUrl.protocol === "ws+unix:";
|
|
4275
|
+
let invalidUrlMessage;
|
|
4276
|
+
if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
|
|
4277
|
+
invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`;
|
|
4278
|
+
} else if (isIpcUrl && !parsedUrl.pathname) {
|
|
4279
|
+
invalidUrlMessage = "The URL's pathname is empty";
|
|
4280
|
+
} else if (parsedUrl.hash) {
|
|
4281
|
+
invalidUrlMessage = "The URL contains a fragment identifier";
|
|
4282
|
+
}
|
|
4283
|
+
if (invalidUrlMessage) {
|
|
4284
|
+
const err = new SyntaxError(invalidUrlMessage);
|
|
4285
|
+
if (websocket._redirects === 0) {
|
|
4286
|
+
throw err;
|
|
4287
|
+
} else {
|
|
4288
|
+
emitErrorAndClose(websocket, err);
|
|
4289
|
+
return;
|
|
4290
|
+
}
|
|
4291
|
+
}
|
|
4292
|
+
const defaultPort = isSecure ? 443 : 80;
|
|
4293
|
+
const key2 = randomBytes(16).toString("base64");
|
|
4294
|
+
const request = isSecure ? https.request : http2.request;
|
|
4295
|
+
const protocolSet = /* @__PURE__ */ new Set();
|
|
4296
|
+
let perMessageDeflate;
|
|
4297
|
+
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
4298
|
+
opts.defaultPort = opts.defaultPort || defaultPort;
|
|
4299
|
+
opts.port = parsedUrl.port || defaultPort;
|
|
4300
|
+
opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
|
|
4301
|
+
opts.headers = {
|
|
4302
|
+
...opts.headers,
|
|
4303
|
+
"Sec-WebSocket-Version": opts.protocolVersion,
|
|
4304
|
+
"Sec-WebSocket-Key": key2,
|
|
4305
|
+
Connection: "Upgrade",
|
|
4306
|
+
Upgrade: "websocket"
|
|
4307
|
+
};
|
|
4308
|
+
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
4309
|
+
opts.timeout = opts.handshakeTimeout;
|
|
4310
|
+
if (opts.perMessageDeflate) {
|
|
4311
|
+
perMessageDeflate = new PerMessageDeflate(
|
|
4312
|
+
opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
|
|
4313
|
+
false,
|
|
4314
|
+
opts.maxPayload
|
|
4315
|
+
);
|
|
4316
|
+
opts.headers["Sec-WebSocket-Extensions"] = format({
|
|
4317
|
+
[PerMessageDeflate.extensionName]: perMessageDeflate.offer()
|
|
4318
|
+
});
|
|
4319
|
+
}
|
|
4320
|
+
if (protocols.length) {
|
|
4321
|
+
for (const protocol of protocols) {
|
|
4322
|
+
if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
|
|
4323
|
+
throw new SyntaxError(
|
|
4324
|
+
"An invalid or duplicated subprotocol was specified"
|
|
4325
|
+
);
|
|
4326
|
+
}
|
|
4327
|
+
protocolSet.add(protocol);
|
|
4328
|
+
}
|
|
4329
|
+
opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
|
|
4330
|
+
}
|
|
4331
|
+
if (opts.origin) {
|
|
4332
|
+
if (opts.protocolVersion < 13) {
|
|
4333
|
+
opts.headers["Sec-WebSocket-Origin"] = opts.origin;
|
|
4334
|
+
} else {
|
|
4335
|
+
opts.headers.Origin = opts.origin;
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
if (parsedUrl.username || parsedUrl.password) {
|
|
4339
|
+
opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
4340
|
+
}
|
|
4341
|
+
if (isIpcUrl) {
|
|
4342
|
+
const parts = opts.path.split(":");
|
|
4343
|
+
opts.socketPath = parts[0];
|
|
4344
|
+
opts.path = parts[1];
|
|
4345
|
+
}
|
|
4346
|
+
let req;
|
|
4347
|
+
if (opts.followRedirects) {
|
|
4348
|
+
if (websocket._redirects === 0) {
|
|
4349
|
+
websocket._originalIpc = isIpcUrl;
|
|
4350
|
+
websocket._originalSecure = isSecure;
|
|
4351
|
+
websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
|
|
4352
|
+
const headers = options && options.headers;
|
|
4353
|
+
options = { ...options, headers: {} };
|
|
4354
|
+
if (headers) {
|
|
4355
|
+
for (const [key3, value] of Object.entries(headers)) {
|
|
4356
|
+
options.headers[key3.toLowerCase()] = value;
|
|
4357
|
+
}
|
|
4358
|
+
}
|
|
4359
|
+
} else if (websocket.listenerCount("redirect") === 0) {
|
|
4360
|
+
const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
4361
|
+
if (!isSameHost || websocket._originalSecure && !isSecure) {
|
|
4362
|
+
delete opts.headers.authorization;
|
|
4363
|
+
delete opts.headers.cookie;
|
|
4364
|
+
if (!isSameHost) delete opts.headers.host;
|
|
4365
|
+
opts.auth = void 0;
|
|
4366
|
+
}
|
|
4367
|
+
}
|
|
4368
|
+
if (opts.auth && !options.headers.authorization) {
|
|
4369
|
+
options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
|
|
4370
|
+
}
|
|
4371
|
+
req = websocket._req = request(opts);
|
|
4372
|
+
if (websocket._redirects) {
|
|
4373
|
+
websocket.emit("redirect", websocket.url, req);
|
|
4374
|
+
}
|
|
4375
|
+
} else {
|
|
4376
|
+
req = websocket._req = request(opts);
|
|
4377
|
+
}
|
|
4378
|
+
if (opts.timeout) {
|
|
4379
|
+
req.on("timeout", () => {
|
|
4380
|
+
abortHandshake(websocket, req, "Opening handshake has timed out");
|
|
4381
|
+
});
|
|
4382
|
+
}
|
|
4383
|
+
req.on("error", (err) => {
|
|
4384
|
+
if (req === null || req[kAborted]) return;
|
|
4385
|
+
req = websocket._req = null;
|
|
4386
|
+
emitErrorAndClose(websocket, err);
|
|
4387
|
+
});
|
|
4388
|
+
req.on("response", (res) => {
|
|
4389
|
+
const location = res.headers.location;
|
|
4390
|
+
const statusCode = res.statusCode;
|
|
4391
|
+
if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
|
|
4392
|
+
if (++websocket._redirects > opts.maxRedirects) {
|
|
4393
|
+
abortHandshake(websocket, req, "Maximum redirects exceeded");
|
|
4394
|
+
return;
|
|
4395
|
+
}
|
|
4396
|
+
req.abort();
|
|
4397
|
+
let addr;
|
|
4398
|
+
try {
|
|
4399
|
+
addr = new URL2(location, address);
|
|
4400
|
+
} catch (e5) {
|
|
4401
|
+
const err = new SyntaxError(`Invalid URL: ${location}`);
|
|
4402
|
+
emitErrorAndClose(websocket, err);
|
|
4403
|
+
return;
|
|
4404
|
+
}
|
|
4405
|
+
initAsClient(websocket, addr, protocols, options);
|
|
4406
|
+
} else if (!websocket.emit("unexpected-response", req, res)) {
|
|
4407
|
+
abortHandshake(
|
|
4408
|
+
websocket,
|
|
4409
|
+
req,
|
|
4410
|
+
`Unexpected server response: ${res.statusCode}`
|
|
4411
|
+
);
|
|
4412
|
+
}
|
|
4413
|
+
});
|
|
4414
|
+
req.on("upgrade", (res, socket, head) => {
|
|
4415
|
+
websocket.emit("upgrade", res);
|
|
4416
|
+
if (websocket.readyState !== WebSocket2.CONNECTING) return;
|
|
4417
|
+
req = websocket._req = null;
|
|
4418
|
+
const upgrade = res.headers.upgrade;
|
|
4419
|
+
if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
|
|
4420
|
+
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
4421
|
+
return;
|
|
4422
|
+
}
|
|
4423
|
+
const digest = createHash2("sha1").update(key2 + GUID).digest("base64");
|
|
4424
|
+
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
4425
|
+
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
4426
|
+
return;
|
|
4427
|
+
}
|
|
4428
|
+
const serverProt = res.headers["sec-websocket-protocol"];
|
|
4429
|
+
let protError;
|
|
4430
|
+
if (serverProt !== void 0) {
|
|
4431
|
+
if (!protocolSet.size) {
|
|
4432
|
+
protError = "Server sent a subprotocol but none was requested";
|
|
4433
|
+
} else if (!protocolSet.has(serverProt)) {
|
|
4434
|
+
protError = "Server sent an invalid subprotocol";
|
|
4435
|
+
}
|
|
4436
|
+
} else if (protocolSet.size) {
|
|
4437
|
+
protError = "Server sent no subprotocol";
|
|
4438
|
+
}
|
|
4439
|
+
if (protError) {
|
|
4440
|
+
abortHandshake(websocket, socket, protError);
|
|
4441
|
+
return;
|
|
4442
|
+
}
|
|
4443
|
+
if (serverProt) websocket._protocol = serverProt;
|
|
4444
|
+
const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
|
|
4445
|
+
if (secWebSocketExtensions !== void 0) {
|
|
4446
|
+
if (!perMessageDeflate) {
|
|
4447
|
+
const message = "Server sent a Sec-WebSocket-Extensions header but no extension was requested";
|
|
4448
|
+
abortHandshake(websocket, socket, message);
|
|
4449
|
+
return;
|
|
4450
|
+
}
|
|
4451
|
+
let extensions;
|
|
4452
|
+
try {
|
|
4453
|
+
extensions = parse5(secWebSocketExtensions);
|
|
4454
|
+
} catch (err) {
|
|
4455
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
4456
|
+
abortHandshake(websocket, socket, message);
|
|
4457
|
+
return;
|
|
4458
|
+
}
|
|
4459
|
+
const extensionNames = Object.keys(extensions);
|
|
4460
|
+
if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
|
|
4461
|
+
const message = "Server indicated an extension that was not requested";
|
|
4462
|
+
abortHandshake(websocket, socket, message);
|
|
4463
|
+
return;
|
|
4464
|
+
}
|
|
4465
|
+
try {
|
|
4466
|
+
perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
|
|
4467
|
+
} catch (err) {
|
|
4468
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
4469
|
+
abortHandshake(websocket, socket, message);
|
|
4470
|
+
return;
|
|
4471
|
+
}
|
|
4472
|
+
websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
4473
|
+
}
|
|
4474
|
+
websocket.setSocket(socket, head, {
|
|
4475
|
+
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
4476
|
+
generateMask: opts.generateMask,
|
|
4477
|
+
maxPayload: opts.maxPayload,
|
|
4478
|
+
skipUTF8Validation: opts.skipUTF8Validation
|
|
4479
|
+
});
|
|
4480
|
+
});
|
|
4481
|
+
if (opts.finishRequest) {
|
|
4482
|
+
opts.finishRequest(req, websocket);
|
|
4483
|
+
} else {
|
|
4484
|
+
req.end();
|
|
4485
|
+
}
|
|
4486
|
+
}
|
|
4487
|
+
function emitErrorAndClose(websocket, err) {
|
|
4488
|
+
websocket._readyState = WebSocket2.CLOSING;
|
|
4489
|
+
websocket._errorEmitted = true;
|
|
4490
|
+
websocket.emit("error", err);
|
|
4491
|
+
websocket.emitClose();
|
|
4492
|
+
}
|
|
4493
|
+
function netConnect(options) {
|
|
4494
|
+
options.path = options.socketPath;
|
|
4495
|
+
return net.connect(options);
|
|
4496
|
+
}
|
|
4497
|
+
function tlsConnect(options) {
|
|
4498
|
+
options.path = void 0;
|
|
4499
|
+
if (!options.servername && options.servername !== "") {
|
|
4500
|
+
options.servername = net.isIP(options.host) ? "" : options.host;
|
|
4501
|
+
}
|
|
4502
|
+
return tls.connect(options);
|
|
4503
|
+
}
|
|
4504
|
+
function abortHandshake(websocket, stream, message) {
|
|
4505
|
+
websocket._readyState = WebSocket2.CLOSING;
|
|
4506
|
+
const err = new Error(message);
|
|
4507
|
+
Error.captureStackTrace(err, abortHandshake);
|
|
4508
|
+
if (stream.setHeader) {
|
|
4509
|
+
stream[kAborted] = true;
|
|
4510
|
+
stream.abort();
|
|
4511
|
+
if (stream.socket && !stream.socket.destroyed) {
|
|
4512
|
+
stream.socket.destroy();
|
|
4513
|
+
}
|
|
4514
|
+
process.nextTick(emitErrorAndClose, websocket, err);
|
|
4515
|
+
} else {
|
|
4516
|
+
stream.destroy(err);
|
|
4517
|
+
stream.once("error", websocket.emit.bind(websocket, "error"));
|
|
4518
|
+
stream.once("close", websocket.emitClose.bind(websocket));
|
|
4519
|
+
}
|
|
4520
|
+
}
|
|
4521
|
+
function sendAfterClose(websocket, data, cb) {
|
|
4522
|
+
if (data) {
|
|
4523
|
+
const length = isBlob(data) ? data.size : toBuffer(data).length;
|
|
4524
|
+
if (websocket._socket) websocket._sender._bufferedBytes += length;
|
|
4525
|
+
else websocket._bufferedAmount += length;
|
|
4526
|
+
}
|
|
4527
|
+
if (cb) {
|
|
4528
|
+
const err = new Error(
|
|
4529
|
+
`WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`
|
|
4530
|
+
);
|
|
4531
|
+
process.nextTick(cb, err);
|
|
4532
|
+
}
|
|
4533
|
+
}
|
|
4534
|
+
function receiverOnConclude(code, reason) {
|
|
4535
|
+
const websocket = this[kWebSocket];
|
|
4536
|
+
websocket._closeFrameReceived = true;
|
|
4537
|
+
websocket._closeMessage = reason;
|
|
4538
|
+
websocket._closeCode = code;
|
|
4539
|
+
if (websocket._socket[kWebSocket] === void 0) return;
|
|
4540
|
+
websocket._socket.removeListener("data", socketOnData);
|
|
4541
|
+
process.nextTick(resume, websocket._socket);
|
|
4542
|
+
if (code === 1005) websocket.close();
|
|
4543
|
+
else websocket.close(code, reason);
|
|
4544
|
+
}
|
|
4545
|
+
function receiverOnDrain() {
|
|
4546
|
+
const websocket = this[kWebSocket];
|
|
4547
|
+
if (!websocket.isPaused) websocket._socket.resume();
|
|
4548
|
+
}
|
|
4549
|
+
function receiverOnError(err) {
|
|
4550
|
+
const websocket = this[kWebSocket];
|
|
4551
|
+
if (websocket._socket[kWebSocket] !== void 0) {
|
|
4552
|
+
websocket._socket.removeListener("data", socketOnData);
|
|
4553
|
+
process.nextTick(resume, websocket._socket);
|
|
4554
|
+
websocket.close(err[kStatusCode]);
|
|
4555
|
+
}
|
|
4556
|
+
if (!websocket._errorEmitted) {
|
|
4557
|
+
websocket._errorEmitted = true;
|
|
4558
|
+
websocket.emit("error", err);
|
|
4559
|
+
}
|
|
4560
|
+
}
|
|
4561
|
+
function receiverOnFinish() {
|
|
4562
|
+
this[kWebSocket].emitClose();
|
|
4563
|
+
}
|
|
4564
|
+
function receiverOnMessage(data, isBinary) {
|
|
4565
|
+
this[kWebSocket].emit("message", data, isBinary);
|
|
4566
|
+
}
|
|
4567
|
+
function receiverOnPing(data) {
|
|
4568
|
+
const websocket = this[kWebSocket];
|
|
4569
|
+
if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP2);
|
|
4570
|
+
websocket.emit("ping", data);
|
|
4571
|
+
}
|
|
4572
|
+
function receiverOnPong(data) {
|
|
4573
|
+
this[kWebSocket].emit("pong", data);
|
|
4574
|
+
}
|
|
4575
|
+
function resume(stream) {
|
|
4576
|
+
stream.resume();
|
|
4577
|
+
}
|
|
4578
|
+
function senderOnError(err) {
|
|
4579
|
+
const websocket = this[kWebSocket];
|
|
4580
|
+
if (websocket.readyState === WebSocket2.CLOSED) return;
|
|
4581
|
+
if (websocket.readyState === WebSocket2.OPEN) {
|
|
4582
|
+
websocket._readyState = WebSocket2.CLOSING;
|
|
4583
|
+
setCloseTimer(websocket);
|
|
4584
|
+
}
|
|
4585
|
+
this._socket.end();
|
|
4586
|
+
if (!websocket._errorEmitted) {
|
|
4587
|
+
websocket._errorEmitted = true;
|
|
4588
|
+
websocket.emit("error", err);
|
|
4589
|
+
}
|
|
4590
|
+
}
|
|
4591
|
+
function setCloseTimer(websocket) {
|
|
4592
|
+
websocket._closeTimer = setTimeout(
|
|
4593
|
+
websocket._socket.destroy.bind(websocket._socket),
|
|
4594
|
+
closeTimeout
|
|
4595
|
+
);
|
|
4596
|
+
}
|
|
4597
|
+
function socketOnClose() {
|
|
4598
|
+
const websocket = this[kWebSocket];
|
|
4599
|
+
this.removeListener("close", socketOnClose);
|
|
4600
|
+
this.removeListener("data", socketOnData);
|
|
4601
|
+
this.removeListener("end", socketOnEnd);
|
|
4602
|
+
websocket._readyState = WebSocket2.CLOSING;
|
|
4603
|
+
let chunk;
|
|
4604
|
+
if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && (chunk = websocket._socket.read()) !== null) {
|
|
4605
|
+
websocket._receiver.write(chunk);
|
|
4606
|
+
}
|
|
4607
|
+
websocket._receiver.end();
|
|
4608
|
+
this[kWebSocket] = void 0;
|
|
4609
|
+
clearTimeout(websocket._closeTimer);
|
|
4610
|
+
if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
|
|
4611
|
+
websocket.emitClose();
|
|
4612
|
+
} else {
|
|
4613
|
+
websocket._receiver.on("error", receiverOnFinish);
|
|
4614
|
+
websocket._receiver.on("finish", receiverOnFinish);
|
|
4615
|
+
}
|
|
4616
|
+
}
|
|
4617
|
+
function socketOnData(chunk) {
|
|
4618
|
+
if (!this[kWebSocket]._receiver.write(chunk)) {
|
|
4619
|
+
this.pause();
|
|
4620
|
+
}
|
|
4621
|
+
}
|
|
4622
|
+
function socketOnEnd() {
|
|
4623
|
+
const websocket = this[kWebSocket];
|
|
4624
|
+
websocket._readyState = WebSocket2.CLOSING;
|
|
4625
|
+
websocket._receiver.end();
|
|
4626
|
+
this.end();
|
|
4627
|
+
}
|
|
4628
|
+
function socketOnError() {
|
|
4629
|
+
const websocket = this[kWebSocket];
|
|
4630
|
+
this.removeListener("error", socketOnError);
|
|
4631
|
+
this.on("error", NOOP2);
|
|
4632
|
+
if (websocket) {
|
|
4633
|
+
websocket._readyState = WebSocket2.CLOSING;
|
|
4634
|
+
this.destroy();
|
|
4635
|
+
}
|
|
4636
|
+
}
|
|
4637
|
+
}
|
|
4638
|
+
});
|
|
4639
|
+
|
|
4640
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/stream.js
|
|
4641
|
+
var require_stream = __commonJS({
|
|
4642
|
+
"node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/stream.js"(exports2, module2) {
|
|
4643
|
+
"use strict";
|
|
4644
|
+
var WebSocket2 = require_websocket();
|
|
4645
|
+
var { Duplex } = require("stream");
|
|
4646
|
+
function emitClose(stream) {
|
|
4647
|
+
stream.emit("close");
|
|
4648
|
+
}
|
|
4649
|
+
function duplexOnEnd() {
|
|
4650
|
+
if (!this.destroyed && this._writableState.finished) {
|
|
4651
|
+
this.destroy();
|
|
4652
|
+
}
|
|
4653
|
+
}
|
|
4654
|
+
function duplexOnError(err) {
|
|
4655
|
+
this.removeListener("error", duplexOnError);
|
|
4656
|
+
this.destroy();
|
|
4657
|
+
if (this.listenerCount("error") === 0) {
|
|
4658
|
+
this.emit("error", err);
|
|
4659
|
+
}
|
|
4660
|
+
}
|
|
4661
|
+
function createWebSocketStream2(ws2, options) {
|
|
4662
|
+
let terminateOnDestroy = true;
|
|
4663
|
+
const duplex = new Duplex({
|
|
4664
|
+
...options,
|
|
4665
|
+
autoDestroy: false,
|
|
4666
|
+
emitClose: false,
|
|
4667
|
+
objectMode: false,
|
|
4668
|
+
writableObjectMode: false
|
|
4669
|
+
});
|
|
4670
|
+
ws2.on("message", function message(msg, isBinary) {
|
|
4671
|
+
const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
|
|
4672
|
+
if (!duplex.push(data)) ws2.pause();
|
|
4673
|
+
});
|
|
4674
|
+
ws2.once("error", function error(err) {
|
|
4675
|
+
if (duplex.destroyed) return;
|
|
4676
|
+
terminateOnDestroy = false;
|
|
4677
|
+
duplex.destroy(err);
|
|
4678
|
+
});
|
|
4679
|
+
ws2.once("close", function close() {
|
|
4680
|
+
if (duplex.destroyed) return;
|
|
4681
|
+
duplex.push(null);
|
|
4682
|
+
});
|
|
4683
|
+
duplex._destroy = function(err, callback) {
|
|
4684
|
+
if (ws2.readyState === ws2.CLOSED) {
|
|
4685
|
+
callback(err);
|
|
4686
|
+
process.nextTick(emitClose, duplex);
|
|
4687
|
+
return;
|
|
4688
|
+
}
|
|
4689
|
+
let called = false;
|
|
4690
|
+
ws2.once("error", function error(err2) {
|
|
4691
|
+
called = true;
|
|
4692
|
+
callback(err2);
|
|
4693
|
+
});
|
|
4694
|
+
ws2.once("close", function close() {
|
|
4695
|
+
if (!called) callback(err);
|
|
4696
|
+
process.nextTick(emitClose, duplex);
|
|
4697
|
+
});
|
|
4698
|
+
if (terminateOnDestroy) ws2.terminate();
|
|
4699
|
+
};
|
|
4700
|
+
duplex._final = function(callback) {
|
|
4701
|
+
if (ws2.readyState === ws2.CONNECTING) {
|
|
4702
|
+
ws2.once("open", function open() {
|
|
4703
|
+
duplex._final(callback);
|
|
4704
|
+
});
|
|
4705
|
+
return;
|
|
4706
|
+
}
|
|
4707
|
+
if (ws2._socket === null) return;
|
|
4708
|
+
if (ws2._socket._writableState.finished) {
|
|
4709
|
+
callback();
|
|
4710
|
+
if (duplex._readableState.endEmitted) duplex.destroy();
|
|
4711
|
+
} else {
|
|
4712
|
+
ws2._socket.once("finish", function finish() {
|
|
4713
|
+
callback();
|
|
4714
|
+
});
|
|
4715
|
+
ws2.close();
|
|
4716
|
+
}
|
|
4717
|
+
};
|
|
4718
|
+
duplex._read = function() {
|
|
4719
|
+
if (ws2.isPaused) ws2.resume();
|
|
4720
|
+
};
|
|
4721
|
+
duplex._write = function(chunk, encoding, callback) {
|
|
4722
|
+
if (ws2.readyState === ws2.CONNECTING) {
|
|
4723
|
+
ws2.once("open", function open() {
|
|
4724
|
+
duplex._write(chunk, encoding, callback);
|
|
4725
|
+
});
|
|
4726
|
+
return;
|
|
4727
|
+
}
|
|
4728
|
+
ws2.send(chunk, callback);
|
|
4729
|
+
};
|
|
4730
|
+
duplex.on("end", duplexOnEnd);
|
|
4731
|
+
duplex.on("error", duplexOnError);
|
|
4732
|
+
return duplex;
|
|
4733
|
+
}
|
|
4734
|
+
module2.exports = createWebSocketStream2;
|
|
4735
|
+
}
|
|
4736
|
+
});
|
|
4737
|
+
|
|
4738
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/subprotocol.js
|
|
4739
|
+
var require_subprotocol = __commonJS({
|
|
4740
|
+
"node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/subprotocol.js"(exports2, module2) {
|
|
4741
|
+
"use strict";
|
|
4742
|
+
var { tokenChars } = require_validation();
|
|
4743
|
+
function parse5(header) {
|
|
4744
|
+
const protocols = /* @__PURE__ */ new Set();
|
|
4745
|
+
let start = -1;
|
|
4746
|
+
let end = -1;
|
|
4747
|
+
let i6 = 0;
|
|
4748
|
+
for (i6; i6 < header.length; i6++) {
|
|
4749
|
+
const code = header.charCodeAt(i6);
|
|
4750
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
4751
|
+
if (start === -1) start = i6;
|
|
4752
|
+
} else if (i6 !== 0 && (code === 32 || code === 9)) {
|
|
4753
|
+
if (end === -1 && start !== -1) end = i6;
|
|
4754
|
+
} else if (code === 44) {
|
|
4755
|
+
if (start === -1) {
|
|
4756
|
+
throw new SyntaxError(`Unexpected character at index ${i6}`);
|
|
4757
|
+
}
|
|
4758
|
+
if (end === -1) end = i6;
|
|
4759
|
+
const protocol2 = header.slice(start, end);
|
|
4760
|
+
if (protocols.has(protocol2)) {
|
|
4761
|
+
throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
|
|
4762
|
+
}
|
|
4763
|
+
protocols.add(protocol2);
|
|
4764
|
+
start = end = -1;
|
|
4765
|
+
} else {
|
|
4766
|
+
throw new SyntaxError(`Unexpected character at index ${i6}`);
|
|
4767
|
+
}
|
|
4768
|
+
}
|
|
4769
|
+
if (start === -1 || end !== -1) {
|
|
4770
|
+
throw new SyntaxError("Unexpected end of input");
|
|
4771
|
+
}
|
|
4772
|
+
const protocol = header.slice(start, i6);
|
|
4773
|
+
if (protocols.has(protocol)) {
|
|
4774
|
+
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
4775
|
+
}
|
|
4776
|
+
protocols.add(protocol);
|
|
4777
|
+
return protocols;
|
|
4778
|
+
}
|
|
4779
|
+
module2.exports = { parse: parse5 };
|
|
4780
|
+
}
|
|
4781
|
+
});
|
|
4782
|
+
|
|
4783
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket-server.js
|
|
4784
|
+
var require_websocket_server = __commonJS({
|
|
4785
|
+
"node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket-server.js"(exports2, module2) {
|
|
4786
|
+
"use strict";
|
|
4787
|
+
var EventEmitter = require("events");
|
|
4788
|
+
var http2 = require("http");
|
|
4789
|
+
var { Duplex } = require("stream");
|
|
4790
|
+
var { createHash: createHash2 } = require("crypto");
|
|
4791
|
+
var extension = require_extension();
|
|
4792
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
4793
|
+
var subprotocol = require_subprotocol();
|
|
4794
|
+
var WebSocket2 = require_websocket();
|
|
4795
|
+
var { GUID, kWebSocket } = require_constants();
|
|
4796
|
+
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
4797
|
+
var RUNNING = 0;
|
|
4798
|
+
var CLOSING = 1;
|
|
4799
|
+
var CLOSED = 2;
|
|
4800
|
+
var WebSocketServer2 = class extends EventEmitter {
|
|
4801
|
+
/**
|
|
4802
|
+
* Create a `WebSocketServer` instance.
|
|
4803
|
+
*
|
|
4804
|
+
* @param {Object} options Configuration options
|
|
4805
|
+
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
|
|
4806
|
+
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
4807
|
+
* multiple times in the same tick
|
|
4808
|
+
* @param {Boolean} [options.autoPong=true] Specifies whether or not to
|
|
4809
|
+
* automatically send a pong in response to a ping
|
|
4810
|
+
* @param {Number} [options.backlog=511] The maximum length of the queue of
|
|
4811
|
+
* pending connections
|
|
4812
|
+
* @param {Boolean} [options.clientTracking=true] Specifies whether or not to
|
|
4813
|
+
* track clients
|
|
4814
|
+
* @param {Function} [options.handleProtocols] A hook to handle protocols
|
|
4815
|
+
* @param {String} [options.host] The hostname where to bind the server
|
|
4816
|
+
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
|
|
4817
|
+
* size
|
|
4818
|
+
* @param {Boolean} [options.noServer=false] Enable no server mode
|
|
4819
|
+
* @param {String} [options.path] Accept only connections matching this path
|
|
4820
|
+
* @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
|
|
4821
|
+
* permessage-deflate
|
|
4822
|
+
* @param {Number} [options.port] The port where to bind the server
|
|
4823
|
+
* @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
|
|
4824
|
+
* server to use
|
|
4825
|
+
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
4826
|
+
* not to skip UTF-8 validation for text and close messages
|
|
4827
|
+
* @param {Function} [options.verifyClient] A hook to reject connections
|
|
4828
|
+
* @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
|
|
4829
|
+
* class to use. It must be the `WebSocket` class or class that extends it
|
|
4830
|
+
* @param {Function} [callback] A listener for the `listening` event
|
|
4831
|
+
*/
|
|
4832
|
+
constructor(options, callback) {
|
|
4833
|
+
super();
|
|
4834
|
+
options = {
|
|
4835
|
+
allowSynchronousEvents: true,
|
|
4836
|
+
autoPong: true,
|
|
4837
|
+
maxPayload: 100 * 1024 * 1024,
|
|
4838
|
+
skipUTF8Validation: false,
|
|
4839
|
+
perMessageDeflate: false,
|
|
4840
|
+
handleProtocols: null,
|
|
4841
|
+
clientTracking: true,
|
|
4842
|
+
verifyClient: null,
|
|
4843
|
+
noServer: false,
|
|
4844
|
+
backlog: null,
|
|
4845
|
+
// use default (511 as implemented in net.js)
|
|
4846
|
+
server: null,
|
|
4847
|
+
host: null,
|
|
4848
|
+
path: null,
|
|
4849
|
+
port: null,
|
|
4850
|
+
WebSocket: WebSocket2,
|
|
4851
|
+
...options
|
|
4852
|
+
};
|
|
4853
|
+
if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
|
|
4854
|
+
throw new TypeError(
|
|
4855
|
+
'One and only one of the "port", "server", or "noServer" options must be specified'
|
|
4856
|
+
);
|
|
4857
|
+
}
|
|
4858
|
+
if (options.port != null) {
|
|
4859
|
+
this._server = http2.createServer((req, res) => {
|
|
4860
|
+
const body = http2.STATUS_CODES[426];
|
|
4861
|
+
res.writeHead(426, {
|
|
4862
|
+
"Content-Length": body.length,
|
|
4863
|
+
"Content-Type": "text/plain"
|
|
4864
|
+
});
|
|
4865
|
+
res.end(body);
|
|
4866
|
+
});
|
|
4867
|
+
this._server.listen(
|
|
4868
|
+
options.port,
|
|
4869
|
+
options.host,
|
|
4870
|
+
options.backlog,
|
|
4871
|
+
callback
|
|
4872
|
+
);
|
|
4873
|
+
} else if (options.server) {
|
|
4874
|
+
this._server = options.server;
|
|
4875
|
+
}
|
|
4876
|
+
if (this._server) {
|
|
4877
|
+
const emitConnection = this.emit.bind(this, "connection");
|
|
4878
|
+
this._removeListeners = addListeners(this._server, {
|
|
4879
|
+
listening: this.emit.bind(this, "listening"),
|
|
4880
|
+
error: this.emit.bind(this, "error"),
|
|
4881
|
+
upgrade: (req, socket, head) => {
|
|
4882
|
+
this.handleUpgrade(req, socket, head, emitConnection);
|
|
4883
|
+
}
|
|
4884
|
+
});
|
|
4885
|
+
}
|
|
4886
|
+
if (options.perMessageDeflate === true) options.perMessageDeflate = {};
|
|
4887
|
+
if (options.clientTracking) {
|
|
4888
|
+
this.clients = /* @__PURE__ */ new Set();
|
|
4889
|
+
this._shouldEmitClose = false;
|
|
4890
|
+
}
|
|
4891
|
+
this.options = options;
|
|
4892
|
+
this._state = RUNNING;
|
|
4893
|
+
}
|
|
4894
|
+
/**
|
|
4895
|
+
* Returns the bound address, the address family name, and port of the server
|
|
4896
|
+
* as reported by the operating system if listening on an IP socket.
|
|
4897
|
+
* If the server is listening on a pipe or UNIX domain socket, the name is
|
|
4898
|
+
* returned as a string.
|
|
4899
|
+
*
|
|
4900
|
+
* @return {(Object|String|null)} The address of the server
|
|
4901
|
+
* @public
|
|
4902
|
+
*/
|
|
4903
|
+
address() {
|
|
4904
|
+
if (this.options.noServer) {
|
|
4905
|
+
throw new Error('The server is operating in "noServer" mode');
|
|
4906
|
+
}
|
|
4907
|
+
if (!this._server) return null;
|
|
4908
|
+
return this._server.address();
|
|
4909
|
+
}
|
|
4910
|
+
/**
|
|
4911
|
+
* Stop the server from accepting new connections and emit the `'close'` event
|
|
4912
|
+
* when all existing connections are closed.
|
|
4913
|
+
*
|
|
4914
|
+
* @param {Function} [cb] A one-time listener for the `'close'` event
|
|
4915
|
+
* @public
|
|
4916
|
+
*/
|
|
4917
|
+
close(cb) {
|
|
4918
|
+
if (this._state === CLOSED) {
|
|
4919
|
+
if (cb) {
|
|
4920
|
+
this.once("close", () => {
|
|
4921
|
+
cb(new Error("The server is not running"));
|
|
4922
|
+
});
|
|
4923
|
+
}
|
|
4924
|
+
process.nextTick(emitClose, this);
|
|
4925
|
+
return;
|
|
4926
|
+
}
|
|
4927
|
+
if (cb) this.once("close", cb);
|
|
4928
|
+
if (this._state === CLOSING) return;
|
|
4929
|
+
this._state = CLOSING;
|
|
4930
|
+
if (this.options.noServer || this.options.server) {
|
|
4931
|
+
if (this._server) {
|
|
4932
|
+
this._removeListeners();
|
|
4933
|
+
this._removeListeners = this._server = null;
|
|
4934
|
+
}
|
|
4935
|
+
if (this.clients) {
|
|
4936
|
+
if (!this.clients.size) {
|
|
4937
|
+
process.nextTick(emitClose, this);
|
|
4938
|
+
} else {
|
|
4939
|
+
this._shouldEmitClose = true;
|
|
4940
|
+
}
|
|
4941
|
+
} else {
|
|
4942
|
+
process.nextTick(emitClose, this);
|
|
4943
|
+
}
|
|
4944
|
+
} else {
|
|
4945
|
+
const server = this._server;
|
|
4946
|
+
this._removeListeners();
|
|
4947
|
+
this._removeListeners = this._server = null;
|
|
4948
|
+
server.close(() => {
|
|
4949
|
+
emitClose(this);
|
|
4950
|
+
});
|
|
4951
|
+
}
|
|
4952
|
+
}
|
|
4953
|
+
/**
|
|
4954
|
+
* See if a given request should be handled by this server instance.
|
|
4955
|
+
*
|
|
4956
|
+
* @param {http.IncomingMessage} req Request object to inspect
|
|
4957
|
+
* @return {Boolean} `true` if the request is valid, else `false`
|
|
4958
|
+
* @public
|
|
4959
|
+
*/
|
|
4960
|
+
shouldHandle(req) {
|
|
4961
|
+
if (this.options.path) {
|
|
4962
|
+
const index = req.url.indexOf("?");
|
|
4963
|
+
const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
|
|
4964
|
+
if (pathname !== this.options.path) return false;
|
|
4965
|
+
}
|
|
4966
|
+
return true;
|
|
4967
|
+
}
|
|
4968
|
+
/**
|
|
4969
|
+
* Handle a HTTP Upgrade request.
|
|
4970
|
+
*
|
|
4971
|
+
* @param {http.IncomingMessage} req The request object
|
|
4972
|
+
* @param {Duplex} socket The network socket between the server and client
|
|
4973
|
+
* @param {Buffer} head The first packet of the upgraded stream
|
|
4974
|
+
* @param {Function} cb Callback
|
|
4975
|
+
* @public
|
|
4976
|
+
*/
|
|
4977
|
+
handleUpgrade(req, socket, head, cb) {
|
|
4978
|
+
socket.on("error", socketOnError);
|
|
4979
|
+
const key2 = req.headers["sec-websocket-key"];
|
|
4980
|
+
const upgrade = req.headers.upgrade;
|
|
4981
|
+
const version2 = +req.headers["sec-websocket-version"];
|
|
4982
|
+
if (req.method !== "GET") {
|
|
4983
|
+
const message = "Invalid HTTP method";
|
|
4984
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
|
|
4985
|
+
return;
|
|
4986
|
+
}
|
|
4987
|
+
if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
|
|
4988
|
+
const message = "Invalid Upgrade header";
|
|
4989
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
4990
|
+
return;
|
|
4991
|
+
}
|
|
4992
|
+
if (key2 === void 0 || !keyRegex.test(key2)) {
|
|
4993
|
+
const message = "Missing or invalid Sec-WebSocket-Key header";
|
|
4994
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
4995
|
+
return;
|
|
4996
|
+
}
|
|
4997
|
+
if (version2 !== 13 && version2 !== 8) {
|
|
4998
|
+
const message = "Missing or invalid Sec-WebSocket-Version header";
|
|
4999
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
|
|
5000
|
+
"Sec-WebSocket-Version": "13, 8"
|
|
5001
|
+
});
|
|
5002
|
+
return;
|
|
5003
|
+
}
|
|
5004
|
+
if (!this.shouldHandle(req)) {
|
|
5005
|
+
abortHandshake(socket, 400);
|
|
5006
|
+
return;
|
|
5007
|
+
}
|
|
5008
|
+
const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
|
|
5009
|
+
let protocols = /* @__PURE__ */ new Set();
|
|
5010
|
+
if (secWebSocketProtocol !== void 0) {
|
|
5011
|
+
try {
|
|
5012
|
+
protocols = subprotocol.parse(secWebSocketProtocol);
|
|
5013
|
+
} catch (err) {
|
|
5014
|
+
const message = "Invalid Sec-WebSocket-Protocol header";
|
|
5015
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
5016
|
+
return;
|
|
5017
|
+
}
|
|
5018
|
+
}
|
|
5019
|
+
const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
|
|
5020
|
+
const extensions = {};
|
|
5021
|
+
if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
|
|
5022
|
+
const perMessageDeflate = new PerMessageDeflate(
|
|
5023
|
+
this.options.perMessageDeflate,
|
|
5024
|
+
true,
|
|
5025
|
+
this.options.maxPayload
|
|
5026
|
+
);
|
|
5027
|
+
try {
|
|
5028
|
+
const offers = extension.parse(secWebSocketExtensions);
|
|
5029
|
+
if (offers[PerMessageDeflate.extensionName]) {
|
|
5030
|
+
perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
|
|
5031
|
+
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
5032
|
+
}
|
|
5033
|
+
} catch (err) {
|
|
5034
|
+
const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
|
|
5035
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
5036
|
+
return;
|
|
5037
|
+
}
|
|
5038
|
+
}
|
|
5039
|
+
if (this.options.verifyClient) {
|
|
5040
|
+
const info = {
|
|
5041
|
+
origin: req.headers[`${version2 === 8 ? "sec-websocket-origin" : "origin"}`],
|
|
5042
|
+
secure: !!(req.socket.authorized || req.socket.encrypted),
|
|
5043
|
+
req
|
|
5044
|
+
};
|
|
5045
|
+
if (this.options.verifyClient.length === 2) {
|
|
5046
|
+
this.options.verifyClient(info, (verified, code, message, headers) => {
|
|
5047
|
+
if (!verified) {
|
|
5048
|
+
return abortHandshake(socket, code || 401, message, headers);
|
|
5049
|
+
}
|
|
5050
|
+
this.completeUpgrade(
|
|
5051
|
+
extensions,
|
|
5052
|
+
key2,
|
|
5053
|
+
protocols,
|
|
5054
|
+
req,
|
|
5055
|
+
socket,
|
|
5056
|
+
head,
|
|
5057
|
+
cb
|
|
5058
|
+
);
|
|
5059
|
+
});
|
|
5060
|
+
return;
|
|
5061
|
+
}
|
|
5062
|
+
if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
|
|
5063
|
+
}
|
|
5064
|
+
this.completeUpgrade(extensions, key2, protocols, req, socket, head, cb);
|
|
5065
|
+
}
|
|
5066
|
+
/**
|
|
5067
|
+
* Upgrade the connection to WebSocket.
|
|
5068
|
+
*
|
|
5069
|
+
* @param {Object} extensions The accepted extensions
|
|
5070
|
+
* @param {String} key The value of the `Sec-WebSocket-Key` header
|
|
5071
|
+
* @param {Set} protocols The subprotocols
|
|
5072
|
+
* @param {http.IncomingMessage} req The request object
|
|
5073
|
+
* @param {Duplex} socket The network socket between the server and client
|
|
5074
|
+
* @param {Buffer} head The first packet of the upgraded stream
|
|
5075
|
+
* @param {Function} cb Callback
|
|
5076
|
+
* @throws {Error} If called more than once with the same socket
|
|
5077
|
+
* @private
|
|
5078
|
+
*/
|
|
5079
|
+
completeUpgrade(extensions, key2, protocols, req, socket, head, cb) {
|
|
5080
|
+
if (!socket.readable || !socket.writable) return socket.destroy();
|
|
5081
|
+
if (socket[kWebSocket]) {
|
|
5082
|
+
throw new Error(
|
|
5083
|
+
"server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
|
|
5084
|
+
);
|
|
5085
|
+
}
|
|
5086
|
+
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
5087
|
+
const digest = createHash2("sha1").update(key2 + GUID).digest("base64");
|
|
5088
|
+
const headers = [
|
|
5089
|
+
"HTTP/1.1 101 Switching Protocols",
|
|
5090
|
+
"Upgrade: websocket",
|
|
5091
|
+
"Connection: Upgrade",
|
|
5092
|
+
`Sec-WebSocket-Accept: ${digest}`
|
|
5093
|
+
];
|
|
5094
|
+
const ws2 = new this.options.WebSocket(null, void 0, this.options);
|
|
5095
|
+
if (protocols.size) {
|
|
5096
|
+
const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
|
|
5097
|
+
if (protocol) {
|
|
5098
|
+
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
5099
|
+
ws2._protocol = protocol;
|
|
5100
|
+
}
|
|
5101
|
+
}
|
|
5102
|
+
if (extensions[PerMessageDeflate.extensionName]) {
|
|
5103
|
+
const params = extensions[PerMessageDeflate.extensionName].params;
|
|
5104
|
+
const value = extension.format({
|
|
5105
|
+
[PerMessageDeflate.extensionName]: [params]
|
|
5106
|
+
});
|
|
5107
|
+
headers.push(`Sec-WebSocket-Extensions: ${value}`);
|
|
5108
|
+
ws2._extensions = extensions;
|
|
5109
|
+
}
|
|
5110
|
+
this.emit("headers", headers, req);
|
|
5111
|
+
socket.write(headers.concat("\r\n").join("\r\n"));
|
|
5112
|
+
socket.removeListener("error", socketOnError);
|
|
5113
|
+
ws2.setSocket(socket, head, {
|
|
5114
|
+
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
5115
|
+
maxPayload: this.options.maxPayload,
|
|
5116
|
+
skipUTF8Validation: this.options.skipUTF8Validation
|
|
5117
|
+
});
|
|
5118
|
+
if (this.clients) {
|
|
5119
|
+
this.clients.add(ws2);
|
|
5120
|
+
ws2.on("close", () => {
|
|
5121
|
+
this.clients.delete(ws2);
|
|
5122
|
+
if (this._shouldEmitClose && !this.clients.size) {
|
|
5123
|
+
process.nextTick(emitClose, this);
|
|
5124
|
+
}
|
|
5125
|
+
});
|
|
5126
|
+
}
|
|
5127
|
+
cb(ws2, req);
|
|
5128
|
+
}
|
|
5129
|
+
};
|
|
5130
|
+
module2.exports = WebSocketServer2;
|
|
5131
|
+
function addListeners(server, map) {
|
|
5132
|
+
for (const event of Object.keys(map)) server.on(event, map[event]);
|
|
5133
|
+
return function removeListeners() {
|
|
5134
|
+
for (const event of Object.keys(map)) {
|
|
5135
|
+
server.removeListener(event, map[event]);
|
|
5136
|
+
}
|
|
5137
|
+
};
|
|
5138
|
+
}
|
|
5139
|
+
function emitClose(server) {
|
|
5140
|
+
server._state = CLOSED;
|
|
5141
|
+
server.emit("close");
|
|
5142
|
+
}
|
|
5143
|
+
function socketOnError() {
|
|
5144
|
+
this.destroy();
|
|
5145
|
+
}
|
|
5146
|
+
function abortHandshake(socket, code, message, headers) {
|
|
5147
|
+
message = message || http2.STATUS_CODES[code];
|
|
5148
|
+
headers = {
|
|
5149
|
+
Connection: "close",
|
|
5150
|
+
"Content-Type": "text/html",
|
|
5151
|
+
"Content-Length": Buffer.byteLength(message),
|
|
5152
|
+
...headers
|
|
5153
|
+
};
|
|
5154
|
+
socket.once("finish", socket.destroy);
|
|
5155
|
+
socket.end(
|
|
5156
|
+
`HTTP/1.1 ${code} ${http2.STATUS_CODES[code]}\r
|
|
5157
|
+
` + Object.keys(headers).map((h9) => `${h9}: ${headers[h9]}`).join("\r\n") + "\r\n\r\n" + message
|
|
5158
|
+
);
|
|
5159
|
+
}
|
|
5160
|
+
function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
|
|
5161
|
+
if (server.listenerCount("wsClientError")) {
|
|
5162
|
+
const err = new Error(message);
|
|
5163
|
+
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
|
|
5164
|
+
server.emit("wsClientError", err, socket, req);
|
|
5165
|
+
} else {
|
|
5166
|
+
abortHandshake(socket, code, message, headers);
|
|
5167
|
+
}
|
|
5168
|
+
}
|
|
5169
|
+
}
|
|
5170
|
+
});
|
|
5171
|
+
|
|
1564
5172
|
// src/server/main.ts
|
|
1565
5173
|
var import_node_child_process2 = require("node:child_process");
|
|
1566
5174
|
var import_node_fs22 = __toESM(require("node:fs"), 1);
|
|
@@ -17117,8 +20725,8 @@ function isIntrospectableSchema(parse5) {
|
|
|
17117
20725
|
function createState(key2, valueConfig) {
|
|
17118
20726
|
return new StateConfig(key2, valueConfig);
|
|
17119
20727
|
}
|
|
17120
|
-
function $getState(node, stateConfig,
|
|
17121
|
-
const latestOrDirectNode =
|
|
20728
|
+
function $getState(node, stateConfig, version2 = NODE_STATE_LATEST) {
|
|
20729
|
+
const latestOrDirectNode = version2 === NODE_STATE_LATEST ? node.getLatest() : node;
|
|
17122
20730
|
const state = latestOrDirectNode.__state;
|
|
17123
20731
|
if (state) {
|
|
17124
20732
|
$checkCollision(node, stateConfig, state);
|
|
@@ -25684,11 +29292,11 @@ function collectBuildInformation() {
|
|
|
25684
29292
|
if (isLexicalEditor(editor)) {
|
|
25685
29293
|
compatibleEditors++;
|
|
25686
29294
|
} else if (editor) {
|
|
25687
|
-
let
|
|
25688
|
-
if (
|
|
25689
|
-
|
|
29295
|
+
let version2 = String(editor.constructor.version || "<0.17.1");
|
|
29296
|
+
if (version2 === thisVersion) {
|
|
29297
|
+
version2 += " (separately built, likely a bundler configuration issue)";
|
|
25690
29298
|
}
|
|
25691
|
-
incompatibleEditors.add(
|
|
29299
|
+
incompatibleEditors.add(version2);
|
|
25692
29300
|
}
|
|
25693
29301
|
}
|
|
25694
29302
|
}
|
|
@@ -28321,13 +31929,13 @@ function createEditor(editorConfig) {
|
|
|
28321
31929
|
replaceWithKlass = options.withKlass || null;
|
|
28322
31930
|
}
|
|
28323
31931
|
if (typeof klass !== "function" || !klass.prototype || !(klass === LexicalNode || klass.prototype instanceof LexicalNode)) {
|
|
28324
|
-
let
|
|
31932
|
+
let version2 = "<unknown>";
|
|
28325
31933
|
try {
|
|
28326
|
-
|
|
31934
|
+
version2 = JSON.parse(LEXICAL_VERSION);
|
|
28327
31935
|
} catch {
|
|
28328
31936
|
}
|
|
28329
31937
|
{
|
|
28330
|
-
formatDevErrorMessage(`createEditor: nodes[${String(i6 - nodes.length + (config.nodes ? config.nodes.length : 0))}] ${typeof klass === "function" ? `${klass.name}${typeof klass.getType === "function" ? ` (type ${String(klass.getType())})` : ""}` : String(klass)} is not a constructor that subclasses LexicalNode from the lexical package used by this editor (${String(
|
|
31938
|
+
formatDevErrorMessage(`createEditor: nodes[${String(i6 - nodes.length + (config.nodes ? config.nodes.length : 0))}] ${typeof klass === "function" ? `${klass.name}${typeof klass.getType === "function" ? ` (type ${String(klass.getType())})` : ""}` : String(klass)} is not a constructor that subclasses LexicalNode from the lexical package used by this editor (${String(version2)})`);
|
|
28331
31939
|
}
|
|
28332
31940
|
}
|
|
28333
31941
|
void getStaticNodeConfig(klass);
|
|
@@ -30676,19 +34284,19 @@ function hasOwnStaticMethod(klass, k5) {
|
|
|
30676
34284
|
function isAbstractNodeClass(klass) {
|
|
30677
34285
|
if (!(klass === LexicalNode || klass.prototype instanceof LexicalNode)) {
|
|
30678
34286
|
let ownNodeType = "<unknown>";
|
|
30679
|
-
let
|
|
34287
|
+
let version2 = "<unknown>";
|
|
30680
34288
|
try {
|
|
30681
34289
|
ownNodeType = klass.getType();
|
|
30682
34290
|
} catch (_err) {
|
|
30683
34291
|
}
|
|
30684
34292
|
try {
|
|
30685
34293
|
if (LexicalEditor.version) {
|
|
30686
|
-
|
|
34294
|
+
version2 = JSON.parse(LexicalEditor.version);
|
|
30687
34295
|
}
|
|
30688
34296
|
} catch (_err) {
|
|
30689
34297
|
}
|
|
30690
34298
|
{
|
|
30691
|
-
formatDevErrorMessage(`${klass.name} (type ${ownNodeType}) does not subclass LexicalNode from the lexical package used by this editor (version ${
|
|
34299
|
+
formatDevErrorMessage(`${klass.name} (type ${ownNodeType}) does not subclass LexicalNode from the lexical package used by this editor (version ${version2}). All lexical and @lexical/* packages used by an editor must have identical versions. If you suspect the version does match, then the problem may be caused by multiple copies of the same lexical module (e.g. both esm and cjs, or included directly in multiple entrypoints).`);
|
|
30692
34300
|
}
|
|
30693
34301
|
}
|
|
30694
34302
|
return klass === DecoratorNode || klass === ElementNode || klass === LexicalNode;
|
|
@@ -48065,10 +51673,10 @@ var VersionVector = class _VersionVector {
|
|
|
48065
51673
|
* @param {Map<PeerID, number>} version
|
|
48066
51674
|
* @returns {VersionVector}
|
|
48067
51675
|
*/
|
|
48068
|
-
static parseJSON(
|
|
51676
|
+
static parseJSON(version2) {
|
|
48069
51677
|
try {
|
|
48070
51678
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
48071
|
-
wasm.versionvector_parseJSON(retptr, addHeapObject(
|
|
51679
|
+
wasm.versionvector_parseJSON(retptr, addHeapObject(version2));
|
|
48072
51680
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
48073
51681
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
48074
51682
|
var r22 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
@@ -81215,8 +84823,8 @@ var DecoratorTextNode = class extends DecoratorNode2 {
|
|
|
81215
84823
|
}]
|
|
81216
84824
|
});
|
|
81217
84825
|
}
|
|
81218
|
-
getFormat(
|
|
81219
|
-
return $getState2(this, formatState,
|
|
84826
|
+
getFormat(version2) {
|
|
84827
|
+
return $getState2(this, formatState, version2);
|
|
81220
84828
|
}
|
|
81221
84829
|
getFormatFlags(type, alignWithFormat) {
|
|
81222
84830
|
return toggleTextFormatType2(this.getFormat(), type, alignWithFormat);
|
|
@@ -81451,7 +85059,7 @@ function $serializeNodeVersion(node) {
|
|
|
81451
85059
|
const json = node.exportJSON();
|
|
81452
85060
|
delete json.children;
|
|
81453
85061
|
delete json.$slots;
|
|
81454
|
-
const
|
|
85062
|
+
const version2 = {
|
|
81455
85063
|
json,
|
|
81456
85064
|
key: node.__key,
|
|
81457
85065
|
next: node.__next,
|
|
@@ -81459,21 +85067,21 @@ function $serializeNodeVersion(node) {
|
|
|
81459
85067
|
prev: node.__prev
|
|
81460
85068
|
};
|
|
81461
85069
|
if ($isElementNode2(node)) {
|
|
81462
|
-
|
|
81463
|
-
|
|
81464
|
-
|
|
85070
|
+
version2.first = node.__first;
|
|
85071
|
+
version2.last = node.__last;
|
|
85072
|
+
version2.size = node.__size;
|
|
81465
85073
|
}
|
|
81466
85074
|
const {
|
|
81467
85075
|
__slotHost,
|
|
81468
85076
|
__slots
|
|
81469
85077
|
} = node;
|
|
81470
85078
|
if (__slots != null) {
|
|
81471
|
-
|
|
85079
|
+
version2.slots = Array.from(__slots);
|
|
81472
85080
|
}
|
|
81473
85081
|
if (__slotHost != null) {
|
|
81474
|
-
|
|
85082
|
+
version2.slotHost = __slotHost;
|
|
81475
85083
|
}
|
|
81476
|
-
return
|
|
85084
|
+
return version2;
|
|
81477
85085
|
}
|
|
81478
85086
|
function serializeEditorStateFamily(states) {
|
|
81479
85087
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -81604,46 +85212,46 @@ function deserializeEditorStateFamily(family, editor) {
|
|
|
81604
85212
|
let slotsUsed = false;
|
|
81605
85213
|
let linked = false;
|
|
81606
85214
|
const template = editor.parseEditorState(SCRATCH_STATE_JSON, () => {
|
|
81607
|
-
for (const
|
|
85215
|
+
for (const version2 of family.nodes) {
|
|
81608
85216
|
let node = null;
|
|
81609
85217
|
try {
|
|
81610
|
-
node = $buildNodeVersion(
|
|
85218
|
+
node = $buildNodeVersion(version2.json, editor);
|
|
81611
85219
|
} catch {
|
|
81612
85220
|
versions.push(null);
|
|
81613
85221
|
continue;
|
|
81614
85222
|
}
|
|
81615
|
-
const key2 = keys2.get(
|
|
85223
|
+
const key2 = keys2.get(version2.key);
|
|
81616
85224
|
if (key2 === void 0) {
|
|
81617
|
-
keys2.set(
|
|
85225
|
+
keys2.set(version2.key, node.__key);
|
|
81618
85226
|
} else {
|
|
81619
85227
|
node.__key = key2;
|
|
81620
85228
|
}
|
|
81621
85229
|
versions.push(node);
|
|
81622
85230
|
}
|
|
81623
85231
|
const mapKey = (key2) => key2 === null ? null : keys2.get(key2) ?? null;
|
|
81624
|
-
for (const [index,
|
|
85232
|
+
for (const [index, version2] of family.nodes.entries()) {
|
|
81625
85233
|
const node = versions[index];
|
|
81626
85234
|
if (node === null) {
|
|
81627
85235
|
continue;
|
|
81628
85236
|
}
|
|
81629
|
-
node.__parent = mapKey(
|
|
81630
|
-
node.__prev = mapKey(
|
|
81631
|
-
node.__next = mapKey(
|
|
85237
|
+
node.__parent = mapKey(version2.parent);
|
|
85238
|
+
node.__prev = mapKey(version2.prev);
|
|
85239
|
+
node.__next = mapKey(version2.next);
|
|
81632
85240
|
if ($isElementNode2(node)) {
|
|
81633
|
-
node.__first = mapKey(
|
|
81634
|
-
node.__last = mapKey(
|
|
81635
|
-
node.__size =
|
|
85241
|
+
node.__first = mapKey(version2.first ?? null);
|
|
85242
|
+
node.__last = mapKey(version2.last ?? null);
|
|
85243
|
+
node.__size = version2.size ?? 0;
|
|
81636
85244
|
}
|
|
81637
85245
|
const slotted = node;
|
|
81638
|
-
if (
|
|
85246
|
+
if (version2.slots !== void 0) {
|
|
81639
85247
|
slotsUsed = true;
|
|
81640
|
-
slotted.__slots = new Map(
|
|
85248
|
+
slotted.__slots = new Map(version2.slots.flatMap(([name, key2]) => {
|
|
81641
85249
|
const restored = mapKey(key2);
|
|
81642
85250
|
return restored === null ? [] : [[name, restored]];
|
|
81643
85251
|
}));
|
|
81644
85252
|
}
|
|
81645
|
-
if (
|
|
81646
|
-
slotted.__slotHost = mapKey(
|
|
85253
|
+
if (version2.slotHost !== void 0) {
|
|
85254
|
+
slotted.__slotHost = mapKey(version2.slotHost);
|
|
81647
85255
|
}
|
|
81648
85256
|
}
|
|
81649
85257
|
linked = true;
|
|
@@ -85021,6 +88629,158 @@ function setProjectAutoPublish(file, value) {
|
|
|
85021
88629
|
writeJsonAtomic(file, config);
|
|
85022
88630
|
}
|
|
85023
88631
|
|
|
88632
|
+
// src/server/credentials.ts
|
|
88633
|
+
var import_node_fs13 = __toESM(require("node:fs"), 1);
|
|
88634
|
+
var import_node_path13 = __toESM(require("node:path"), 1);
|
|
88635
|
+
function credentialsFile(env, platform, home) {
|
|
88636
|
+
if (platform === "win32" && env.APPDATA) return import_node_path13.default.join(env.APPDATA, "ryugi", "credentials.json");
|
|
88637
|
+
return import_node_path13.default.join(env.XDG_CONFIG_HOME || import_node_path13.default.join(home, ".config"), "ryugi", "credentials.json");
|
|
88638
|
+
}
|
|
88639
|
+
function readCredentials(file, origin) {
|
|
88640
|
+
let raw;
|
|
88641
|
+
try {
|
|
88642
|
+
raw = JSON.parse(import_node_fs13.default.readFileSync(file, "utf8"));
|
|
88643
|
+
} catch {
|
|
88644
|
+
return null;
|
|
88645
|
+
}
|
|
88646
|
+
if (typeof raw !== "object" || raw === null) return null;
|
|
88647
|
+
const { origin: savedOrigin, token, login } = raw;
|
|
88648
|
+
if (typeof savedOrigin !== "string" || typeof token !== "string" || typeof login !== "string") return null;
|
|
88649
|
+
if (savedOrigin !== origin) return null;
|
|
88650
|
+
return { origin: savedOrigin, token, login };
|
|
88651
|
+
}
|
|
88652
|
+
function writeCredentials(file, credentials) {
|
|
88653
|
+
import_node_fs13.default.mkdirSync(import_node_path13.default.dirname(file), { recursive: true, mode: 448 });
|
|
88654
|
+
writeJsonAtomic(file, credentials);
|
|
88655
|
+
}
|
|
88656
|
+
function clearCredentials(file) {
|
|
88657
|
+
import_node_fs13.default.rmSync(file, { force: true });
|
|
88658
|
+
}
|
|
88659
|
+
|
|
88660
|
+
// node_modules/.pnpm/ws@8.18.3/node_modules/ws/wrapper.mjs
|
|
88661
|
+
var import_stream = __toESM(require_stream(), 1);
|
|
88662
|
+
var import_receiver = __toESM(require_receiver(), 1);
|
|
88663
|
+
var import_sender = __toESM(require_sender(), 1);
|
|
88664
|
+
var import_websocket = __toESM(require_websocket(), 1);
|
|
88665
|
+
var import_websocket_server = __toESM(require_websocket_server(), 1);
|
|
88666
|
+
var wrapper_default = import_websocket.default;
|
|
88667
|
+
|
|
88668
|
+
// src/server/relay.ts
|
|
88669
|
+
var HEARTBEAT_MS = 25e3;
|
|
88670
|
+
var PONG_TIMEOUT_MS = 1e4;
|
|
88671
|
+
var HANDSHAKE_TIMEOUT_MS = 1e4;
|
|
88672
|
+
var MAX_BACKOFF_MS = 3e4;
|
|
88673
|
+
function createRelayClient(options) {
|
|
88674
|
+
let socket = null;
|
|
88675
|
+
let announced = "";
|
|
88676
|
+
let watched = /* @__PURE__ */ new Set();
|
|
88677
|
+
let backoff = 1e3;
|
|
88678
|
+
let nextAttempt = 0;
|
|
88679
|
+
let heartbeat;
|
|
88680
|
+
let pongDeadline;
|
|
88681
|
+
let closed = false;
|
|
88682
|
+
const send2 = (message) => {
|
|
88683
|
+
if (socket?.readyState === wrapper_default.OPEN) socket.send(JSON.stringify(message));
|
|
88684
|
+
};
|
|
88685
|
+
const idsOf = (served) => [...served.keys()].sort();
|
|
88686
|
+
const drop = () => {
|
|
88687
|
+
clearInterval(heartbeat);
|
|
88688
|
+
clearTimeout(pongDeadline);
|
|
88689
|
+
socket?.removeAllListeners();
|
|
88690
|
+
socket?.on("error", () => {
|
|
88691
|
+
});
|
|
88692
|
+
socket?.terminate();
|
|
88693
|
+
socket = null;
|
|
88694
|
+
announced = "";
|
|
88695
|
+
watched = /* @__PURE__ */ new Set();
|
|
88696
|
+
options.onWatch?.(/* @__PURE__ */ new Set());
|
|
88697
|
+
};
|
|
88698
|
+
const reply = (conn, rid, body) => send2({ t: "reply", conn, rid, body });
|
|
88699
|
+
const onRequest = async (message) => {
|
|
88700
|
+
if (typeof message.conn !== "string" || typeof message.id !== "string") return;
|
|
88701
|
+
options.onActivity();
|
|
88702
|
+
const key2 = options.served().get(message.id);
|
|
88703
|
+
if (!key2) return reply(message.conn, message.rid, { ok: false, error: "not served here" });
|
|
88704
|
+
try {
|
|
88705
|
+
reply(message.conn, message.rid, { ok: true, data: await options.handle(key2, message.body, message.conn) });
|
|
88706
|
+
} catch (err) {
|
|
88707
|
+
reply(message.conn, message.rid, { ok: false, error: err.message });
|
|
88708
|
+
}
|
|
88709
|
+
};
|
|
88710
|
+
const connect = (token, served) => {
|
|
88711
|
+
const ws2 = new wrapper_default(options.url, { headers: { Authorization: `Bearer ${token}` }, handshakeTimeout: options.handshakeTimeoutMs ?? HANDSHAKE_TIMEOUT_MS });
|
|
88712
|
+
socket = ws2;
|
|
88713
|
+
ws2.on("open", () => {
|
|
88714
|
+
backoff = 1e3;
|
|
88715
|
+
announced = idsOf(served).join("\n");
|
|
88716
|
+
send2({ t: "hello", version: options.version, ids: idsOf(served) });
|
|
88717
|
+
heartbeat = setInterval(() => {
|
|
88718
|
+
if (watched.size > 0) options.onActivity();
|
|
88719
|
+
ws2.send("ping");
|
|
88720
|
+
pongDeadline ??= setTimeout(drop, PONG_TIMEOUT_MS);
|
|
88721
|
+
}, options.heartbeatMs ?? HEARTBEAT_MS);
|
|
88722
|
+
});
|
|
88723
|
+
ws2.on("message", (data) => {
|
|
88724
|
+
const text2 = data.toString();
|
|
88725
|
+
if (text2 === "pong") {
|
|
88726
|
+
clearTimeout(pongDeadline);
|
|
88727
|
+
pongDeadline = void 0;
|
|
88728
|
+
return;
|
|
88729
|
+
}
|
|
88730
|
+
let message;
|
|
88731
|
+
try {
|
|
88732
|
+
message = JSON.parse(text2);
|
|
88733
|
+
} catch {
|
|
88734
|
+
return;
|
|
88735
|
+
}
|
|
88736
|
+
if (message.t === "watch" && Array.isArray(message.ids)) {
|
|
88737
|
+
watched = new Set(message.ids.filter((id2) => typeof id2 === "string"));
|
|
88738
|
+
const served2 = options.served();
|
|
88739
|
+
options.onWatch?.(new Set([...watched].flatMap((id2) => served2.has(id2) ? [served2.get(id2)] : [])));
|
|
88740
|
+
} else if (message.t === "request") void onRequest(message);
|
|
88741
|
+
});
|
|
88742
|
+
const lost = () => {
|
|
88743
|
+
if (socket !== ws2) return;
|
|
88744
|
+
drop();
|
|
88745
|
+
nextAttempt = Date.now() + backoff;
|
|
88746
|
+
backoff = Math.min(backoff * 2, MAX_BACKOFF_MS);
|
|
88747
|
+
};
|
|
88748
|
+
ws2.on("close", lost);
|
|
88749
|
+
ws2.on("error", lost);
|
|
88750
|
+
};
|
|
88751
|
+
const tick = () => {
|
|
88752
|
+
if (closed) return;
|
|
88753
|
+
const token = options.token();
|
|
88754
|
+
const served = options.served();
|
|
88755
|
+
if (!token || served.size === 0) {
|
|
88756
|
+
if (socket) drop();
|
|
88757
|
+
return;
|
|
88758
|
+
}
|
|
88759
|
+
if (!socket) {
|
|
88760
|
+
if (Date.now() >= nextAttempt) connect(token, served);
|
|
88761
|
+
return;
|
|
88762
|
+
}
|
|
88763
|
+
const ids = idsOf(served).join("\n");
|
|
88764
|
+
if (socket.readyState === wrapper_default.OPEN && ids !== announced) {
|
|
88765
|
+
announced = ids;
|
|
88766
|
+
send2({ t: "ids", ids: idsOf(served) });
|
|
88767
|
+
}
|
|
88768
|
+
};
|
|
88769
|
+
const poll = setInterval(tick, options.pollMs ?? 5e3);
|
|
88770
|
+
tick();
|
|
88771
|
+
return {
|
|
88772
|
+
emit(key2, body) {
|
|
88773
|
+
for (const [id2, servedKey] of options.served()) if (servedKey === key2 && watched.has(id2)) send2({ t: "event", id: id2, body });
|
|
88774
|
+
},
|
|
88775
|
+
refresh: tick,
|
|
88776
|
+
close() {
|
|
88777
|
+
closed = true;
|
|
88778
|
+
clearInterval(poll);
|
|
88779
|
+
drop();
|
|
88780
|
+
}
|
|
88781
|
+
};
|
|
88782
|
+
}
|
|
88783
|
+
|
|
85024
88784
|
// src/server/avatars.ts
|
|
85025
88785
|
var import_node_crypto3 = require("node:crypto");
|
|
85026
88786
|
var AVATAR_ROUTE = /^\/api\/avatar\/([a-z]+)\/([^/]+)$/;
|
|
@@ -85172,34 +88932,6 @@ function callbackPage(result) {
|
|
|
85172
88932
|
`;
|
|
85173
88933
|
}
|
|
85174
88934
|
|
|
85175
|
-
// src/server/credentials.ts
|
|
85176
|
-
var import_node_fs13 = __toESM(require("node:fs"), 1);
|
|
85177
|
-
var import_node_path13 = __toESM(require("node:path"), 1);
|
|
85178
|
-
function credentialsFile(env, platform, home) {
|
|
85179
|
-
if (platform === "win32" && env.APPDATA) return import_node_path13.default.join(env.APPDATA, "ryugi", "credentials.json");
|
|
85180
|
-
return import_node_path13.default.join(env.XDG_CONFIG_HOME || import_node_path13.default.join(home, ".config"), "ryugi", "credentials.json");
|
|
85181
|
-
}
|
|
85182
|
-
function readCredentials(file, origin) {
|
|
85183
|
-
let raw;
|
|
85184
|
-
try {
|
|
85185
|
-
raw = JSON.parse(import_node_fs13.default.readFileSync(file, "utf8"));
|
|
85186
|
-
} catch {
|
|
85187
|
-
return null;
|
|
85188
|
-
}
|
|
85189
|
-
if (typeof raw !== "object" || raw === null) return null;
|
|
85190
|
-
const { origin: savedOrigin, token, login } = raw;
|
|
85191
|
-
if (typeof savedOrigin !== "string" || typeof token !== "string" || typeof login !== "string") return null;
|
|
85192
|
-
if (savedOrigin !== origin) return null;
|
|
85193
|
-
return { origin: savedOrigin, token, login };
|
|
85194
|
-
}
|
|
85195
|
-
function writeCredentials(file, credentials) {
|
|
85196
|
-
import_node_fs13.default.mkdirSync(import_node_path13.default.dirname(file), { recursive: true, mode: 448 });
|
|
85197
|
-
writeJsonAtomic(file, credentials);
|
|
85198
|
-
}
|
|
85199
|
-
function clearCredentials(file) {
|
|
85200
|
-
import_node_fs13.default.rmSync(file, { force: true });
|
|
85201
|
-
}
|
|
85202
|
-
|
|
85203
88935
|
// src/server/pack.ts
|
|
85204
88936
|
var import_node_fs14 = __toESM(require("node:fs"), 1);
|
|
85205
88937
|
var import_node_path14 = __toESM(require("node:path"), 1);
|
|
@@ -85416,7 +89148,7 @@ function createCloudRoutes(options) {
|
|
|
85416
89148
|
const hashed = files.map((file) => ({ ...file, hash: import_node_crypto4.default.createHash("sha256").update(file.data).digest("hex") }));
|
|
85417
89149
|
const byHash = new Map(hashed.map((file) => [file.hash, file.data]));
|
|
85418
89150
|
const manifest = hashed.map(({ path: path20, hash }) => ({ path: path20, hash }));
|
|
85419
|
-
const
|
|
89151
|
+
const version2 = (visibility) => ({ title: inspected.title, payload: inspected.payload, files: manifest, project, ...visibility ? { visibility } : {} });
|
|
85420
89152
|
const create3 = async () => {
|
|
85421
89153
|
const res2 = await cloudFetch("POST", "/api/artifacts", { type: ref.type, visibility: requested ?? entry.visibility ?? "private", project });
|
|
85422
89154
|
if (res2.status === 403) throw new CreateRefused(await errorMessage(res2));
|
|
@@ -85439,12 +89171,12 @@ function createCloudRoutes(options) {
|
|
|
85439
89171
|
}
|
|
85440
89172
|
};
|
|
85441
89173
|
const commit = async (id2, visibility) => {
|
|
85442
|
-
const res2 = await cloudFetch("POST", `/api/artifacts/${id2}/versions`,
|
|
89174
|
+
const res2 = await cloudFetch("POST", `/api/artifacts/${id2}/versions`, version2(visibility));
|
|
85443
89175
|
if (res2.status !== 409) return res2;
|
|
85444
89176
|
const { missing } = await res2.clone().json().catch(() => ({}));
|
|
85445
89177
|
if (!Array.isArray(missing)) return res2;
|
|
85446
89178
|
await upload(id2, missing);
|
|
85447
|
-
return cloudFetch("POST", `/api/artifacts/${id2}/versions`,
|
|
89179
|
+
return cloudFetch("POST", `/api/artifacts/${id2}/versions`, version2(visibility));
|
|
85448
89180
|
};
|
|
85449
89181
|
let res = entry.cloud ? await commit(entry.cloud.id, requested) : await commit(await create3(), void 0);
|
|
85450
89182
|
if (res.status === 404 && entry.cloud) {
|
|
@@ -86072,9 +89804,11 @@ async function startArtifactsServer(options) {
|
|
|
86072
89804
|
const touch = () => activityListeners.forEach((listener) => listener());
|
|
86073
89805
|
let port = 0;
|
|
86074
89806
|
let cookieName = "";
|
|
89807
|
+
let relay = null;
|
|
86075
89808
|
const broadcast = (message) => {
|
|
86076
89809
|
const frame = textFrame(JSON.stringify(message));
|
|
86077
89810
|
for (const socket of clients) socket.write(frame);
|
|
89811
|
+
relay?.emit(message.artifact, message);
|
|
86078
89812
|
};
|
|
86079
89813
|
const avatars = createAvatars(options.fetch);
|
|
86080
89814
|
const names = commentNames({ agentFile: import_node_path18.default.join(stateDir, "agent"), projectDir: import_node_path18.default.resolve(root, "../.."), cloud: options.cloud });
|
|
@@ -86136,6 +89870,14 @@ async function startArtifactsServer(options) {
|
|
|
86136
89870
|
return null;
|
|
86137
89871
|
}
|
|
86138
89872
|
};
|
|
89873
|
+
const documentState = (id2, session) => ({
|
|
89874
|
+
snapshot: Buffer.from(session.snapshot()).toString("base64"),
|
|
89875
|
+
lineage: session.lineage(),
|
|
89876
|
+
outcome: session.outcome(),
|
|
89877
|
+
streaming: session.streaming(),
|
|
89878
|
+
cursor: session.cursor(),
|
|
89879
|
+
comments: documents.comments(id2)
|
|
89880
|
+
});
|
|
86139
89881
|
const serveDocumentApi = async (req, res, id2, action) => {
|
|
86140
89882
|
if (action !== "state" && (req.method !== "POST" || !sameOrigin(req))) {
|
|
86141
89883
|
send(res, 403, "Forbidden");
|
|
@@ -86160,14 +89902,7 @@ async function startArtifactsServer(options) {
|
|
|
86160
89902
|
return;
|
|
86161
89903
|
}
|
|
86162
89904
|
if (action === "state") {
|
|
86163
|
-
sendJson(res, 200,
|
|
86164
|
-
snapshot: Buffer.from(session.snapshot()).toString("base64"),
|
|
86165
|
-
lineage: session.lineage(),
|
|
86166
|
-
outcome: session.outcome(),
|
|
86167
|
-
streaming: session.streaming(),
|
|
86168
|
-
cursor: session.cursor(),
|
|
86169
|
-
comments: documents.comments(id2)
|
|
86170
|
-
});
|
|
89905
|
+
sendJson(res, 200, documentState(id2, session));
|
|
86171
89906
|
return;
|
|
86172
89907
|
}
|
|
86173
89908
|
if (Number(req.headers["content-length"] ?? 0) > MAX_DOCUMENT_UPDATE) {
|
|
@@ -86282,14 +90017,18 @@ async function startArtifactsServer(options) {
|
|
|
86282
90017
|
}
|
|
86283
90018
|
});
|
|
86284
90019
|
};
|
|
90020
|
+
const artifactMeta = (ref, dir) => ({
|
|
90021
|
+
...readArtifact(dir, ref, runtimeOf(ref, dir)),
|
|
90022
|
+
...ref.type !== "html" ? { agent: names.agent() } : {},
|
|
90023
|
+
contentBase: `${contentPrefix}${ref.type}/${ref.id}/`
|
|
90024
|
+
});
|
|
86285
90025
|
const serveArtifactApi = (res, type, id2) => {
|
|
86286
90026
|
const dir = resolveArtifactDir(root, type, id2);
|
|
86287
90027
|
if (!dir) {
|
|
86288
90028
|
sendJson(res, 404, { warnings: [`artifact ${type}/${id2} not found`] });
|
|
86289
90029
|
return;
|
|
86290
90030
|
}
|
|
86291
|
-
|
|
86292
|
-
sendJson(res, 200, { ...readArtifact(dir, ref, runtimeOf(ref, dir)), ...ref.type !== "html" ? { agent: names.agent() } : {}, contentBase: `${contentPrefix}${type}/${id2}/` });
|
|
90031
|
+
sendJson(res, 200, artifactMeta(artifactKeyOf(`${type}/${id2}`), dir));
|
|
86293
90032
|
};
|
|
86294
90033
|
const serveList = (res) => {
|
|
86295
90034
|
const { artifacts, warnings } = listArtifacts(root);
|
|
@@ -86313,7 +90052,7 @@ async function startArtifactsServer(options) {
|
|
|
86313
90052
|
selections.accept(socket, message);
|
|
86314
90053
|
return;
|
|
86315
90054
|
}
|
|
86316
|
-
const { type, artifact, message: detail, version, file } = message;
|
|
90055
|
+
const { type, artifact, message: detail, version: version2, file } = message;
|
|
86317
90056
|
if (typeof artifact !== "string") return;
|
|
86318
90057
|
const ref = artifactKeyOf(artifact);
|
|
86319
90058
|
if (!ref || ref.type === "artboard" || artifact !== `${ref.type}/${ref.id}`) return;
|
|
@@ -86333,8 +90072,8 @@ async function startArtifactsServer(options) {
|
|
|
86333
90072
|
return;
|
|
86334
90073
|
}
|
|
86335
90074
|
if (type === "loaded") {
|
|
86336
|
-
if (typeof
|
|
86337
|
-
ranVersions.set(artifact,
|
|
90075
|
+
if (typeof version2 !== "number" || version2 !== readHtml(dir, ref.id).version) return;
|
|
90076
|
+
ranVersions.set(artifact, version2);
|
|
86338
90077
|
writeState(ref, dir);
|
|
86339
90078
|
return;
|
|
86340
90079
|
}
|
|
@@ -86539,6 +90278,60 @@ async function startArtifactsServer(options) {
|
|
|
86539
90278
|
if (entry.type === "document") void documents.open(entry.id);
|
|
86540
90279
|
}
|
|
86541
90280
|
writeJsonAtomic(import_node_path18.default.join(stateDir, "server-info"), { type: "server-started", url, port, root });
|
|
90281
|
+
const relayViewers = /* @__PURE__ */ new Map();
|
|
90282
|
+
const servedDocuments = () => {
|
|
90283
|
+
const served = /* @__PURE__ */ new Map();
|
|
90284
|
+
if (!options.configFile) return served;
|
|
90285
|
+
for (const [key2, entry] of Object.entries(readConfig(options.configFile).config.artifacts)) {
|
|
90286
|
+
const ref = artifactKeyOf(key2);
|
|
90287
|
+
if (entry.cloud && ref?.type === "document" && resolveArtifactDir(root, "document", ref.id)) served.set(entry.cloud.id, key2);
|
|
90288
|
+
}
|
|
90289
|
+
return served;
|
|
90290
|
+
};
|
|
90291
|
+
const handleRelay = async (key2, body, conn) => {
|
|
90292
|
+
const ref = artifactKeyOf(key2);
|
|
90293
|
+
const dir = resolveArtifactDir(root, ref.type, ref.id);
|
|
90294
|
+
if (!dir) throw new Error(`${key2} not found`);
|
|
90295
|
+
const request = typeof body === "object" && body !== null ? body : {};
|
|
90296
|
+
if (request.op === "meta") return artifactMeta(ref, dir);
|
|
90297
|
+
if (request.op === "state" || request.op === "update") {
|
|
90298
|
+
const session = await documents.open(ref.id);
|
|
90299
|
+
if (!session) throw new Error(`${key2} has no doc.xml`);
|
|
90300
|
+
if (request.op === "state") return documentState(ref.id, session);
|
|
90301
|
+
const bytes = typeof request.bytes === "string" ? Buffer.from(request.bytes, "base64") : null;
|
|
90302
|
+
if (!bytes) throw new Error("update needs bytes");
|
|
90303
|
+
if (bytes.length > MAX_DOCUMENT_UPDATE) throw new Error("update too large");
|
|
90304
|
+
session.importUpdate(new Uint8Array(bytes));
|
|
90305
|
+
return null;
|
|
90306
|
+
}
|
|
90307
|
+
if (request.op === "comment") {
|
|
90308
|
+
const op = JSON.stringify(request.comment ?? null).length <= MAX_COMMENT_OP ? asHumanOp(request.comment) : null;
|
|
90309
|
+
if (!op) throw new Error("not a comment op");
|
|
90310
|
+
return { comments: documents.applyCommentOp(ref.id, op) };
|
|
90311
|
+
}
|
|
90312
|
+
if (request.op === "selection") {
|
|
90313
|
+
if (typeof request.selection !== "object" || request.selection === null) throw new Error("not a selection");
|
|
90314
|
+
const viewer = relayViewers.get(conn) ?? { key: key2, tab: {} };
|
|
90315
|
+
relayViewers.set(conn, viewer);
|
|
90316
|
+
selections.accept(viewer.tab, { ...request.selection, artifact: key2 });
|
|
90317
|
+
return null;
|
|
90318
|
+
}
|
|
90319
|
+
throw new Error("unknown request");
|
|
90320
|
+
};
|
|
90321
|
+
relay = options.relay && options.cloud ? createRelayClient({
|
|
90322
|
+
...options.relay,
|
|
90323
|
+
token: () => readCredentials(options.cloud.credentialsFile, options.cloud.origin)?.token ?? null,
|
|
90324
|
+
served: servedDocuments,
|
|
90325
|
+
handle: handleRelay,
|
|
90326
|
+
onActivity: touch,
|
|
90327
|
+
onWatch: (keys2) => {
|
|
90328
|
+
for (const [conn, viewer] of relayViewers) {
|
|
90329
|
+
if (keys2.has(viewer.key)) continue;
|
|
90330
|
+
selections.drop(viewer.tab);
|
|
90331
|
+
relayViewers.delete(conn);
|
|
90332
|
+
}
|
|
90333
|
+
}
|
|
90334
|
+
}) : null;
|
|
86542
90335
|
const watcher = watchTree(
|
|
86543
90336
|
root,
|
|
86544
90337
|
(files) => {
|
|
@@ -86569,6 +90362,7 @@ async function startArtifactsServer(options) {
|
|
|
86569
90362
|
const payload = refreshState(ref, dir);
|
|
86570
90363
|
const frame = textFrame(JSON.stringify({ type: "change", artifact: key2, files: changed }));
|
|
86571
90364
|
for (const socket of clients) socket.write(frame);
|
|
90365
|
+
relay?.emit(key2, { type: "change", artifact: key2, files: changed });
|
|
86572
90366
|
changeListeners.forEach((listener) => listener(ref, payload, changed));
|
|
86573
90367
|
}
|
|
86574
90368
|
touch();
|
|
@@ -86589,6 +90383,7 @@ async function startArtifactsServer(options) {
|
|
|
86589
90383
|
onActivity: (listener) => activityListeners.push(listener),
|
|
86590
90384
|
close: () => new Promise((resolve) => {
|
|
86591
90385
|
watcher.close();
|
|
90386
|
+
relay?.close();
|
|
86592
90387
|
selections.clearAll();
|
|
86593
90388
|
for (const socket of clients) socket.destroy();
|
|
86594
90389
|
server.close(() => resolve());
|
|
@@ -86692,6 +90487,9 @@ function openReady(payload) {
|
|
|
86692
90487
|
return pageBoards.filter(([id2]) => ready(id2)).length >= 2;
|
|
86693
90488
|
}
|
|
86694
90489
|
|
|
90490
|
+
// package.json
|
|
90491
|
+
var version = "1.13.0";
|
|
90492
|
+
|
|
86695
90493
|
// src/server/main.ts
|
|
86696
90494
|
async function main() {
|
|
86697
90495
|
const config = parseEnv(process.env, process.argv.slice(2));
|
|
@@ -86704,7 +90502,8 @@ async function main() {
|
|
|
86704
90502
|
host: config.host,
|
|
86705
90503
|
urlHost: config.urlHost,
|
|
86706
90504
|
configFile: import_node_path19.default.join(import_node_path19.default.dirname(root), "config.json"),
|
|
86707
|
-
cloud: { origin: config.cloudOrigin, credentialsFile: credentialsFile(process.env, process.platform, import_node_os.default.homedir()) }
|
|
90505
|
+
cloud: { origin: config.cloudOrigin, credentialsFile: credentialsFile(process.env, process.platform, import_node_os.default.homedir()) },
|
|
90506
|
+
relay: { url: `${config.cloudOrigin.replace(/^http/, "ws")}/api/relay/host`, version }
|
|
86708
90507
|
});
|
|
86709
90508
|
let lastActivity = Date.now();
|
|
86710
90509
|
server.onActivity(() => {
|