nme-library 2.0.0-RC4
Sign up to get free protection for your applications and to get access to all the features.
- package/4xhj3q2e.cjs +1 -0
- package/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/src/NEMLibrary.d.ts +25 -0
- package/dist/src/NEMLibrary.js +69 -0
- package/dist/src/NEMLibrary.js.map +1 -0
- package/dist/src/infrastrcture.d.ts +13 -0
- package/dist/src/infrastrcture.js +44 -0
- package/dist/src/infrastrcture.js.map +1 -0
- package/dist/src/infrastructure/AccountHttp.d.ts +204 -0
- package/dist/src/infrastructure/AccountHttp.js +415 -0
- package/dist/src/infrastructure/AccountHttp.js.map +1 -0
- package/dist/src/infrastructure/AccountListener.d.ts +20 -0
- package/dist/src/infrastructure/AccountListener.js +71 -0
- package/dist/src/infrastructure/AccountListener.js.map +1 -0
- package/dist/src/infrastructure/AllTransactionsPageable.d.ts +1 -0
- package/dist/src/infrastructure/AllTransactionsPageable.js +35 -0
- package/dist/src/infrastructure/AllTransactionsPageable.js.map +1 -0
- package/dist/src/infrastructure/AssetHttp.d.ts +36 -0
- package/dist/src/infrastructure/AssetHttp.js +85 -0
- package/dist/src/infrastructure/AssetHttp.js.map +1 -0
- package/dist/src/infrastructure/BlockHttp.d.ts +14 -0
- package/dist/src/infrastructure/BlockHttp.js +54 -0
- package/dist/src/infrastructure/BlockHttp.js.map +1 -0
- package/dist/src/infrastructure/BlockchainListener.d.ts +24 -0
- package/dist/src/infrastructure/BlockchainListener.js +93 -0
- package/dist/src/infrastructure/BlockchainListener.js.map +1 -0
- package/dist/src/infrastructure/ChainHttp.d.ts +23 -0
- package/dist/src/infrastructure/ChainHttp.js +68 -0
- package/dist/src/infrastructure/ChainHttp.js.map +1 -0
- package/dist/src/infrastructure/ConfirmedTransactionListener.d.ts +20 -0
- package/dist/src/infrastructure/ConfirmedTransactionListener.js +76 -0
- package/dist/src/infrastructure/ConfirmedTransactionListener.js.map +1 -0
- package/dist/src/infrastructure/HarvestInfoPageable.d.ts +1 -0
- package/dist/src/infrastructure/HarvestInfoPageable.js +52 -0
- package/dist/src/infrastructure/HarvestInfoPageable.js.map +1 -0
- package/dist/src/infrastructure/HttpEndpoint.d.ts +15 -0
- package/dist/src/infrastructure/HttpEndpoint.js +132 -0
- package/dist/src/infrastructure/HttpEndpoint.js.map +1 -0
- package/dist/src/infrastructure/IncomingTransactionsPageable.d.ts +1 -0
- package/dist/src/infrastructure/IncomingTransactionsPageable.js +29 -0
- package/dist/src/infrastructure/IncomingTransactionsPageable.js.map +1 -0
- package/dist/src/infrastructure/Listener.d.ts +14 -0
- package/dist/src/infrastructure/Listener.js +101 -0
- package/dist/src/infrastructure/Listener.js.map +1 -0
- package/dist/src/infrastructure/NamespaceHttp.d.ts +27 -0
- package/dist/src/infrastructure/NamespaceHttp.js +78 -0
- package/dist/src/infrastructure/NamespaceHttp.js.map +1 -0
- package/dist/src/infrastructure/NamespacesPageable.d.ts +1 -0
- package/dist/src/infrastructure/NamespacesPageable.js +28 -0
- package/dist/src/infrastructure/NamespacesPageable.js.map +1 -0
- package/dist/src/infrastructure/NodeHttp.d.ts +45 -0
- package/dist/src/infrastructure/NodeHttp.js +116 -0
- package/dist/src/infrastructure/NodeHttp.js.map +1 -0
- package/dist/src/infrastructure/OutgoingTransactionsPageable.d.ts +1 -0
- package/dist/src/infrastructure/OutgoingTransactionsPageable.js +59 -0
- package/dist/src/infrastructure/OutgoingTransactionsPageable.js.map +1 -0
- package/dist/src/infrastructure/Pageable.d.ts +10 -0
- package/dist/src/infrastructure/Pageable.js +55 -0
- package/dist/src/infrastructure/Pageable.js.map +1 -0
- package/dist/src/infrastructure/TransactionHttp.d.ts +20 -0
- package/dist/src/infrastructure/TransactionHttp.js +68 -0
- package/dist/src/infrastructure/TransactionHttp.js.map +1 -0
- package/dist/src/infrastructure/UnconfirmedTransactionListener.d.ts +20 -0
- package/dist/src/infrastructure/UnconfirmedTransactionListener.js +76 -0
- package/dist/src/infrastructure/UnconfirmedTransactionListener.js.map +1 -0
- package/dist/src/infrastructure/account/AccountHistoricalDataViewModelDTO.d.ts +1 -0
- package/dist/src/infrastructure/account/AccountHistoricalDataViewModelDTO.js +26 -0
- package/dist/src/infrastructure/account/AccountHistoricalDataViewModelDTO.js.map +1 -0
- package/dist/src/infrastructure/account/AccountImportanceViewModelDTO.d.ts +1 -0
- package/dist/src/infrastructure/account/AccountImportanceViewModelDTO.js +26 -0
- package/dist/src/infrastructure/account/AccountImportanceViewModelDTO.js.map +1 -0
- package/dist/src/infrastructure/account/AccountInfoDTO.d.ts +10 -0
- package/dist/src/infrastructure/account/AccountInfoDTO.js +26 -0
- package/dist/src/infrastructure/account/AccountInfoDTO.js.map +1 -0
- package/dist/src/infrastructure/account/AccountMetaDataDTO.d.ts +1 -0
- package/dist/src/infrastructure/account/AccountMetaDataDTO.js +26 -0
- package/dist/src/infrastructure/account/AccountMetaDataDTO.js.map +1 -0
- package/dist/src/infrastructure/account/AccountMetaDataPairDTO.d.ts +1 -0
- package/dist/src/infrastructure/account/AccountMetaDataPairDTO.js +26 -0
- package/dist/src/infrastructure/account/AccountMetaDataPairDTO.js.map +1 -0
- package/dist/src/infrastructure/account/AccountPrivateKeyTransactionsPageDTO.d.ts +1 -0
- package/dist/src/infrastructure/account/AccountPrivateKeyTransactionsPageDTO.js +26 -0
- package/dist/src/infrastructure/account/AccountPrivateKeyTransactionsPageDTO.js.map +1 -0
- package/dist/src/infrastructure/account/HarvestInfoDTO.d.ts +1 -0
- package/dist/src/infrastructure/account/HarvestInfoDTO.js +26 -0
- package/dist/src/infrastructure/account/HarvestInfoDTO.js.map +1 -0
- package/dist/src/infrastructure/account/KeyPairViewModelDTO.d.ts +1 -0
- package/dist/src/infrastructure/account/KeyPairViewModelDTO.js +26 -0
- package/dist/src/infrastructure/account/KeyPairViewModelDTO.js.map +1 -0
- package/dist/src/infrastructure/account/PrivateKeyDTO.d.ts +1 -0
- package/dist/src/infrastructure/account/PrivateKeyDTO.js +26 -0
- package/dist/src/infrastructure/account/PrivateKeyDTO.js.map +1 -0
- package/dist/src/infrastructure/asset/MosaicDTO.d.ts +1 -0
- package/dist/src/infrastructure/asset/MosaicDTO.js +26 -0
- package/dist/src/infrastructure/asset/MosaicDTO.js.map +1 -0
- package/dist/src/infrastructure/asset/MosaicDefinitionDTO.d.ts +1 -0
- package/dist/src/infrastructure/asset/MosaicDefinitionDTO.js +26 -0
- package/dist/src/infrastructure/asset/MosaicDefinitionDTO.js.map +1 -0
- package/dist/src/infrastructure/asset/MosaicDefinitionMetaDataPairDTO.d.ts +1 -0
- package/dist/src/infrastructure/asset/MosaicDefinitionMetaDataPairDTO.js +26 -0
- package/dist/src/infrastructure/asset/MosaicDefinitionMetaDataPairDTO.js.map +1 -0
- package/dist/src/infrastructure/asset/MosaicIdDTO.d.ts +1 -0
- package/dist/src/infrastructure/asset/MosaicIdDTO.js +26 -0
- package/dist/src/infrastructure/asset/MosaicIdDTO.js.map +1 -0
- package/dist/src/infrastructure/asset/MosaicLevyDTO.d.ts +1 -0
- package/dist/src/infrastructure/asset/MosaicLevyDTO.js +26 -0
- package/dist/src/infrastructure/asset/MosaicLevyDTO.js.map +1 -0
- package/dist/src/infrastructure/asset/MosaicPropertyDTO.d.ts +8 -0
- package/dist/src/infrastructure/asset/MosaicPropertyDTO.js +26 -0
- package/dist/src/infrastructure/asset/MosaicPropertyDTO.js.map +1 -0
- package/dist/src/infrastructure/blockchain/BlockChainScoreDTO.d.ts +1 -0
- package/dist/src/infrastructure/blockchain/BlockChainScoreDTO.js +26 -0
- package/dist/src/infrastructure/blockchain/BlockChainScoreDTO.js.map +1 -0
- package/dist/src/infrastructure/blockchain/BlockDTO.d.ts +6 -0
- package/dist/src/infrastructure/blockchain/BlockDTO.js +26 -0
- package/dist/src/infrastructure/blockchain/BlockDTO.js.map +1 -0
- package/dist/src/infrastructure/blockchain/BlockHeightDTO.d.ts +1 -0
- package/dist/src/infrastructure/blockchain/BlockHeightDTO.js +26 -0
- package/dist/src/infrastructure/blockchain/BlockHeightDTO.js.map +1 -0
- package/dist/src/infrastructure/blockchain/ExplorerBlockViewModelDTO.d.ts +1 -0
- package/dist/src/infrastructure/blockchain/ExplorerBlockViewModelDTO.js +26 -0
- package/dist/src/infrastructure/blockchain/ExplorerBlockViewModelDTO.js.map +1 -0
- package/dist/src/infrastructure/debug/AuditCollectionDTO.d.ts +22 -0
- package/dist/src/infrastructure/debug/AuditCollectionDTO.js +26 -0
- package/dist/src/infrastructure/debug/AuditCollectionDTO.js.map +1 -0
- package/dist/src/infrastructure/debug/NemAsyncTimerVisitorDTO.d.ts +1 -0
- package/dist/src/infrastructure/debug/NemAsyncTimerVisitorDTO.js +26 -0
- package/dist/src/infrastructure/debug/NemAsyncTimerVisitorDTO.js.map +1 -0
- package/dist/src/infrastructure/debug/NisNodeInfoDTO.d.ts +1 -0
- package/dist/src/infrastructure/debug/NisNodeInfoDTO.js +26 -0
- package/dist/src/infrastructure/debug/NisNodeInfoDTO.js.map +1 -0
- package/dist/src/infrastructure/debug/TimeSynchronizationResultDTO.d.ts +1 -0
- package/dist/src/infrastructure/debug/TimeSynchronizationResultDTO.js +26 -0
- package/dist/src/infrastructure/debug/TimeSynchronizationResultDTO.js.map +1 -0
- package/dist/src/infrastructure/namespace/NamespaceDTO.d.ts +1 -0
- package/dist/src/infrastructure/namespace/NamespaceDTO.js +26 -0
- package/dist/src/infrastructure/namespace/NamespaceDTO.js.map +1 -0
- package/dist/src/infrastructure/namespace/NamespaceMetaDataPairDTO.d.ts +1 -0
- package/dist/src/infrastructure/namespace/NamespaceMetaDataPairDTO.js +26 -0
- package/dist/src/infrastructure/namespace/NamespaceMetaDataPairDTO.js.map +1 -0
- package/dist/src/infrastructure/node/ApplicationMetaDataDTO.d.ts +1 -0
- package/dist/src/infrastructure/node/ApplicationMetaDataDTO.js +26 -0
- package/dist/src/infrastructure/node/ApplicationMetaDataDTO.js.map +1 -0
- package/dist/src/infrastructure/node/BootNodeRequestDTO.d.ts +1 -0
- package/dist/src/infrastructure/node/BootNodeRequestDTO.js +26 -0
- package/dist/src/infrastructure/node/BootNodeRequestDTO.js.map +1 -0
- package/dist/src/infrastructure/node/CommunicationTimeStampsDTO.d.ts +1 -0
- package/dist/src/infrastructure/node/CommunicationTimeStampsDTO.js +26 -0
- package/dist/src/infrastructure/node/CommunicationTimeStampsDTO.js.map +1 -0
- package/dist/src/infrastructure/node/ExtendedNodeExperiencePairDTO.d.ts +1 -0
- package/dist/src/infrastructure/node/ExtendedNodeExperiencePairDTO.js +26 -0
- package/dist/src/infrastructure/node/ExtendedNodeExperiencePairDTO.js.map +1 -0
- package/dist/src/infrastructure/node/NodeCollectionDTO.d.ts +1 -0
- package/dist/src/infrastructure/node/NodeCollectionDTO.js +26 -0
- package/dist/src/infrastructure/node/NodeCollectionDTO.js.map +1 -0
- package/dist/src/infrastructure/node/NodeDTO.d.ts +19 -0
- package/dist/src/infrastructure/node/NodeDTO.js +26 -0
- package/dist/src/infrastructure/node/NodeDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/CreateTransactionFromDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/CreateTransactionFromDTO.js +162 -0
- package/dist/src/infrastructure/transaction/CreateTransactionFromDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/CreateUnconfirmedTransactionFromDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/CreateUnconfirmedTransactionFromDTO.js +104 -0
- package/dist/src/infrastructure/transaction/CreateUnconfirmedTransactionFromDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/ErrorObjectDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/ErrorObjectDTO.js +26 -0
- package/dist/src/infrastructure/transaction/ErrorObjectDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/HashData.d.ts +10 -0
- package/dist/src/infrastructure/transaction/HashData.js +26 -0
- package/dist/src/infrastructure/transaction/HashData.js.map +1 -0
- package/dist/src/infrastructure/transaction/ImportanceTransferTransactionDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/ImportanceTransferTransactionDTO.js +26 -0
- package/dist/src/infrastructure/transaction/ImportanceTransferTransactionDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/Message.d.ts +1 -0
- package/dist/src/infrastructure/transaction/Message.js +26 -0
- package/dist/src/infrastructure/transaction/Message.js.map +1 -0
- package/dist/src/infrastructure/transaction/MosaicDefinitionCreationTransactionDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/MosaicDefinitionCreationTransactionDTO.js +26 -0
- package/dist/src/infrastructure/transaction/MosaicDefinitionCreationTransactionDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/MosaicSupplyChangeTransactionDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/MosaicSupplyChangeTransactionDTO.js +26 -0
- package/dist/src/infrastructure/transaction/MosaicSupplyChangeTransactionDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/MultisigAggregateModificationTransactionDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/MultisigAggregateModificationTransactionDTO.js +26 -0
- package/dist/src/infrastructure/transaction/MultisigAggregateModificationTransactionDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/MultisigCosignatoryModificationDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/MultisigCosignatoryModificationDTO.js +26 -0
- package/dist/src/infrastructure/transaction/MultisigCosignatoryModificationDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/MultisigSignatureTransactionDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/MultisigSignatureTransactionDTO.js +26 -0
- package/dist/src/infrastructure/transaction/MultisigSignatureTransactionDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/MultisigTransactionDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/MultisigTransactionDTO.js +26 -0
- package/dist/src/infrastructure/transaction/MultisigTransactionDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/NemAnnounceResultDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/NemAnnounceResultDTO.js +26 -0
- package/dist/src/infrastructure/transaction/NemAnnounceResultDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/NemRequestResultDTO.d.ts +10 -0
- package/dist/src/infrastructure/transaction/NemRequestResultDTO.js +26 -0
- package/dist/src/infrastructure/transaction/NemRequestResultDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/ProvisionNamespaceTransactionDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/ProvisionNamespaceTransactionDTO.js +26 -0
- package/dist/src/infrastructure/transaction/ProvisionNamespaceTransactionDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/RequestPrepareAnnonceDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/RequestPrepareAnnonceDTO.js +26 -0
- package/dist/src/infrastructure/transaction/RequestPrepareAnnonceDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/TransactionDTO.d.ts +31 -0
- package/dist/src/infrastructure/transaction/TransactionDTO.js +26 -0
- package/dist/src/infrastructure/transaction/TransactionDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/TransactionMetaDataDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/TransactionMetaDataDTO.js +26 -0
- package/dist/src/infrastructure/transaction/TransactionMetaDataDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/TransactionMetaDataPairDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/TransactionMetaDataPairDTO.js +26 -0
- package/dist/src/infrastructure/transaction/TransactionMetaDataPairDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/TransferTransactionDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/TransferTransactionDTO.js +26 -0
- package/dist/src/infrastructure/transaction/TransferTransactionDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/UnconfirmedTransactionMetaDataDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/UnconfirmedTransactionMetaDataDTO.js +26 -0
- package/dist/src/infrastructure/transaction/UnconfirmedTransactionMetaDataDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/UnconfirmedTransactionMetaDataPairDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/UnconfirmedTransactionMetaDataPairDTO.js +26 -0
- package/dist/src/infrastructure/transaction/UnconfirmedTransactionMetaDataPairDTO.js.map +1 -0
- package/dist/src/infrastructure/transaction/UnconfirmedTransactionsDTO.d.ts +1 -0
- package/dist/src/infrastructure/transaction/UnconfirmedTransactionsDTO.js +26 -0
- package/dist/src/infrastructure/transaction/UnconfirmedTransactionsDTO.js.map +1 -0
- package/dist/src/models/account/Account.d.ts +52 -0
- package/dist/src/models/account/Account.js +136 -0
- package/dist/src/models/account/Account.js.map +1 -0
- package/dist/src/models/account/AccountHarvestInfo.d.ts +25 -0
- package/dist/src/models/account/AccountHarvestInfo.js +55 -0
- package/dist/src/models/account/AccountHarvestInfo.js.map +1 -0
- package/dist/src/models/account/AccountHistoricalInfo.d.ts +25 -0
- package/dist/src/models/account/AccountHistoricalInfo.js +58 -0
- package/dist/src/models/account/AccountHistoricalInfo.js.map +1 -0
- package/dist/src/models/account/AccountImportanceInfo.d.ts +35 -0
- package/dist/src/models/account/AccountImportanceInfo.js +77 -0
- package/dist/src/models/account/AccountImportanceInfo.js.map +1 -0
- package/dist/src/models/account/AccountInfo.d.ts +79 -0
- package/dist/src/models/account/AccountInfo.js +129 -0
- package/dist/src/models/account/AccountInfo.js.map +1 -0
- package/dist/src/models/account/Address.d.ts +25 -0
- package/dist/src/models/account/Address.js +80 -0
- package/dist/src/models/account/Address.js.map +1 -0
- package/dist/src/models/account/Balance.d.ts +17 -0
- package/dist/src/models/account/Balance.js +42 -0
- package/dist/src/models/account/Balance.js.map +1 -0
- package/dist/src/models/account/NodeHarvestInfo.d.ts +10 -0
- package/dist/src/models/account/NodeHarvestInfo.js +38 -0
- package/dist/src/models/account/NodeHarvestInfo.js.map +1 -0
- package/dist/src/models/account/PublicAccount.d.ts +25 -0
- package/dist/src/models/account/PublicAccount.js +82 -0
- package/dist/src/models/account/PublicAccount.js.map +1 -0
- package/dist/src/models/asset/Asset.d.ts +20 -0
- package/dist/src/models/asset/Asset.js +59 -0
- package/dist/src/models/asset/Asset.js.map +1 -0
- package/dist/src/models/asset/AssetDefinition.d.ts +83 -0
- package/dist/src/models/asset/AssetDefinition.js +136 -0
- package/dist/src/models/asset/AssetDefinition.js.map +1 -0
- package/dist/src/models/asset/AssetId.d.ts +31 -0
- package/dist/src/models/asset/AssetId.js +77 -0
- package/dist/src/models/asset/AssetId.js.map +1 -0
- package/dist/src/models/asset/AssetLevy.d.ts +40 -0
- package/dist/src/models/asset/AssetLevy.js +76 -0
- package/dist/src/models/asset/AssetLevy.js.map +1 -0
- package/dist/src/models/asset/AssetTransferable.d.ts +65 -0
- package/dist/src/models/asset/AssetTransferable.js +88 -0
- package/dist/src/models/asset/AssetTransferable.js.map +1 -0
- package/dist/src/models/asset/XEM.d.ts +49 -0
- package/dist/src/models/asset/XEM.js +83 -0
- package/dist/src/models/asset/XEM.js.map +1 -0
- package/dist/src/models/blockchain/Block.d.ts +57 -0
- package/dist/src/models/blockchain/Block.js +81 -0
- package/dist/src/models/blockchain/Block.js.map +1 -0
- package/dist/src/models/namespace/Namespace.d.ts +23 -0
- package/dist/src/models/namespace/Namespace.js +64 -0
- package/dist/src/models/namespace/Namespace.js.map +1 -0
- package/dist/src/models/node/ExtendedNodeExperience.d.ts +34 -0
- package/dist/src/models/node/ExtendedNodeExperience.js +79 -0
- package/dist/src/models/node/ExtendedNodeExperience.js.map +1 -0
- package/dist/src/models/node/NetworkTypes.d.ts +17 -0
- package/dist/src/models/node/NetworkTypes.js +44 -0
- package/dist/src/models/node/NetworkTypes.js.map +1 -0
- package/dist/src/models/node/NisNodeInfo.d.ts +39 -0
- package/dist/src/models/node/NisNodeInfo.js +79 -0
- package/dist/src/models/node/NisNodeInfo.js.map +1 -0
- package/dist/src/models/node/Node.d.ts +76 -0
- package/dist/src/models/node/Node.js +131 -0
- package/dist/src/models/node/Node.js.map +1 -0
- package/dist/src/models/node/NodeCollection.d.ts +22 -0
- package/dist/src/models/node/NodeCollection.js +54 -0
- package/dist/src/models/node/NodeCollection.js.map +1 -0
- package/dist/src/models/transaction/AssetDefinitionCreationTransaction.d.ts +39 -0
- package/dist/src/models/transaction/AssetDefinitionCreationTransaction.js +94 -0
- package/dist/src/models/transaction/AssetDefinitionCreationTransaction.js.map +1 -0
- package/dist/src/models/transaction/AssetSupplyChangeTransaction.d.ts +48 -0
- package/dist/src/models/transaction/AssetSupplyChangeTransaction.js +94 -0
- package/dist/src/models/transaction/AssetSupplyChangeTransaction.js.map +1 -0
- package/dist/src/models/transaction/EncryptedMessage.d.ts +8 -0
- package/dist/src/models/transaction/EncryptedMessage.js +86 -0
- package/dist/src/models/transaction/EncryptedMessage.js.map +1 -0
- package/dist/src/models/transaction/HexMessage.d.ts +10 -0
- package/dist/src/models/transaction/HexMessage.js +37 -0
- package/dist/src/models/transaction/HexMessage.js.map +1 -0
- package/dist/src/models/transaction/ImportanceTransferTransaction.d.ts +45 -0
- package/dist/src/models/transaction/ImportanceTransferTransaction.js +92 -0
- package/dist/src/models/transaction/ImportanceTransferTransaction.js.map +1 -0
- package/dist/src/models/transaction/Message.d.ts +12 -0
- package/dist/src/models/transaction/Message.js +110 -0
- package/dist/src/models/transaction/Message.js.map +1 -0
- package/dist/src/models/transaction/MultisigAggregateModificationTransaction.d.ts +55 -0
- package/dist/src/models/transaction/MultisigAggregateModificationTransaction.js +112 -0
- package/dist/src/models/transaction/MultisigAggregateModificationTransaction.js.map +1 -0
- package/dist/src/models/transaction/MultisigSignatureTransaction.d.ts +35 -0
- package/dist/src/models/transaction/MultisigSignatureTransaction.js +92 -0
- package/dist/src/models/transaction/MultisigSignatureTransaction.js.map +1 -0
- package/dist/src/models/transaction/MultisigTransaction.d.ts +49 -0
- package/dist/src/models/transaction/MultisigTransaction.js +102 -0
- package/dist/src/models/transaction/MultisigTransaction.js.map +1 -0
- package/dist/src/models/transaction/NemAnnounceResult.d.ts +77 -0
- package/dist/src/models/transaction/NemAnnounceResult.js +66 -0
- package/dist/src/models/transaction/NemAnnounceResult.js.map +1 -0
- package/dist/src/models/transaction/PlainMessage.d.ts +19 -0
- package/dist/src/models/transaction/PlainMessage.js +77 -0
- package/dist/src/models/transaction/PlainMessage.js.map +1 -0
- package/dist/src/models/transaction/ProvisionNamespaceTransaction.d.ts +57 -0
- package/dist/src/models/transaction/ProvisionNamespaceTransaction.js +117 -0
- package/dist/src/models/transaction/ProvisionNamespaceTransaction.js.map +1 -0
- package/dist/src/models/transaction/SignedTransaction.d.ts +13 -0
- package/dist/src/models/transaction/SignedTransaction.js +26 -0
- package/dist/src/models/transaction/SignedTransaction.js.map +1 -0
- package/dist/src/models/transaction/TimeWindow.d.ts +24 -0
- package/dist/src/models/transaction/TimeWindow.js +84 -0
- package/dist/src/models/transaction/TimeWindow.js.map +1 -0
- package/dist/src/models/transaction/Transaction.d.ts +56 -0
- package/dist/src/models/transaction/Transaction.js +98 -0
- package/dist/src/models/transaction/Transaction.js.map +1 -0
- package/dist/src/models/transaction/TransactionInfo.d.ts +39 -0
- package/dist/src/models/transaction/TransactionInfo.js +60 -0
- package/dist/src/models/transaction/TransactionInfo.js.map +1 -0
- package/dist/src/models/transaction/TransactionTypes.d.ts +80 -0
- package/dist/src/models/transaction/TransactionTypes.js +159 -0
- package/dist/src/models/transaction/TransactionTypes.js.map +1 -0
- package/dist/src/models/transaction/TransferTransaction.d.ts +78 -0
- package/dist/src/models/transaction/TransferTransaction.js +176 -0
- package/dist/src/models/transaction/TransferTransaction.js.map +1 -0
- package/dist/src/models/wallet/BrainPassword.d.ts +11 -0
- package/dist/src/models/wallet/BrainPassword.js +42 -0
- package/dist/src/models/wallet/BrainPassword.js.map +1 -0
- package/dist/src/models/wallet/BrainWallet.d.ts +34 -0
- package/dist/src/models/wallet/BrainWallet.js +101 -0
- package/dist/src/models/wallet/BrainWallet.js.map +1 -0
- package/dist/src/models/wallet/EncryptedPrivateKey.d.ts +13 -0
- package/dist/src/models/wallet/EncryptedPrivateKey.js +56 -0
- package/dist/src/models/wallet/EncryptedPrivateKey.js.map +1 -0
- package/dist/src/models/wallet/Password.d.ts +14 -0
- package/dist/src/models/wallet/Password.js +41 -0
- package/dist/src/models/wallet/Password.js.map +1 -0
- package/dist/src/models/wallet/SimpleWallet.d.ts +47 -0
- package/dist/src/models/wallet/SimpleWallet.js +143 -0
- package/dist/src/models/wallet/SimpleWallet.js.map +1 -0
- package/dist/src/models/wallet/Wallet.d.ts +51 -0
- package/dist/src/models/wallet/Wallet.js +81 -0
- package/dist/src/models/wallet/Wallet.js.map +1 -0
- package/dist/src/models.d.ts +46 -0
- package/dist/src/models.js +74 -0
- package/dist/src/models.js.map +1 -0
- package/dist/src/services/AccountOwnedAssetService.d.ts +30 -0
- package/dist/src/services/AccountOwnedAssetService.js +63 -0
- package/dist/src/services/AccountOwnedAssetService.js.map +1 -0
- package/dist/src/services/AssetService.d.ts +23 -0
- package/dist/src/services/AssetService.js +87 -0
- package/dist/src/services/AssetService.js.map +1 -0
- package/dist/src/services/QRService.d.ts +66 -0
- package/dist/src/services/QRService.js +155 -0
- package/dist/src/services/QRService.js.map +1 -0
- package/dist/src/services.d.ts +3 -0
- package/dist/src/services.js +32 -0
- package/dist/src/services.js.map +1 -0
- package/dist/src/vendor/sockjs-0.3.4.d.ts +25 -0
- package/dist/src/vendor/sockjs-0.3.4.js +2516 -0
- package/dist/src/vendor/sockjs-0.3.4.min.js +27 -0
- package/package.json +87 -0
@@ -0,0 +1,2516 @@
|
|
1
|
+
/* SockJS client, version 0.3.4, http://sockjs.org, MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011-2012 VMware, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
*/
|
23
|
+
|
24
|
+
// JSON2 by Douglas Crockford (minified).
|
25
|
+
var JSON;
|
26
|
+
JSON || (JSON = {}), function () {
|
27
|
+
function str(a, b) {
|
28
|
+
var c, d, e, f, g = gap, h, i = b[a];
|
29
|
+
i && typeof i == "object" && typeof i.toJSON == "function" && (i = i.toJSON(a)), typeof rep == "function" && (i = rep.call(b, a, i));
|
30
|
+
switch (typeof i) {
|
31
|
+
case"string":
|
32
|
+
return quote(i);
|
33
|
+
case"number":
|
34
|
+
return isFinite(i) ? String(i) : "null";
|
35
|
+
case"boolean":
|
36
|
+
case"null":
|
37
|
+
return String(i);
|
38
|
+
case"object":
|
39
|
+
if (!i)return "null";
|
40
|
+
gap += indent, h = [];
|
41
|
+
if (Object.prototype.toString.apply(i) === "[object Array]") {
|
42
|
+
f = i.length;
|
43
|
+
for (c = 0; c < f; c += 1)h[c] = str(c, i) || "null";
|
44
|
+
e = h.length === 0 ? "[]" : gap ? "[\n" + gap + h.join(",\n" + gap) + "\n" + g + "]" : "[" + h.join(",") + "]", gap = g;
|
45
|
+
return e
|
46
|
+
}
|
47
|
+
if (rep && typeof rep == "object") {
|
48
|
+
f = rep.length;
|
49
|
+
for (c = 0; c < f; c += 1)typeof rep[c] == "string" && (d = rep[c], e = str(d, i), e && h.push(quote(d) + (gap ? ": " : ":") + e))
|
50
|
+
} else for (d in i)Object.prototype.hasOwnProperty.call(i, d) && (e = str(d, i), e && h.push(quote(d) + (gap ? ": " : ":") + e));
|
51
|
+
e = h.length === 0 ? "{}" : gap ? "{\n" + gap + h.join(",\n" + gap) + "\n" + g + "}" : "{" + h.join(",") + "}", gap = g;
|
52
|
+
return e
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
function quote(a) {
|
57
|
+
escapable.lastIndex = 0;
|
58
|
+
return escapable.test(a) ? '"' + a.replace(escapable, function (a) {
|
59
|
+
var b = meta[a];
|
60
|
+
return typeof b == "string" ? b : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
|
61
|
+
}) + '"' : '"' + a + '"'
|
62
|
+
}
|
63
|
+
|
64
|
+
function f(a) {
|
65
|
+
return a < 10 ? "0" + a : a
|
66
|
+
}
|
67
|
+
|
68
|
+
"use strict", typeof Date.prototype.toJSON != "function" && (Date.prototype.toJSON = function (a) {
|
69
|
+
return isFinite(this.valueOf()) ? this.getUTCFullYear() + "-" + f(this.getUTCMonth() + 1) + "-" + f(this.getUTCDate()) + "T" + f(this.getUTCHours()) + ":" + f(this.getUTCMinutes()) + ":" + f(this.getUTCSeconds()) + "Z" : null
|
70
|
+
}, String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function (a) {
|
71
|
+
return this.valueOf()
|
72
|
+
});
|
73
|
+
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
74
|
+
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
75
|
+
gap, indent, meta = {"\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", '"': '\\"', "\\": "\\\\"},
|
76
|
+
rep;
|
77
|
+
typeof JSON.stringify != "function" && (JSON.stringify = function (a, b, c) {
|
78
|
+
var d;
|
79
|
+
gap = "", indent = "";
|
80
|
+
if (typeof c == "number")for (d = 0; d < c; d += 1)indent += " "; else typeof c == "string" && (indent = c);
|
81
|
+
rep = b;
|
82
|
+
if (!b || typeof b == "function" || typeof b == "object" && typeof b.length == "number")return str("", {"": a});
|
83
|
+
throw new Error("JSON.stringify")
|
84
|
+
}), typeof JSON.parse != "function" && (JSON.parse = function (text, reviver) {
|
85
|
+
function walk(a, b) {
|
86
|
+
var c, d, e = a[b];
|
87
|
+
if (e && typeof e == "object")for (c in e)Object.prototype.hasOwnProperty.call(e, c) && (d = walk(e, c), d !== undefined ? e[c] = d : delete e[c]);
|
88
|
+
return reviver.call(a, b, e)
|
89
|
+
}
|
90
|
+
|
91
|
+
var j;
|
92
|
+
text = String(text), cx.lastIndex = 0, cx.test(text) && (text = text.replace(cx, function (a) {
|
93
|
+
return "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
|
94
|
+
}));
|
95
|
+
if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) {
|
96
|
+
j = eval("(" + text + ")");
|
97
|
+
return typeof reviver == "function" ? walk({"": j}, "") : j
|
98
|
+
}
|
99
|
+
throw new SyntaxError("JSON.parse")
|
100
|
+
})
|
101
|
+
}()
|
102
|
+
|
103
|
+
|
104
|
+
// [*] Including lib/index.js
|
105
|
+
// Public object
|
106
|
+
SockJS = (function () {
|
107
|
+
var _document = document;
|
108
|
+
var _window = window;
|
109
|
+
var utils = {};
|
110
|
+
|
111
|
+
|
112
|
+
// [*] Including lib/reventtarget.js
|
113
|
+
/*
|
114
|
+
* ***** BEGIN LICENSE BLOCK *****
|
115
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
116
|
+
*
|
117
|
+
* For the license see COPYING.
|
118
|
+
* ***** END LICENSE BLOCK *****
|
119
|
+
*/
|
120
|
+
|
121
|
+
/* Simplified implementation of DOM2 EventTarget.
|
122
|
+
* http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget
|
123
|
+
*/
|
124
|
+
var REventTarget = function () {
|
125
|
+
};
|
126
|
+
REventTarget.prototype.addEventListener = function (eventType, listener) {
|
127
|
+
if (!this._listeners) {
|
128
|
+
this._listeners = {};
|
129
|
+
}
|
130
|
+
if (!(eventType in this._listeners)) {
|
131
|
+
this._listeners[eventType] = [];
|
132
|
+
}
|
133
|
+
var arr = this._listeners[eventType];
|
134
|
+
if (utils.arrIndexOf(arr, listener) === -1) {
|
135
|
+
arr.push(listener);
|
136
|
+
}
|
137
|
+
return;
|
138
|
+
};
|
139
|
+
|
140
|
+
REventTarget.prototype.removeEventListener = function (eventType, listener) {
|
141
|
+
if (!(this._listeners && (eventType in this._listeners))) {
|
142
|
+
return;
|
143
|
+
}
|
144
|
+
var arr = this._listeners[eventType];
|
145
|
+
var idx = utils.arrIndexOf(arr, listener);
|
146
|
+
if (idx !== -1) {
|
147
|
+
if (arr.length > 1) {
|
148
|
+
this._listeners[eventType] = arr.slice(0, idx).concat(arr.slice(idx + 1));
|
149
|
+
} else {
|
150
|
+
delete this._listeners[eventType];
|
151
|
+
}
|
152
|
+
return;
|
153
|
+
}
|
154
|
+
return;
|
155
|
+
};
|
156
|
+
|
157
|
+
REventTarget.prototype.dispatchEvent = function (event) {
|
158
|
+
var t = event.type;
|
159
|
+
var args = Array.prototype.slice.call(arguments, 0);
|
160
|
+
if (this['on' + t]) {
|
161
|
+
this['on' + t].apply(this, args);
|
162
|
+
}
|
163
|
+
if (this._listeners && t in this._listeners) {
|
164
|
+
for (var i = 0; i < this._listeners[t].length; i++) {
|
165
|
+
this._listeners[t][i].apply(this, args);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
};
|
169
|
+
// [*] End of lib/reventtarget.js
|
170
|
+
|
171
|
+
|
172
|
+
// [*] Including lib/simpleevent.js
|
173
|
+
/*
|
174
|
+
* ***** BEGIN LICENSE BLOCK *****
|
175
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
176
|
+
*
|
177
|
+
* For the license see COPYING.
|
178
|
+
* ***** END LICENSE BLOCK *****
|
179
|
+
*/
|
180
|
+
|
181
|
+
var SimpleEvent = function (type, obj) {
|
182
|
+
this.type = type;
|
183
|
+
if (typeof obj !== 'undefined') {
|
184
|
+
for (var k in obj) {
|
185
|
+
if (!obj.hasOwnProperty(k)) continue;
|
186
|
+
this[k] = obj[k];
|
187
|
+
}
|
188
|
+
}
|
189
|
+
};
|
190
|
+
|
191
|
+
SimpleEvent.prototype.toString = function () {
|
192
|
+
var r = [];
|
193
|
+
for (var k in this) {
|
194
|
+
if (!this.hasOwnProperty(k)) continue;
|
195
|
+
var v = this[k];
|
196
|
+
if (typeof v === 'function') v = '[function]';
|
197
|
+
r.push(k + '=' + v);
|
198
|
+
}
|
199
|
+
return 'SimpleEvent(' + r.join(', ') + ')';
|
200
|
+
};
|
201
|
+
// [*] End of lib/simpleevent.js
|
202
|
+
|
203
|
+
|
204
|
+
// [*] Including lib/eventemitter.js
|
205
|
+
/*
|
206
|
+
* ***** BEGIN LICENSE BLOCK *****
|
207
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
208
|
+
*
|
209
|
+
* For the license see COPYING.
|
210
|
+
* ***** END LICENSE BLOCK *****
|
211
|
+
*/
|
212
|
+
|
213
|
+
var EventEmitter = function (events) {
|
214
|
+
var that = this;
|
215
|
+
that._events = events || [];
|
216
|
+
that._listeners = {};
|
217
|
+
};
|
218
|
+
EventEmitter.prototype.emit = function (type) {
|
219
|
+
var that = this;
|
220
|
+
that._verifyType(type);
|
221
|
+
if (that._nuked) return;
|
222
|
+
|
223
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
224
|
+
if (that['on' + type]) {
|
225
|
+
that['on' + type].apply(that, args);
|
226
|
+
}
|
227
|
+
if (type in that._listeners) {
|
228
|
+
for (var i = 0; i < that._listeners[type].length; i++) {
|
229
|
+
that._listeners[type][i].apply(that, args);
|
230
|
+
}
|
231
|
+
}
|
232
|
+
};
|
233
|
+
|
234
|
+
EventEmitter.prototype.on = function (type, callback) {
|
235
|
+
var that = this;
|
236
|
+
that._verifyType(type);
|
237
|
+
if (that._nuked) return;
|
238
|
+
|
239
|
+
if (!(type in that._listeners)) {
|
240
|
+
that._listeners[type] = [];
|
241
|
+
}
|
242
|
+
that._listeners[type].push(callback);
|
243
|
+
};
|
244
|
+
|
245
|
+
EventEmitter.prototype._verifyType = function (type) {
|
246
|
+
var that = this;
|
247
|
+
if (utils.arrIndexOf(that._events, type) === -1) {
|
248
|
+
utils.log('Event ' + JSON.stringify(type) +
|
249
|
+
' not listed ' + JSON.stringify(that._events) +
|
250
|
+
' in ' + that);
|
251
|
+
}
|
252
|
+
};
|
253
|
+
|
254
|
+
EventEmitter.prototype.nuke = function () {
|
255
|
+
var that = this;
|
256
|
+
that._nuked = true;
|
257
|
+
for (var i = 0; i < that._events.length; i++) {
|
258
|
+
delete that[that._events[i]];
|
259
|
+
}
|
260
|
+
that._listeners = {};
|
261
|
+
};
|
262
|
+
// [*] End of lib/eventemitter.js
|
263
|
+
|
264
|
+
|
265
|
+
// [*] Including lib/utils.js
|
266
|
+
/*
|
267
|
+
* ***** BEGIN LICENSE BLOCK *****
|
268
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
269
|
+
*
|
270
|
+
* For the license see COPYING.
|
271
|
+
* ***** END LICENSE BLOCK *****
|
272
|
+
*/
|
273
|
+
|
274
|
+
var random_string_chars = 'abcdefghijklmnopqrstuvwxyz0123456789_';
|
275
|
+
utils.random_string = function (length, max) {
|
276
|
+
max = max || random_string_chars.length;
|
277
|
+
var i, ret = [];
|
278
|
+
for (i = 0; i < length; i++) {
|
279
|
+
ret.push(random_string_chars.substr(Math.floor(Math.random() * max), 1));
|
280
|
+
}
|
281
|
+
return ret.join('');
|
282
|
+
};
|
283
|
+
utils.random_number = function (max) {
|
284
|
+
return Math.floor(Math.random() * max);
|
285
|
+
};
|
286
|
+
utils.random_number_string = function (max) {
|
287
|
+
var t = ('' + (max - 1)).length;
|
288
|
+
var p = Array(t + 1).join('0');
|
289
|
+
return (p + utils.random_number(max)).slice(-t);
|
290
|
+
};
|
291
|
+
|
292
|
+
// Assuming that url looks like: http://asdasd:111/asd
|
293
|
+
utils.getOrigin = function (url) {
|
294
|
+
url += '/';
|
295
|
+
var parts = url.split('/').slice(0, 3);
|
296
|
+
return parts.join('/');
|
297
|
+
};
|
298
|
+
|
299
|
+
utils.isSameOriginUrl = function (url_a, url_b) {
|
300
|
+
// location.origin would do, but it's not always available.
|
301
|
+
if (!url_b) url_b = _window.location.href;
|
302
|
+
|
303
|
+
return (url_a.split('/').slice(0, 3).join('/')
|
304
|
+
===
|
305
|
+
url_b.split('/').slice(0, 3).join('/'));
|
306
|
+
};
|
307
|
+
|
308
|
+
utils.getParentDomain = function (url) {
|
309
|
+
// ipv4 ip address
|
310
|
+
if (/^[0-9.]*$/.test(url)) return url;
|
311
|
+
// ipv6 ip address
|
312
|
+
if (/^\[/.test(url)) return url;
|
313
|
+
// no dots
|
314
|
+
if (!(/[.]/.test(url))) return url;
|
315
|
+
|
316
|
+
var parts = url.split('.').slice(1);
|
317
|
+
return parts.join('.');
|
318
|
+
};
|
319
|
+
|
320
|
+
utils.objectExtend = function (dst, src) {
|
321
|
+
for (var k in src) {
|
322
|
+
if (src.hasOwnProperty(k)) {
|
323
|
+
dst[k] = src[k];
|
324
|
+
}
|
325
|
+
}
|
326
|
+
return dst;
|
327
|
+
};
|
328
|
+
|
329
|
+
var WPrefix = '_jp';
|
330
|
+
|
331
|
+
utils.polluteGlobalNamespace = function () {
|
332
|
+
if (!(WPrefix in _window)) {
|
333
|
+
_window[WPrefix] = {};
|
334
|
+
}
|
335
|
+
};
|
336
|
+
|
337
|
+
utils.closeFrame = function (code, reason) {
|
338
|
+
return 'c' + JSON.stringify([code, reason]);
|
339
|
+
};
|
340
|
+
|
341
|
+
utils.userSetCode = function (code) {
|
342
|
+
return code === 1000 || (code >= 3000 && code <= 4999);
|
343
|
+
};
|
344
|
+
|
345
|
+
// See: http://www.erg.abdn.ac.uk/~gerrit/dccp/notes/ccid2/rto_estimator/
|
346
|
+
// and RFC 2988.
|
347
|
+
utils.countRTO = function (rtt) {
|
348
|
+
var rto;
|
349
|
+
if (rtt > 100) {
|
350
|
+
rto = 3 * rtt; // rto > 300msec
|
351
|
+
} else {
|
352
|
+
rto = rtt + 200; // 200msec < rto <= 300msec
|
353
|
+
}
|
354
|
+
return rto;
|
355
|
+
}
|
356
|
+
|
357
|
+
utils.log = function () {
|
358
|
+
if (_window.console && console.log && console.log.apply) {
|
359
|
+
console.log.apply(console, arguments);
|
360
|
+
}
|
361
|
+
};
|
362
|
+
|
363
|
+
utils.bind = function (fun, that) {
|
364
|
+
if (fun.bind) {
|
365
|
+
return fun.bind(that);
|
366
|
+
} else {
|
367
|
+
return function () {
|
368
|
+
return fun.apply(that, arguments);
|
369
|
+
};
|
370
|
+
}
|
371
|
+
};
|
372
|
+
|
373
|
+
utils.flatUrl = function (url) {
|
374
|
+
return url.indexOf('?') === -1 && url.indexOf('#') === -1;
|
375
|
+
};
|
376
|
+
|
377
|
+
utils.amendUrl = function (url) {
|
378
|
+
var dl = _document.location;
|
379
|
+
if (!url) {
|
380
|
+
throw new Error('Wrong url for SockJS');
|
381
|
+
}
|
382
|
+
if (!utils.flatUrl(url)) {
|
383
|
+
throw new Error('Only basic urls are supported in SockJS');
|
384
|
+
}
|
385
|
+
|
386
|
+
// '//abc' --> 'http://abc'
|
387
|
+
if (url.indexOf('//') === 0) {
|
388
|
+
url = dl.protocol + url;
|
389
|
+
}
|
390
|
+
// '/abc' --> 'http://localhost:80/abc'
|
391
|
+
if (url.indexOf('/') === 0) {
|
392
|
+
url = dl.protocol + '//' + dl.host + url;
|
393
|
+
}
|
394
|
+
// strip trailing slashes
|
395
|
+
url = url.replace(/[/]+$/, '');
|
396
|
+
return url;
|
397
|
+
};
|
398
|
+
|
399
|
+
// IE doesn't support [].indexOf.
|
400
|
+
utils.arrIndexOf = function (arr, obj) {
|
401
|
+
for (var i = 0; i < arr.length; i++) {
|
402
|
+
if (arr[i] === obj) {
|
403
|
+
return i;
|
404
|
+
}
|
405
|
+
}
|
406
|
+
return -1;
|
407
|
+
};
|
408
|
+
|
409
|
+
utils.arrSkip = function (arr, obj) {
|
410
|
+
var idx = utils.arrIndexOf(arr, obj);
|
411
|
+
if (idx === -1) {
|
412
|
+
return arr.slice();
|
413
|
+
} else {
|
414
|
+
var dst = arr.slice(0, idx);
|
415
|
+
return dst.concat(arr.slice(idx + 1));
|
416
|
+
}
|
417
|
+
};
|
418
|
+
|
419
|
+
// Via: https://gist.github.com/1133122/2121c601c5549155483f50be3da5305e83b8c5df
|
420
|
+
utils.isArray = Array.isArray || function (value) {
|
421
|
+
return {}.toString.call(value).indexOf('Array') >= 0
|
422
|
+
};
|
423
|
+
|
424
|
+
utils.delay = function (t, fun) {
|
425
|
+
if (typeof t === 'function') {
|
426
|
+
fun = t;
|
427
|
+
t = 0;
|
428
|
+
}
|
429
|
+
return setTimeout(fun, t);
|
430
|
+
};
|
431
|
+
|
432
|
+
|
433
|
+
// Chars worth escaping, as defined by Douglas Crockford:
|
434
|
+
// https://github.com/douglascrockford/JSON-js/blob/47a9882cddeb1e8529e07af9736218075372b8ac/json2.js#L196
|
435
|
+
var json_escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
436
|
+
json_lookup = {
|
437
|
+
"\u0000": "\\u0000", "\u0001": "\\u0001", "\u0002": "\\u0002", "\u0003": "\\u0003",
|
438
|
+
"\u0004": "\\u0004", "\u0005": "\\u0005", "\u0006": "\\u0006", "\u0007": "\\u0007",
|
439
|
+
"\b": "\\b", "\t": "\\t", "\n": "\\n", "\u000b": "\\u000b", "\f": "\\f", "\r": "\\r",
|
440
|
+
"\u000e": "\\u000e", "\u000f": "\\u000f", "\u0010": "\\u0010", "\u0011": "\\u0011",
|
441
|
+
"\u0012": "\\u0012", "\u0013": "\\u0013", "\u0014": "\\u0014", "\u0015": "\\u0015",
|
442
|
+
"\u0016": "\\u0016", "\u0017": "\\u0017", "\u0018": "\\u0018", "\u0019": "\\u0019",
|
443
|
+
"\u001a": "\\u001a", "\u001b": "\\u001b", "\u001c": "\\u001c", "\u001d": "\\u001d",
|
444
|
+
"\u001e": "\\u001e", "\u001f": "\\u001f", "\"": "\\\"", "\\": "\\\\",
|
445
|
+
"\u007f": "\\u007f", "\u0080": "\\u0080", "\u0081": "\\u0081", "\u0082": "\\u0082",
|
446
|
+
"\u0083": "\\u0083", "\u0084": "\\u0084", "\u0085": "\\u0085", "\u0086": "\\u0086",
|
447
|
+
"\u0087": "\\u0087", "\u0088": "\\u0088", "\u0089": "\\u0089", "\u008a": "\\u008a",
|
448
|
+
"\u008b": "\\u008b", "\u008c": "\\u008c", "\u008d": "\\u008d", "\u008e": "\\u008e",
|
449
|
+
"\u008f": "\\u008f", "\u0090": "\\u0090", "\u0091": "\\u0091", "\u0092": "\\u0092",
|
450
|
+
"\u0093": "\\u0093", "\u0094": "\\u0094", "\u0095": "\\u0095", "\u0096": "\\u0096",
|
451
|
+
"\u0097": "\\u0097", "\u0098": "\\u0098", "\u0099": "\\u0099", "\u009a": "\\u009a",
|
452
|
+
"\u009b": "\\u009b", "\u009c": "\\u009c", "\u009d": "\\u009d", "\u009e": "\\u009e",
|
453
|
+
"\u009f": "\\u009f", "\u00ad": "\\u00ad", "\u0600": "\\u0600", "\u0601": "\\u0601",
|
454
|
+
"\u0602": "\\u0602", "\u0603": "\\u0603", "\u0604": "\\u0604", "\u070f": "\\u070f",
|
455
|
+
"\u17b4": "\\u17b4", "\u17b5": "\\u17b5", "\u200c": "\\u200c", "\u200d": "\\u200d",
|
456
|
+
"\u200e": "\\u200e", "\u200f": "\\u200f", "\u2028": "\\u2028", "\u2029": "\\u2029",
|
457
|
+
"\u202a": "\\u202a", "\u202b": "\\u202b", "\u202c": "\\u202c", "\u202d": "\\u202d",
|
458
|
+
"\u202e": "\\u202e", "\u202f": "\\u202f", "\u2060": "\\u2060", "\u2061": "\\u2061",
|
459
|
+
"\u2062": "\\u2062", "\u2063": "\\u2063", "\u2064": "\\u2064", "\u2065": "\\u2065",
|
460
|
+
"\u2066": "\\u2066", "\u2067": "\\u2067", "\u2068": "\\u2068", "\u2069": "\\u2069",
|
461
|
+
"\u206a": "\\u206a", "\u206b": "\\u206b", "\u206c": "\\u206c", "\u206d": "\\u206d",
|
462
|
+
"\u206e": "\\u206e", "\u206f": "\\u206f", "\ufeff": "\\ufeff", "\ufff0": "\\ufff0",
|
463
|
+
"\ufff1": "\\ufff1", "\ufff2": "\\ufff2", "\ufff3": "\\ufff3", "\ufff4": "\\ufff4",
|
464
|
+
"\ufff5": "\\ufff5", "\ufff6": "\\ufff6", "\ufff7": "\\ufff7", "\ufff8": "\\ufff8",
|
465
|
+
"\ufff9": "\\ufff9", "\ufffa": "\\ufffa", "\ufffb": "\\ufffb", "\ufffc": "\\ufffc",
|
466
|
+
"\ufffd": "\\ufffd", "\ufffe": "\\ufffe", "\uffff": "\\uffff"
|
467
|
+
};
|
468
|
+
|
469
|
+
// Some extra characters that Chrome gets wrong, and substitutes with
|
470
|
+
// something else on the wire.
|
471
|
+
var extra_escapable = /[\x00-\x1f\ud800-\udfff\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06ec\u0730\u0732-\u0733\u0735-\u0736\u073a\u073d\u073f-\u0741\u0743\u0745\u0747\u07eb-\u07f1\u0951\u0958-\u095f\u09dc-\u09dd\u09df\u0a33\u0a36\u0a59-\u0a5b\u0a5e\u0b5c-\u0b5d\u0e38-\u0e39\u0f43\u0f4d\u0f52\u0f57\u0f5c\u0f69\u0f72-\u0f76\u0f78\u0f80-\u0f83\u0f93\u0f9d\u0fa2\u0fa7\u0fac\u0fb9\u1939-\u193a\u1a17\u1b6b\u1cda-\u1cdb\u1dc0-\u1dcf\u1dfc\u1dfe\u1f71\u1f73\u1f75\u1f77\u1f79\u1f7b\u1f7d\u1fbb\u1fbe\u1fc9\u1fcb\u1fd3\u1fdb\u1fe3\u1feb\u1fee-\u1fef\u1ff9\u1ffb\u1ffd\u2000-\u2001\u20d0-\u20d1\u20d4-\u20d7\u20e7-\u20e9\u2126\u212a-\u212b\u2329-\u232a\u2adc\u302b-\u302c\uaab2-\uaab3\uf900-\ufa0d\ufa10\ufa12\ufa15-\ufa1e\ufa20\ufa22\ufa25-\ufa26\ufa2a-\ufa2d\ufa30-\ufa6d\ufa70-\ufad9\ufb1d\ufb1f\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4e\ufff0-\uffff]/g,
|
472
|
+
extra_lookup;
|
473
|
+
|
474
|
+
// JSON Quote string. Use native implementation when possible.
|
475
|
+
var JSONQuote = (JSON && JSON.stringify) || function (string) {
|
476
|
+
json_escapable.lastIndex = 0;
|
477
|
+
if (json_escapable.test(string)) {
|
478
|
+
string = string.replace(json_escapable, function (a) {
|
479
|
+
return json_lookup[a];
|
480
|
+
});
|
481
|
+
}
|
482
|
+
return '"' + string + '"';
|
483
|
+
};
|
484
|
+
|
485
|
+
// This may be quite slow, so let's delay until user actually uses bad
|
486
|
+
// characters.
|
487
|
+
var unroll_lookup = function (escapable) {
|
488
|
+
var i;
|
489
|
+
var unrolled = {}
|
490
|
+
var c = []
|
491
|
+
for (i = 0; i < 65536; i++) {
|
492
|
+
c.push(String.fromCharCode(i));
|
493
|
+
}
|
494
|
+
escapable.lastIndex = 0;
|
495
|
+
c.join('').replace(escapable, function (a) {
|
496
|
+
unrolled[a] = '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
497
|
+
return '';
|
498
|
+
});
|
499
|
+
escapable.lastIndex = 0;
|
500
|
+
return unrolled;
|
501
|
+
};
|
502
|
+
|
503
|
+
// Quote string, also taking care of unicode characters that browsers
|
504
|
+
// often break. Especially, take care of unicode surrogates:
|
505
|
+
// http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters#Surrogates
|
506
|
+
utils.quote = function (string) {
|
507
|
+
var quoted = JSONQuote(string);
|
508
|
+
|
509
|
+
// In most cases this should be very fast and good enough.
|
510
|
+
extra_escapable.lastIndex = 0;
|
511
|
+
if (!extra_escapable.test(quoted)) {
|
512
|
+
return quoted;
|
513
|
+
}
|
514
|
+
|
515
|
+
if (!extra_lookup) extra_lookup = unroll_lookup(extra_escapable);
|
516
|
+
|
517
|
+
return quoted.replace(extra_escapable, function (a) {
|
518
|
+
return extra_lookup[a];
|
519
|
+
});
|
520
|
+
}
|
521
|
+
|
522
|
+
var _all_protocols = ['websocket',
|
523
|
+
'xdr-streaming',
|
524
|
+
'xhr-streaming',
|
525
|
+
'iframe-eventsource',
|
526
|
+
'iframe-htmlfile',
|
527
|
+
'xdr-polling',
|
528
|
+
'xhr-polling',
|
529
|
+
'iframe-xhr-polling',
|
530
|
+
'jsonp-polling'];
|
531
|
+
|
532
|
+
utils.probeProtocols = function () {
|
533
|
+
var probed = {};
|
534
|
+
for (var i = 0; i < _all_protocols.length; i++) {
|
535
|
+
var protocol = _all_protocols[i];
|
536
|
+
// User can have a typo in protocol name.
|
537
|
+
probed[protocol] = SockJS[protocol] &&
|
538
|
+
SockJS[protocol].enabled();
|
539
|
+
}
|
540
|
+
return probed;
|
541
|
+
};
|
542
|
+
|
543
|
+
utils.detectProtocols = function (probed, protocols_whitelist, info) {
|
544
|
+
var pe = {},
|
545
|
+
protocols = [];
|
546
|
+
if (!protocols_whitelist) protocols_whitelist = _all_protocols;
|
547
|
+
for (var i = 0; i < protocols_whitelist.length; i++) {
|
548
|
+
var protocol = protocols_whitelist[i];
|
549
|
+
pe[protocol] = probed[protocol];
|
550
|
+
}
|
551
|
+
var maybe_push = function (protos) {
|
552
|
+
var proto = protos.shift();
|
553
|
+
if (pe[proto]) {
|
554
|
+
protocols.push(proto);
|
555
|
+
} else {
|
556
|
+
if (protos.length > 0) {
|
557
|
+
maybe_push(protos);
|
558
|
+
}
|
559
|
+
}
|
560
|
+
}
|
561
|
+
|
562
|
+
// 1. Websocket
|
563
|
+
if (info.websocket !== false) {
|
564
|
+
maybe_push(['websocket']);
|
565
|
+
}
|
566
|
+
|
567
|
+
// 2. Streaming
|
568
|
+
if (pe['xhr-streaming'] && !info.null_origin) {
|
569
|
+
protocols.push('xhr-streaming');
|
570
|
+
} else {
|
571
|
+
if (pe['xdr-streaming'] && !info.cookie_needed && !info.null_origin) {
|
572
|
+
protocols.push('xdr-streaming');
|
573
|
+
} else {
|
574
|
+
maybe_push(['iframe-eventsource',
|
575
|
+
'iframe-htmlfile']);
|
576
|
+
}
|
577
|
+
}
|
578
|
+
|
579
|
+
// 3. Polling
|
580
|
+
if (pe['xhr-polling'] && !info.null_origin) {
|
581
|
+
protocols.push('xhr-polling');
|
582
|
+
} else {
|
583
|
+
if (pe['xdr-polling'] && !info.cookie_needed && !info.null_origin) {
|
584
|
+
protocols.push('xdr-polling');
|
585
|
+
} else {
|
586
|
+
maybe_push(['iframe-xhr-polling',
|
587
|
+
'jsonp-polling']);
|
588
|
+
}
|
589
|
+
}
|
590
|
+
return protocols;
|
591
|
+
}
|
592
|
+
// [*] End of lib/utils.js
|
593
|
+
|
594
|
+
|
595
|
+
// [*] Including lib/dom.js
|
596
|
+
/*
|
597
|
+
* ***** BEGIN LICENSE BLOCK *****
|
598
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
599
|
+
*
|
600
|
+
* For the license see COPYING.
|
601
|
+
* ***** END LICENSE BLOCK *****
|
602
|
+
*/
|
603
|
+
|
604
|
+
// May be used by htmlfile jsonp and transports.
|
605
|
+
var MPrefix = '_sockjs_global';
|
606
|
+
utils.createHook = function () {
|
607
|
+
var window_id = 'a' + utils.random_string(8);
|
608
|
+
if (!(MPrefix in _window)) {
|
609
|
+
var map = {};
|
610
|
+
_window[MPrefix] = function (window_id) {
|
611
|
+
if (!(window_id in map)) {
|
612
|
+
map[window_id] = {
|
613
|
+
id: window_id,
|
614
|
+
del: function () {
|
615
|
+
delete map[window_id];
|
616
|
+
}
|
617
|
+
};
|
618
|
+
}
|
619
|
+
return map[window_id];
|
620
|
+
}
|
621
|
+
}
|
622
|
+
return _window[MPrefix](window_id);
|
623
|
+
};
|
624
|
+
|
625
|
+
|
626
|
+
utils.attachMessage = function (listener) {
|
627
|
+
utils.attachEvent('message', listener);
|
628
|
+
};
|
629
|
+
utils.attachEvent = function (event, listener) {
|
630
|
+
if (typeof _window.addEventListener !== 'undefined') {
|
631
|
+
_window.addEventListener(event, listener, false);
|
632
|
+
} else {
|
633
|
+
// IE quirks.
|
634
|
+
// According to: http://stevesouders.com/misc/test-postmessage.php
|
635
|
+
// the message gets delivered only to 'document', not 'window'.
|
636
|
+
_document.attachEvent("on" + event, listener);
|
637
|
+
// I get 'window' for ie8.
|
638
|
+
_window.attachEvent("on" + event, listener);
|
639
|
+
}
|
640
|
+
};
|
641
|
+
|
642
|
+
utils.detachMessage = function (listener) {
|
643
|
+
utils.detachEvent('message', listener);
|
644
|
+
};
|
645
|
+
utils.detachEvent = function (event, listener) {
|
646
|
+
if (typeof _window.addEventListener !== 'undefined') {
|
647
|
+
_window.removeEventListener(event, listener, false);
|
648
|
+
} else {
|
649
|
+
_document.detachEvent("on" + event, listener);
|
650
|
+
_window.detachEvent("on" + event, listener);
|
651
|
+
}
|
652
|
+
};
|
653
|
+
|
654
|
+
|
655
|
+
var on_unload = {};
|
656
|
+
// Things registered after beforeunload are to be called immediately.
|
657
|
+
var after_unload = false;
|
658
|
+
|
659
|
+
var trigger_unload_callbacks = function () {
|
660
|
+
for (var ref in on_unload) {
|
661
|
+
on_unload[ref]();
|
662
|
+
delete on_unload[ref];
|
663
|
+
}
|
664
|
+
;
|
665
|
+
};
|
666
|
+
|
667
|
+
var unload_triggered = function () {
|
668
|
+
if (after_unload) return;
|
669
|
+
after_unload = true;
|
670
|
+
trigger_unload_callbacks();
|
671
|
+
};
|
672
|
+
|
673
|
+
// 'unload' alone is not reliable in opera within an iframe, but we
|
674
|
+
// can't use `beforeunload` as IE fires it on javascript: links.
|
675
|
+
utils.attachEvent('unload', unload_triggered);
|
676
|
+
|
677
|
+
utils.unload_add = function (listener) {
|
678
|
+
var ref = utils.random_string(8);
|
679
|
+
on_unload[ref] = listener;
|
680
|
+
if (after_unload) {
|
681
|
+
utils.delay(trigger_unload_callbacks);
|
682
|
+
}
|
683
|
+
return ref;
|
684
|
+
};
|
685
|
+
utils.unload_del = function (ref) {
|
686
|
+
if (ref in on_unload)
|
687
|
+
delete on_unload[ref];
|
688
|
+
};
|
689
|
+
|
690
|
+
|
691
|
+
utils.createIframe = function (iframe_url, error_callback) {
|
692
|
+
var iframe = _document.createElement('iframe');
|
693
|
+
var tref, unload_ref;
|
694
|
+
var unattach = function () {
|
695
|
+
clearTimeout(tref);
|
696
|
+
// Explorer had problems with that.
|
697
|
+
try {
|
698
|
+
iframe.onload = null;
|
699
|
+
} catch (x) {
|
700
|
+
}
|
701
|
+
iframe.onerror = null;
|
702
|
+
};
|
703
|
+
var cleanup = function () {
|
704
|
+
if (iframe) {
|
705
|
+
unattach();
|
706
|
+
// This timeout makes chrome fire onbeforeunload event
|
707
|
+
// within iframe. Without the timeout it goes straight to
|
708
|
+
// onunload.
|
709
|
+
setTimeout(function () {
|
710
|
+
if (iframe) {
|
711
|
+
iframe.parentNode.removeChild(iframe);
|
712
|
+
}
|
713
|
+
iframe = null;
|
714
|
+
}, 0);
|
715
|
+
utils.unload_del(unload_ref);
|
716
|
+
}
|
717
|
+
};
|
718
|
+
var onerror = function (r) {
|
719
|
+
if (iframe) {
|
720
|
+
cleanup();
|
721
|
+
error_callback(r);
|
722
|
+
}
|
723
|
+
};
|
724
|
+
var post = function (msg, origin) {
|
725
|
+
try {
|
726
|
+
// When the iframe is not loaded, IE raises an exception
|
727
|
+
// on 'contentWindow'.
|
728
|
+
if (iframe && iframe.contentWindow) {
|
729
|
+
iframe.contentWindow.postMessage(msg, origin);
|
730
|
+
}
|
731
|
+
} catch (x) {
|
732
|
+
}
|
733
|
+
;
|
734
|
+
};
|
735
|
+
|
736
|
+
iframe.src = iframe_url;
|
737
|
+
iframe.style.display = 'none';
|
738
|
+
iframe.style.position = 'absolute';
|
739
|
+
iframe.onerror = function () {
|
740
|
+
onerror('onerror');
|
741
|
+
};
|
742
|
+
iframe.onload = function () {
|
743
|
+
// `onload` is triggered before scripts on the iframe are
|
744
|
+
// executed. Give it few seconds to actually load stuff.
|
745
|
+
clearTimeout(tref);
|
746
|
+
tref = setTimeout(function () {
|
747
|
+
onerror('onload timeout');
|
748
|
+
}, 2000);
|
749
|
+
};
|
750
|
+
_document.body.appendChild(iframe);
|
751
|
+
tref = setTimeout(function () {
|
752
|
+
onerror('timeout');
|
753
|
+
}, 15000);
|
754
|
+
unload_ref = utils.unload_add(cleanup);
|
755
|
+
return {
|
756
|
+
post: post,
|
757
|
+
cleanup: cleanup,
|
758
|
+
loaded: unattach
|
759
|
+
};
|
760
|
+
};
|
761
|
+
|
762
|
+
utils.createHtmlfile = function (iframe_url, error_callback) {
|
763
|
+
var doc = new ActiveXObject('htmlfile');
|
764
|
+
var tref, unload_ref;
|
765
|
+
var iframe;
|
766
|
+
var unattach = function () {
|
767
|
+
clearTimeout(tref);
|
768
|
+
};
|
769
|
+
var cleanup = function () {
|
770
|
+
if (doc) {
|
771
|
+
unattach();
|
772
|
+
utils.unload_del(unload_ref);
|
773
|
+
iframe.parentNode.removeChild(iframe);
|
774
|
+
iframe = doc = null;
|
775
|
+
CollectGarbage();
|
776
|
+
}
|
777
|
+
};
|
778
|
+
var onerror = function (r) {
|
779
|
+
if (doc) {
|
780
|
+
cleanup();
|
781
|
+
error_callback(r);
|
782
|
+
}
|
783
|
+
};
|
784
|
+
var post = function (msg, origin) {
|
785
|
+
try {
|
786
|
+
// When the iframe is not loaded, IE raises an exception
|
787
|
+
// on 'contentWindow'.
|
788
|
+
if (iframe && iframe.contentWindow) {
|
789
|
+
iframe.contentWindow.postMessage(msg, origin);
|
790
|
+
}
|
791
|
+
} catch (x) {
|
792
|
+
}
|
793
|
+
;
|
794
|
+
};
|
795
|
+
|
796
|
+
doc.open();
|
797
|
+
doc.write('<html><s' + 'cript>' +
|
798
|
+
'document.domain="' + document.domain + '";' +
|
799
|
+
'</s' + 'cript></html>');
|
800
|
+
doc.close();
|
801
|
+
doc.parentWindow[WPrefix] = _window[WPrefix];
|
802
|
+
var c = doc.createElement('div');
|
803
|
+
doc.body.appendChild(c);
|
804
|
+
iframe = doc.createElement('iframe');
|
805
|
+
c.appendChild(iframe);
|
806
|
+
iframe.src = iframe_url;
|
807
|
+
tref = setTimeout(function () {
|
808
|
+
onerror('timeout');
|
809
|
+
}, 15000);
|
810
|
+
unload_ref = utils.unload_add(cleanup);
|
811
|
+
return {
|
812
|
+
post: post,
|
813
|
+
cleanup: cleanup,
|
814
|
+
loaded: unattach
|
815
|
+
};
|
816
|
+
};
|
817
|
+
// [*] End of lib/dom.js
|
818
|
+
|
819
|
+
|
820
|
+
// [*] Including lib/dom2.js
|
821
|
+
/*
|
822
|
+
* ***** BEGIN LICENSE BLOCK *****
|
823
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
824
|
+
*
|
825
|
+
* For the license see COPYING.
|
826
|
+
* ***** END LICENSE BLOCK *****
|
827
|
+
*/
|
828
|
+
|
829
|
+
var AbstractXHRObject = function () {
|
830
|
+
};
|
831
|
+
AbstractXHRObject.prototype = new EventEmitter(['chunk', 'finish']);
|
832
|
+
|
833
|
+
AbstractXHRObject.prototype._start = function (method, url, payload, opts) {
|
834
|
+
var that = this;
|
835
|
+
|
836
|
+
try {
|
837
|
+
that.xhr = new XMLHttpRequest();
|
838
|
+
} catch (x) {
|
839
|
+
}
|
840
|
+
;
|
841
|
+
|
842
|
+
if (!that.xhr) {
|
843
|
+
try {
|
844
|
+
that.xhr = new _window.ActiveXObject('Microsoft.XMLHTTP');
|
845
|
+
} catch (x) {
|
846
|
+
}
|
847
|
+
;
|
848
|
+
}
|
849
|
+
if (_window.ActiveXObject || _window.XDomainRequest) {
|
850
|
+
// IE8 caches even POSTs
|
851
|
+
url += ((url.indexOf('?') === -1) ? '?' : '&') + 't=' + (+new Date);
|
852
|
+
}
|
853
|
+
|
854
|
+
// Explorer tends to keep connection open, even after the
|
855
|
+
// tab gets closed: http://bugs.jquery.com/ticket/5280
|
856
|
+
that.unload_ref = utils.unload_add(function () {
|
857
|
+
that._cleanup(true);
|
858
|
+
});
|
859
|
+
try {
|
860
|
+
that.xhr.open(method, url, true);
|
861
|
+
} catch (e) {
|
862
|
+
// IE raises an exception on wrong port.
|
863
|
+
that.emit('finish', 0, '');
|
864
|
+
that._cleanup();
|
865
|
+
return;
|
866
|
+
}
|
867
|
+
;
|
868
|
+
|
869
|
+
if (!opts || !opts.no_credentials) {
|
870
|
+
// Mozilla docs says https://developer.mozilla.org/en/XMLHttpRequest :
|
871
|
+
// "This never affects same-site requests."
|
872
|
+
that.xhr.withCredentials = 'true';
|
873
|
+
}
|
874
|
+
if (opts && opts.headers) {
|
875
|
+
for (var key in opts.headers) {
|
876
|
+
that.xhr.setRequestHeader(key, opts.headers[key]);
|
877
|
+
}
|
878
|
+
}
|
879
|
+
|
880
|
+
that.xhr.onreadystatechange = function () {
|
881
|
+
if (that.xhr) {
|
882
|
+
var x = that.xhr;
|
883
|
+
switch (x.readyState) {
|
884
|
+
case 3:
|
885
|
+
// IE doesn't like peeking into responseText or status
|
886
|
+
// on Microsoft.XMLHTTP and readystate=3
|
887
|
+
try {
|
888
|
+
var status = x.status;
|
889
|
+
var text = x.responseText;
|
890
|
+
} catch (x) {
|
891
|
+
}
|
892
|
+
;
|
893
|
+
// IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
|
894
|
+
if (status === 1223) status = 204;
|
895
|
+
|
896
|
+
// IE does return readystate == 3 for 404 answers.
|
897
|
+
if (text && text.length > 0) {
|
898
|
+
that.emit('chunk', status, text);
|
899
|
+
}
|
900
|
+
break;
|
901
|
+
case 4:
|
902
|
+
var status = x.status;
|
903
|
+
// IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
|
904
|
+
if (status === 1223) status = 204;
|
905
|
+
|
906
|
+
that.emit('finish', status, x.responseText);
|
907
|
+
that._cleanup(false);
|
908
|
+
break;
|
909
|
+
}
|
910
|
+
}
|
911
|
+
};
|
912
|
+
that.xhr.send(payload);
|
913
|
+
};
|
914
|
+
|
915
|
+
AbstractXHRObject.prototype._cleanup = function (abort) {
|
916
|
+
var that = this;
|
917
|
+
if (!that.xhr) return;
|
918
|
+
utils.unload_del(that.unload_ref);
|
919
|
+
|
920
|
+
// IE needs this field to be a function
|
921
|
+
that.xhr.onreadystatechange = function () {
|
922
|
+
};
|
923
|
+
|
924
|
+
if (abort) {
|
925
|
+
try {
|
926
|
+
that.xhr.abort();
|
927
|
+
} catch (x) {
|
928
|
+
}
|
929
|
+
;
|
930
|
+
}
|
931
|
+
that.unload_ref = that.xhr = null;
|
932
|
+
};
|
933
|
+
|
934
|
+
AbstractXHRObject.prototype.close = function () {
|
935
|
+
var that = this;
|
936
|
+
that.nuke();
|
937
|
+
that._cleanup(true);
|
938
|
+
};
|
939
|
+
|
940
|
+
var XHRCorsObject = utils.XHRCorsObject = function () {
|
941
|
+
var that = this, args = arguments;
|
942
|
+
utils.delay(function () {
|
943
|
+
that._start.apply(that, args);
|
944
|
+
});
|
945
|
+
};
|
946
|
+
XHRCorsObject.prototype = new AbstractXHRObject();
|
947
|
+
|
948
|
+
var XHRLocalObject = utils.XHRLocalObject = function (method, url, payload) {
|
949
|
+
var that = this;
|
950
|
+
utils.delay(function () {
|
951
|
+
that._start(method, url, payload, {
|
952
|
+
no_credentials: true
|
953
|
+
});
|
954
|
+
});
|
955
|
+
};
|
956
|
+
XHRLocalObject.prototype = new AbstractXHRObject();
|
957
|
+
|
958
|
+
|
959
|
+
// References:
|
960
|
+
// http://ajaxian.com/archives/100-line-ajax-wrapper
|
961
|
+
// http://msdn.microsoft.com/en-us/library/cc288060(v=VS.85).aspx
|
962
|
+
var XDRObject = utils.XDRObject = function (method, url, payload) {
|
963
|
+
var that = this;
|
964
|
+
utils.delay(function () {
|
965
|
+
that._start(method, url, payload);
|
966
|
+
});
|
967
|
+
};
|
968
|
+
XDRObject.prototype = new EventEmitter(['chunk', 'finish']);
|
969
|
+
XDRObject.prototype._start = function (method, url, payload) {
|
970
|
+
var that = this;
|
971
|
+
var xdr = new XDomainRequest();
|
972
|
+
// IE caches even POSTs
|
973
|
+
url += ((url.indexOf('?') === -1) ? '?' : '&') + 't=' + (+new Date);
|
974
|
+
|
975
|
+
var onerror = xdr.ontimeout = xdr.onerror = function () {
|
976
|
+
that.emit('finish', 0, '');
|
977
|
+
that._cleanup(false);
|
978
|
+
};
|
979
|
+
xdr.onprogress = function () {
|
980
|
+
that.emit('chunk', 200, xdr.responseText);
|
981
|
+
};
|
982
|
+
xdr.onload = function () {
|
983
|
+
that.emit('finish', 200, xdr.responseText);
|
984
|
+
that._cleanup(false);
|
985
|
+
};
|
986
|
+
that.xdr = xdr;
|
987
|
+
that.unload_ref = utils.unload_add(function () {
|
988
|
+
that._cleanup(true);
|
989
|
+
});
|
990
|
+
try {
|
991
|
+
// Fails with AccessDenied if port number is bogus
|
992
|
+
that.xdr.open(method, url);
|
993
|
+
that.xdr.send(payload);
|
994
|
+
} catch (x) {
|
995
|
+
onerror();
|
996
|
+
}
|
997
|
+
};
|
998
|
+
|
999
|
+
XDRObject.prototype._cleanup = function (abort) {
|
1000
|
+
var that = this;
|
1001
|
+
if (!that.xdr) return;
|
1002
|
+
utils.unload_del(that.unload_ref);
|
1003
|
+
|
1004
|
+
that.xdr.ontimeout = that.xdr.onerror = that.xdr.onprogress =
|
1005
|
+
that.xdr.onload = null;
|
1006
|
+
if (abort) {
|
1007
|
+
try {
|
1008
|
+
that.xdr.abort();
|
1009
|
+
} catch (x) {
|
1010
|
+
}
|
1011
|
+
;
|
1012
|
+
}
|
1013
|
+
that.unload_ref = that.xdr = null;
|
1014
|
+
};
|
1015
|
+
|
1016
|
+
XDRObject.prototype.close = function () {
|
1017
|
+
var that = this;
|
1018
|
+
that.nuke();
|
1019
|
+
that._cleanup(true);
|
1020
|
+
};
|
1021
|
+
|
1022
|
+
// 1. Is natively via XHR
|
1023
|
+
// 2. Is natively via XDR
|
1024
|
+
// 3. Nope, but postMessage is there so it should work via the Iframe.
|
1025
|
+
// 4. Nope, sorry.
|
1026
|
+
utils.isXHRCorsCapable = function () {
|
1027
|
+
if (_window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest()) {
|
1028
|
+
return 1;
|
1029
|
+
}
|
1030
|
+
// XDomainRequest doesn't work if page is served from file://
|
1031
|
+
if (_window.XDomainRequest && _document.domain) {
|
1032
|
+
return 2;
|
1033
|
+
}
|
1034
|
+
if (IframeTransport.enabled()) {
|
1035
|
+
return 3;
|
1036
|
+
}
|
1037
|
+
return 4;
|
1038
|
+
};
|
1039
|
+
// [*] End of lib/dom2.js
|
1040
|
+
|
1041
|
+
|
1042
|
+
// [*] Including lib/sockjs.js
|
1043
|
+
/*
|
1044
|
+
* ***** BEGIN LICENSE BLOCK *****
|
1045
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
1046
|
+
*
|
1047
|
+
* For the license see COPYING.
|
1048
|
+
* ***** END LICENSE BLOCK *****
|
1049
|
+
*/
|
1050
|
+
|
1051
|
+
var SockJS = function (url, dep_protocols_whitelist, options) {
|
1052
|
+
if (this === _window) {
|
1053
|
+
// makes `new` optional
|
1054
|
+
return new SockJS(url, dep_protocols_whitelist, options);
|
1055
|
+
}
|
1056
|
+
|
1057
|
+
var that = this, protocols_whitelist;
|
1058
|
+
that._options = {
|
1059
|
+
devel: false, debug: false, protocols_whitelist: [],
|
1060
|
+
info: undefined, rtt: undefined
|
1061
|
+
};
|
1062
|
+
if (options) {
|
1063
|
+
utils.objectExtend(that._options, options);
|
1064
|
+
}
|
1065
|
+
that._base_url = utils.amendUrl(url);
|
1066
|
+
that._server = that._options.server || utils.random_number_string(1000);
|
1067
|
+
if (that._options.protocols_whitelist &&
|
1068
|
+
that._options.protocols_whitelist.length) {
|
1069
|
+
protocols_whitelist = that._options.protocols_whitelist;
|
1070
|
+
} else {
|
1071
|
+
// Deprecated API
|
1072
|
+
if (typeof dep_protocols_whitelist === 'string' &&
|
1073
|
+
dep_protocols_whitelist.length > 0) {
|
1074
|
+
protocols_whitelist = [dep_protocols_whitelist];
|
1075
|
+
} else if (utils.isArray(dep_protocols_whitelist)) {
|
1076
|
+
protocols_whitelist = dep_protocols_whitelist
|
1077
|
+
} else {
|
1078
|
+
protocols_whitelist = null;
|
1079
|
+
}
|
1080
|
+
if (protocols_whitelist) {
|
1081
|
+
that._debug('Deprecated API: Use "protocols_whitelist" option ' +
|
1082
|
+
'instead of supplying protocol list as a second ' +
|
1083
|
+
'parameter to SockJS constructor.');
|
1084
|
+
}
|
1085
|
+
}
|
1086
|
+
that._protocols = [];
|
1087
|
+
that.protocol = null;
|
1088
|
+
that.readyState = SockJS.CONNECTING;
|
1089
|
+
that._ir = createInfoReceiver(that._base_url);
|
1090
|
+
that._ir.onfinish = function (info, rtt) {
|
1091
|
+
that._ir = null;
|
1092
|
+
if (info) {
|
1093
|
+
if (that._options.info) {
|
1094
|
+
// Override if user supplies the option
|
1095
|
+
info = utils.objectExtend(info, that._options.info);
|
1096
|
+
}
|
1097
|
+
if (that._options.rtt) {
|
1098
|
+
rtt = that._options.rtt;
|
1099
|
+
}
|
1100
|
+
that._applyInfo(info, rtt, protocols_whitelist);
|
1101
|
+
that._didClose();
|
1102
|
+
} else {
|
1103
|
+
that._didClose(1002, 'Can\'t connect to server', true);
|
1104
|
+
}
|
1105
|
+
};
|
1106
|
+
};
|
1107
|
+
// Inheritance
|
1108
|
+
SockJS.prototype = new REventTarget();
|
1109
|
+
|
1110
|
+
SockJS.version = "0.3.4";
|
1111
|
+
|
1112
|
+
SockJS.CONNECTING = 0;
|
1113
|
+
SockJS.OPEN = 1;
|
1114
|
+
SockJS.CLOSING = 2;
|
1115
|
+
SockJS.CLOSED = 3;
|
1116
|
+
|
1117
|
+
SockJS.prototype._debug = function () {
|
1118
|
+
if (this._options.debug)
|
1119
|
+
utils.log.apply(utils, arguments);
|
1120
|
+
};
|
1121
|
+
|
1122
|
+
SockJS.prototype._dispatchOpen = function () {
|
1123
|
+
var that = this;
|
1124
|
+
if (that.readyState === SockJS.CONNECTING) {
|
1125
|
+
if (that._transport_tref) {
|
1126
|
+
clearTimeout(that._transport_tref);
|
1127
|
+
that._transport_tref = null;
|
1128
|
+
}
|
1129
|
+
that.readyState = SockJS.OPEN;
|
1130
|
+
that.dispatchEvent(new SimpleEvent("open"));
|
1131
|
+
} else {
|
1132
|
+
// The server might have been restarted, and lost track of our
|
1133
|
+
// connection.
|
1134
|
+
that._didClose(1006, "Server lost session");
|
1135
|
+
}
|
1136
|
+
};
|
1137
|
+
|
1138
|
+
SockJS.prototype._dispatchMessage = function (data) {
|
1139
|
+
var that = this;
|
1140
|
+
if (that.readyState !== SockJS.OPEN)
|
1141
|
+
return;
|
1142
|
+
that.dispatchEvent(new SimpleEvent("message", {data: data}));
|
1143
|
+
};
|
1144
|
+
|
1145
|
+
SockJS.prototype._dispatchHeartbeat = function (data) {
|
1146
|
+
var that = this;
|
1147
|
+
if (that.readyState !== SockJS.OPEN)
|
1148
|
+
return;
|
1149
|
+
that.dispatchEvent(new SimpleEvent('heartbeat', {}));
|
1150
|
+
};
|
1151
|
+
|
1152
|
+
SockJS.prototype._didClose = function (code, reason, force) {
|
1153
|
+
var that = this;
|
1154
|
+
if (that.readyState !== SockJS.CONNECTING &&
|
1155
|
+
that.readyState !== SockJS.OPEN &&
|
1156
|
+
that.readyState !== SockJS.CLOSING)
|
1157
|
+
throw new Error('INVALID_STATE_ERR');
|
1158
|
+
if (that._ir) {
|
1159
|
+
that._ir.nuke();
|
1160
|
+
that._ir = null;
|
1161
|
+
}
|
1162
|
+
|
1163
|
+
if (that._transport) {
|
1164
|
+
that._transport.doCleanup();
|
1165
|
+
that._transport = null;
|
1166
|
+
}
|
1167
|
+
|
1168
|
+
var close_event = new SimpleEvent("close", {
|
1169
|
+
code: code,
|
1170
|
+
reason: reason,
|
1171
|
+
wasClean: utils.userSetCode(code)
|
1172
|
+
});
|
1173
|
+
|
1174
|
+
if (!utils.userSetCode(code) &&
|
1175
|
+
that.readyState === SockJS.CONNECTING && !force) {
|
1176
|
+
if (that._try_next_protocol(close_event)) {
|
1177
|
+
return;
|
1178
|
+
}
|
1179
|
+
close_event = new SimpleEvent("close", {
|
1180
|
+
code: 2000,
|
1181
|
+
reason: "All transports failed",
|
1182
|
+
wasClean: false,
|
1183
|
+
last_event: close_event
|
1184
|
+
});
|
1185
|
+
}
|
1186
|
+
that.readyState = SockJS.CLOSED;
|
1187
|
+
|
1188
|
+
utils.delay(function () {
|
1189
|
+
that.dispatchEvent(close_event);
|
1190
|
+
});
|
1191
|
+
};
|
1192
|
+
|
1193
|
+
SockJS.prototype._didMessage = function (data) {
|
1194
|
+
var that = this;
|
1195
|
+
var type = data.slice(0, 1);
|
1196
|
+
switch (type) {
|
1197
|
+
case 'o':
|
1198
|
+
that._dispatchOpen();
|
1199
|
+
break;
|
1200
|
+
case 'a':
|
1201
|
+
var payload = JSON.parse(data.slice(1) || '[]');
|
1202
|
+
for (var i = 0; i < payload.length; i++) {
|
1203
|
+
that._dispatchMessage(payload[i]);
|
1204
|
+
}
|
1205
|
+
break;
|
1206
|
+
case 'm':
|
1207
|
+
var payload = JSON.parse(data.slice(1) || 'null');
|
1208
|
+
that._dispatchMessage(payload);
|
1209
|
+
break;
|
1210
|
+
case 'c':
|
1211
|
+
var payload = JSON.parse(data.slice(1) || '[]');
|
1212
|
+
that._didClose(payload[0], payload[1]);
|
1213
|
+
break;
|
1214
|
+
case 'h':
|
1215
|
+
that._dispatchHeartbeat();
|
1216
|
+
break;
|
1217
|
+
}
|
1218
|
+
};
|
1219
|
+
|
1220
|
+
SockJS.prototype._try_next_protocol = function (close_event) {
|
1221
|
+
var that = this;
|
1222
|
+
if (that.protocol) {
|
1223
|
+
that._debug('Closed transport:', that.protocol, '' + close_event);
|
1224
|
+
that.protocol = null;
|
1225
|
+
}
|
1226
|
+
if (that._transport_tref) {
|
1227
|
+
clearTimeout(that._transport_tref);
|
1228
|
+
that._transport_tref = null;
|
1229
|
+
}
|
1230
|
+
|
1231
|
+
while (1) {
|
1232
|
+
var protocol = that.protocol = that._protocols.shift();
|
1233
|
+
if (!protocol) {
|
1234
|
+
return false;
|
1235
|
+
}
|
1236
|
+
// Some protocols require access to `body`, what if were in
|
1237
|
+
// the `head`?
|
1238
|
+
if (SockJS[protocol] &&
|
1239
|
+
SockJS[protocol].need_body === true &&
|
1240
|
+
(!_document.body ||
|
1241
|
+
(typeof _document.readyState !== 'undefined'
|
1242
|
+
&& _document.readyState !== 'complete'))) {
|
1243
|
+
that._protocols.unshift(protocol);
|
1244
|
+
that.protocol = 'waiting-for-load';
|
1245
|
+
utils.attachEvent('load', function () {
|
1246
|
+
that._try_next_protocol();
|
1247
|
+
});
|
1248
|
+
return true;
|
1249
|
+
}
|
1250
|
+
|
1251
|
+
if (!SockJS[protocol] ||
|
1252
|
+
!SockJS[protocol].enabled(that._options)) {
|
1253
|
+
that._debug('Skipping transport:', protocol);
|
1254
|
+
} else {
|
1255
|
+
var roundTrips = SockJS[protocol].roundTrips || 1;
|
1256
|
+
var to = ((that._options.rto || 0) * roundTrips) || 5000;
|
1257
|
+
that._transport_tref = utils.delay(to, function () {
|
1258
|
+
if (that.readyState === SockJS.CONNECTING) {
|
1259
|
+
// I can't understand how it is possible to run
|
1260
|
+
// this timer, when the state is CLOSED, but
|
1261
|
+
// apparently in IE everythin is possible.
|
1262
|
+
that._didClose(2007, "Transport timeouted");
|
1263
|
+
}
|
1264
|
+
});
|
1265
|
+
|
1266
|
+
var connid = utils.random_string(8);
|
1267
|
+
var trans_url = that._base_url + '/' + that._server + '/' + connid;
|
1268
|
+
that._debug('Opening transport:', protocol, ' url:' + trans_url,
|
1269
|
+
' RTO:' + that._options.rto);
|
1270
|
+
that._transport = new SockJS[protocol](that, trans_url,
|
1271
|
+
that._base_url);
|
1272
|
+
return true;
|
1273
|
+
}
|
1274
|
+
}
|
1275
|
+
};
|
1276
|
+
|
1277
|
+
SockJS.prototype.close = function (code, reason) {
|
1278
|
+
var that = this;
|
1279
|
+
if (code && !utils.userSetCode(code))
|
1280
|
+
throw new Error("INVALID_ACCESS_ERR");
|
1281
|
+
if (that.readyState !== SockJS.CONNECTING &&
|
1282
|
+
that.readyState !== SockJS.OPEN) {
|
1283
|
+
return false;
|
1284
|
+
}
|
1285
|
+
that.readyState = SockJS.CLOSING;
|
1286
|
+
that._didClose(code || 1000, reason || "Normal closure");
|
1287
|
+
return true;
|
1288
|
+
};
|
1289
|
+
|
1290
|
+
SockJS.prototype.send = function (data) {
|
1291
|
+
var that = this;
|
1292
|
+
if (that.readyState === SockJS.CONNECTING)
|
1293
|
+
throw new Error('INVALID_STATE_ERR');
|
1294
|
+
if (that.readyState === SockJS.OPEN) {
|
1295
|
+
that._transport.doSend(utils.quote('' + data));
|
1296
|
+
}
|
1297
|
+
return true;
|
1298
|
+
};
|
1299
|
+
|
1300
|
+
SockJS.prototype._applyInfo = function (info, rtt, protocols_whitelist) {
|
1301
|
+
var that = this;
|
1302
|
+
that._options.info = info;
|
1303
|
+
that._options.rtt = rtt;
|
1304
|
+
that._options.rto = utils.countRTO(rtt);
|
1305
|
+
that._options.info.null_origin = !_document.domain;
|
1306
|
+
var probed = utils.probeProtocols();
|
1307
|
+
that._protocols = utils.detectProtocols(probed, protocols_whitelist, info);
|
1308
|
+
};
|
1309
|
+
// [*] End of lib/sockjs.js
|
1310
|
+
|
1311
|
+
|
1312
|
+
// [*] Including lib/trans-websocket.js
|
1313
|
+
/*
|
1314
|
+
* ***** BEGIN LICENSE BLOCK *****
|
1315
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
1316
|
+
*
|
1317
|
+
* For the license see COPYING.
|
1318
|
+
* ***** END LICENSE BLOCK *****
|
1319
|
+
*/
|
1320
|
+
|
1321
|
+
var WebSocketTransport = SockJS.websocket = function (ri, trans_url) {
|
1322
|
+
var that = this;
|
1323
|
+
var url = trans_url + '/websocket';
|
1324
|
+
if (url.slice(0, 5) === 'https') {
|
1325
|
+
url = 'wss' + url.slice(5);
|
1326
|
+
} else {
|
1327
|
+
url = 'ws' + url.slice(4);
|
1328
|
+
}
|
1329
|
+
that.ri = ri;
|
1330
|
+
that.url = url;
|
1331
|
+
var Constructor = _window.WebSocket || _window.MozWebSocket;
|
1332
|
+
|
1333
|
+
that.ws = new Constructor(that.url);
|
1334
|
+
that.ws.onmessage = function (e) {
|
1335
|
+
that.ri._didMessage(e.data);
|
1336
|
+
};
|
1337
|
+
// Firefox has an interesting bug. If a websocket connection is
|
1338
|
+
// created after onunload, it stays alive even when user
|
1339
|
+
// navigates away from the page. In such situation let's lie -
|
1340
|
+
// let's not open the ws connection at all. See:
|
1341
|
+
// https://github.com/sockjs/sockjs-client/issues/28
|
1342
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=696085
|
1343
|
+
that.unload_ref = utils.unload_add(function () {
|
1344
|
+
that.ws.close()
|
1345
|
+
});
|
1346
|
+
that.ws.onclose = function () {
|
1347
|
+
that.ri._didMessage(utils.closeFrame(1006, "WebSocket connection broken"));
|
1348
|
+
};
|
1349
|
+
};
|
1350
|
+
|
1351
|
+
WebSocketTransport.prototype.doSend = function (data) {
|
1352
|
+
this.ws.send('[' + data + ']');
|
1353
|
+
};
|
1354
|
+
|
1355
|
+
WebSocketTransport.prototype.doCleanup = function () {
|
1356
|
+
var that = this;
|
1357
|
+
var ws = that.ws;
|
1358
|
+
if (ws) {
|
1359
|
+
ws.onmessage = ws.onclose = null;
|
1360
|
+
ws.close();
|
1361
|
+
utils.unload_del(that.unload_ref);
|
1362
|
+
that.unload_ref = that.ri = that.ws = null;
|
1363
|
+
}
|
1364
|
+
};
|
1365
|
+
|
1366
|
+
WebSocketTransport.enabled = function () {
|
1367
|
+
return !!(_window.WebSocket || _window.MozWebSocket);
|
1368
|
+
};
|
1369
|
+
|
1370
|
+
// In theory, ws should require 1 round trip. But in chrome, this is
|
1371
|
+
// not very stable over SSL. Most likely a ws connection requires a
|
1372
|
+
// separate SSL connection, in which case 2 round trips are an
|
1373
|
+
// absolute minumum.
|
1374
|
+
WebSocketTransport.roundTrips = 2;
|
1375
|
+
// [*] End of lib/trans-websocket.js
|
1376
|
+
|
1377
|
+
|
1378
|
+
// [*] Including lib/trans-sender.js
|
1379
|
+
/*
|
1380
|
+
* ***** BEGIN LICENSE BLOCK *****
|
1381
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
1382
|
+
*
|
1383
|
+
* For the license see COPYING.
|
1384
|
+
* ***** END LICENSE BLOCK *****
|
1385
|
+
*/
|
1386
|
+
|
1387
|
+
var BufferedSender = function () {
|
1388
|
+
};
|
1389
|
+
BufferedSender.prototype.send_constructor = function (sender) {
|
1390
|
+
var that = this;
|
1391
|
+
that.send_buffer = [];
|
1392
|
+
that.sender = sender;
|
1393
|
+
};
|
1394
|
+
BufferedSender.prototype.doSend = function (message) {
|
1395
|
+
var that = this;
|
1396
|
+
that.send_buffer.push(message);
|
1397
|
+
if (!that.send_stop) {
|
1398
|
+
that.send_schedule();
|
1399
|
+
}
|
1400
|
+
};
|
1401
|
+
|
1402
|
+
// For polling transports in a situation when in the message callback,
|
1403
|
+
// new message is being send. If the sending connection was started
|
1404
|
+
// before receiving one, it is possible to saturate the network and
|
1405
|
+
// timeout due to the lack of receiving socket. To avoid that we delay
|
1406
|
+
// sending messages by some small time, in order to let receiving
|
1407
|
+
// connection be started beforehand. This is only a halfmeasure and
|
1408
|
+
// does not fix the big problem, but it does make the tests go more
|
1409
|
+
// stable on slow networks.
|
1410
|
+
BufferedSender.prototype.send_schedule_wait = function () {
|
1411
|
+
var that = this;
|
1412
|
+
var tref;
|
1413
|
+
that.send_stop = function () {
|
1414
|
+
that.send_stop = null;
|
1415
|
+
clearTimeout(tref);
|
1416
|
+
};
|
1417
|
+
tref = utils.delay(25, function () {
|
1418
|
+
that.send_stop = null;
|
1419
|
+
that.send_schedule();
|
1420
|
+
});
|
1421
|
+
};
|
1422
|
+
|
1423
|
+
BufferedSender.prototype.send_schedule = function () {
|
1424
|
+
var that = this;
|
1425
|
+
if (that.send_buffer.length > 0) {
|
1426
|
+
var payload = '[' + that.send_buffer.join(',') + ']';
|
1427
|
+
that.send_stop = that.sender(that.trans_url, payload, function (success, abort_reason) {
|
1428
|
+
that.send_stop = null;
|
1429
|
+
if (success === false) {
|
1430
|
+
that.ri._didClose(1006, 'Sending error ' + abort_reason);
|
1431
|
+
} else {
|
1432
|
+
that.send_schedule_wait();
|
1433
|
+
}
|
1434
|
+
});
|
1435
|
+
that.send_buffer = [];
|
1436
|
+
}
|
1437
|
+
};
|
1438
|
+
|
1439
|
+
BufferedSender.prototype.send_destructor = function () {
|
1440
|
+
var that = this;
|
1441
|
+
if (that._send_stop) {
|
1442
|
+
that._send_stop();
|
1443
|
+
}
|
1444
|
+
that._send_stop = null;
|
1445
|
+
};
|
1446
|
+
|
1447
|
+
var jsonPGenericSender = function (url, payload, callback) {
|
1448
|
+
var that = this;
|
1449
|
+
|
1450
|
+
if (!('_send_form' in that)) {
|
1451
|
+
var form = that._send_form = _document.createElement('form');
|
1452
|
+
var area = that._send_area = _document.createElement('textarea');
|
1453
|
+
area.name = 'd';
|
1454
|
+
form.style.display = 'none';
|
1455
|
+
form.style.position = 'absolute';
|
1456
|
+
form.method = 'POST';
|
1457
|
+
form.enctype = 'application/x-www-form-urlencoded';
|
1458
|
+
form.acceptCharset = "UTF-8";
|
1459
|
+
form.appendChild(area);
|
1460
|
+
_document.body.appendChild(form);
|
1461
|
+
}
|
1462
|
+
var form = that._send_form;
|
1463
|
+
var area = that._send_area;
|
1464
|
+
var id = 'a' + utils.random_string(8);
|
1465
|
+
form.target = id;
|
1466
|
+
form.action = url + '/jsonp_send?i=' + id;
|
1467
|
+
|
1468
|
+
var iframe;
|
1469
|
+
try {
|
1470
|
+
// ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
|
1471
|
+
iframe = _document.createElement('<iframe name="' + id + '">');
|
1472
|
+
} catch (x) {
|
1473
|
+
iframe = _document.createElement('iframe');
|
1474
|
+
iframe.name = id;
|
1475
|
+
}
|
1476
|
+
iframe.id = id;
|
1477
|
+
form.appendChild(iframe);
|
1478
|
+
iframe.style.display = 'none';
|
1479
|
+
|
1480
|
+
try {
|
1481
|
+
area.value = payload;
|
1482
|
+
} catch (e) {
|
1483
|
+
utils.log('Your browser is seriously broken. Go home! ' + e.message);
|
1484
|
+
}
|
1485
|
+
form.submit();
|
1486
|
+
|
1487
|
+
var completed = function (e) {
|
1488
|
+
if (!iframe.onerror) return;
|
1489
|
+
iframe.onreadystatechange = iframe.onerror = iframe.onload = null;
|
1490
|
+
// Opera mini doesn't like if we GC iframe
|
1491
|
+
// immediately, thus this timeout.
|
1492
|
+
utils.delay(500, function () {
|
1493
|
+
iframe.parentNode.removeChild(iframe);
|
1494
|
+
iframe = null;
|
1495
|
+
});
|
1496
|
+
area.value = '';
|
1497
|
+
// It is not possible to detect if the iframe succeeded or
|
1498
|
+
// failed to submit our form.
|
1499
|
+
callback(true);
|
1500
|
+
};
|
1501
|
+
iframe.onerror = iframe.onload = completed;
|
1502
|
+
iframe.onreadystatechange = function (e) {
|
1503
|
+
if (iframe.readyState == 'complete') completed();
|
1504
|
+
};
|
1505
|
+
return completed;
|
1506
|
+
};
|
1507
|
+
|
1508
|
+
var createAjaxSender = function (AjaxObject) {
|
1509
|
+
return function (url, payload, callback) {
|
1510
|
+
var xo = new AjaxObject('POST', url + '/xhr_send', payload);
|
1511
|
+
xo.onfinish = function (status, text) {
|
1512
|
+
callback(status === 200 || status === 204,
|
1513
|
+
'http status ' + status);
|
1514
|
+
};
|
1515
|
+
return function (abort_reason) {
|
1516
|
+
callback(false, abort_reason);
|
1517
|
+
};
|
1518
|
+
};
|
1519
|
+
};
|
1520
|
+
// [*] End of lib/trans-sender.js
|
1521
|
+
|
1522
|
+
|
1523
|
+
// [*] Including lib/trans-jsonp-receiver.js
|
1524
|
+
/*
|
1525
|
+
* ***** BEGIN LICENSE BLOCK *****
|
1526
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
1527
|
+
*
|
1528
|
+
* For the license see COPYING.
|
1529
|
+
* ***** END LICENSE BLOCK *****
|
1530
|
+
*/
|
1531
|
+
|
1532
|
+
// Parts derived from Socket.io:
|
1533
|
+
// https://github.com/LearnBoost/socket.io/blob/0.6.17/lib/socket.io/transports/jsonp-polling.js
|
1534
|
+
// and jQuery-JSONP:
|
1535
|
+
// https://code.google.com/p/jquery-jsonp/source/browse/trunk/core/jquery.jsonp.js
|
1536
|
+
var jsonPGenericReceiver = function (url, callback) {
|
1537
|
+
var tref;
|
1538
|
+
var script = _document.createElement('script');
|
1539
|
+
var script2; // Opera synchronous load trick.
|
1540
|
+
var close_script = function (frame) {
|
1541
|
+
if (script2) {
|
1542
|
+
script2.parentNode.removeChild(script2);
|
1543
|
+
script2 = null;
|
1544
|
+
}
|
1545
|
+
if (script) {
|
1546
|
+
clearTimeout(tref);
|
1547
|
+
// Unfortunately, you can't really abort script loading of
|
1548
|
+
// the script.
|
1549
|
+
script.parentNode.removeChild(script);
|
1550
|
+
script.onreadystatechange = script.onerror =
|
1551
|
+
script.onload = script.onclick = null;
|
1552
|
+
script = null;
|
1553
|
+
callback(frame);
|
1554
|
+
callback = null;
|
1555
|
+
}
|
1556
|
+
};
|
1557
|
+
|
1558
|
+
// IE9 fires 'error' event after orsc or before, in random order.
|
1559
|
+
var loaded_okay = false;
|
1560
|
+
var error_timer = null;
|
1561
|
+
|
1562
|
+
script.id = 'a' + utils.random_string(8);
|
1563
|
+
script.src = url;
|
1564
|
+
script.type = 'text/javascript';
|
1565
|
+
script.charset = 'UTF-8';
|
1566
|
+
script.onerror = function (e) {
|
1567
|
+
if (!error_timer) {
|
1568
|
+
// Delay firing close_script.
|
1569
|
+
error_timer = setTimeout(function () {
|
1570
|
+
if (!loaded_okay) {
|
1571
|
+
close_script(utils.closeFrame(
|
1572
|
+
1006,
|
1573
|
+
"JSONP script loaded abnormally (onerror)"));
|
1574
|
+
}
|
1575
|
+
}, 1000);
|
1576
|
+
}
|
1577
|
+
};
|
1578
|
+
script.onload = function (e) {
|
1579
|
+
close_script(utils.closeFrame(1006, "JSONP script loaded abnormally (onload)"));
|
1580
|
+
};
|
1581
|
+
|
1582
|
+
script.onreadystatechange = function (e) {
|
1583
|
+
if (/loaded|closed/.test(script.readyState)) {
|
1584
|
+
if (script && script.htmlFor && script.onclick) {
|
1585
|
+
loaded_okay = true;
|
1586
|
+
try {
|
1587
|
+
// In IE, actually execute the script.
|
1588
|
+
script.onclick();
|
1589
|
+
} catch (x) {
|
1590
|
+
}
|
1591
|
+
}
|
1592
|
+
if (script) {
|
1593
|
+
close_script(utils.closeFrame(1006, "JSONP script loaded abnormally (onreadystatechange)"));
|
1594
|
+
}
|
1595
|
+
}
|
1596
|
+
};
|
1597
|
+
// IE: event/htmlFor/onclick trick.
|
1598
|
+
// One can't rely on proper order for onreadystatechange. In order to
|
1599
|
+
// make sure, set a 'htmlFor' and 'event' properties, so that
|
1600
|
+
// script code will be installed as 'onclick' handler for the
|
1601
|
+
// script object. Later, onreadystatechange, manually execute this
|
1602
|
+
// code. FF and Chrome doesn't work with 'event' and 'htmlFor'
|
1603
|
+
// set. For reference see:
|
1604
|
+
// http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
|
1605
|
+
// Also, read on that about script ordering:
|
1606
|
+
// http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
|
1607
|
+
if (typeof script.async === 'undefined' && _document.attachEvent) {
|
1608
|
+
// According to mozilla docs, in recent browsers script.async defaults
|
1609
|
+
// to 'true', so we may use it to detect a good browser:
|
1610
|
+
// https://developer.mozilla.org/en/HTML/Element/script
|
1611
|
+
if (!/opera/i.test(navigator.userAgent)) {
|
1612
|
+
// Naively assume we're in IE
|
1613
|
+
try {
|
1614
|
+
script.htmlFor = script.id;
|
1615
|
+
script.event = "onclick";
|
1616
|
+
} catch (x) {
|
1617
|
+
}
|
1618
|
+
script.async = true;
|
1619
|
+
} else {
|
1620
|
+
// Opera, second sync script hack
|
1621
|
+
script2 = _document.createElement('script');
|
1622
|
+
script2.text = "try{var a = document.getElementById('" + script.id + "'); if(a)a.onerror();}catch(x){};";
|
1623
|
+
script.async = script2.async = false;
|
1624
|
+
}
|
1625
|
+
}
|
1626
|
+
if (typeof script.async !== 'undefined') {
|
1627
|
+
script.async = true;
|
1628
|
+
}
|
1629
|
+
|
1630
|
+
// Fallback mostly for Konqueror - stupid timer, 35 seconds shall be plenty.
|
1631
|
+
tref = setTimeout(function () {
|
1632
|
+
close_script(utils.closeFrame(1006, "JSONP script loaded abnormally (timeout)"));
|
1633
|
+
}, 35000);
|
1634
|
+
|
1635
|
+
var head = _document.getElementsByTagName('head')[0];
|
1636
|
+
head.insertBefore(script, head.firstChild);
|
1637
|
+
if (script2) {
|
1638
|
+
head.insertBefore(script2, head.firstChild);
|
1639
|
+
}
|
1640
|
+
return close_script;
|
1641
|
+
};
|
1642
|
+
// [*] End of lib/trans-jsonp-receiver.js
|
1643
|
+
|
1644
|
+
|
1645
|
+
// [*] Including lib/trans-jsonp-polling.js
|
1646
|
+
/*
|
1647
|
+
* ***** BEGIN LICENSE BLOCK *****
|
1648
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
1649
|
+
*
|
1650
|
+
* For the license see COPYING.
|
1651
|
+
* ***** END LICENSE BLOCK *****
|
1652
|
+
*/
|
1653
|
+
|
1654
|
+
// The simplest and most robust transport, using the well-know cross
|
1655
|
+
// domain hack - JSONP. This transport is quite inefficient - one
|
1656
|
+
// mssage could use up to one http request. But at least it works almost
|
1657
|
+
// everywhere.
|
1658
|
+
// Known limitations:
|
1659
|
+
// o you will get a spinning cursor
|
1660
|
+
// o for Konqueror a dumb timer is needed to detect errors
|
1661
|
+
|
1662
|
+
|
1663
|
+
var JsonPTransport = SockJS['jsonp-polling'] = function (ri, trans_url) {
|
1664
|
+
utils.polluteGlobalNamespace();
|
1665
|
+
var that = this;
|
1666
|
+
that.ri = ri;
|
1667
|
+
that.trans_url = trans_url;
|
1668
|
+
that.send_constructor(jsonPGenericSender);
|
1669
|
+
that._schedule_recv();
|
1670
|
+
};
|
1671
|
+
|
1672
|
+
// Inheritnace
|
1673
|
+
JsonPTransport.prototype = new BufferedSender();
|
1674
|
+
|
1675
|
+
JsonPTransport.prototype._schedule_recv = function () {
|
1676
|
+
var that = this;
|
1677
|
+
var callback = function (data) {
|
1678
|
+
that._recv_stop = null;
|
1679
|
+
if (data) {
|
1680
|
+
// no data - heartbeat;
|
1681
|
+
if (!that._is_closing) {
|
1682
|
+
that.ri._didMessage(data);
|
1683
|
+
}
|
1684
|
+
}
|
1685
|
+
// The message can be a close message, and change is_closing state.
|
1686
|
+
if (!that._is_closing) {
|
1687
|
+
that._schedule_recv();
|
1688
|
+
}
|
1689
|
+
};
|
1690
|
+
that._recv_stop = jsonPReceiverWrapper(that.trans_url + '/jsonp',
|
1691
|
+
jsonPGenericReceiver, callback);
|
1692
|
+
};
|
1693
|
+
|
1694
|
+
JsonPTransport.enabled = function () {
|
1695
|
+
return true;
|
1696
|
+
};
|
1697
|
+
|
1698
|
+
JsonPTransport.need_body = true;
|
1699
|
+
|
1700
|
+
|
1701
|
+
JsonPTransport.prototype.doCleanup = function () {
|
1702
|
+
var that = this;
|
1703
|
+
that._is_closing = true;
|
1704
|
+
if (that._recv_stop) {
|
1705
|
+
that._recv_stop();
|
1706
|
+
}
|
1707
|
+
that.ri = that._recv_stop = null;
|
1708
|
+
that.send_destructor();
|
1709
|
+
};
|
1710
|
+
|
1711
|
+
|
1712
|
+
// Abstract away code that handles global namespace pollution.
|
1713
|
+
var jsonPReceiverWrapper = function (url, constructReceiver, user_callback) {
|
1714
|
+
var id = 'a' + utils.random_string(6);
|
1715
|
+
var url_id = url + '?c=' + escape(WPrefix + '.' + id);
|
1716
|
+
|
1717
|
+
// Unfortunately it is not possible to abort loading of the
|
1718
|
+
// script. We need to keep track of frake close frames.
|
1719
|
+
var aborting = 0;
|
1720
|
+
|
1721
|
+
// Callback will be called exactly once.
|
1722
|
+
var callback = function (frame) {
|
1723
|
+
switch (aborting) {
|
1724
|
+
case 0:
|
1725
|
+
// Normal behaviour - delete hook _and_ emit message.
|
1726
|
+
delete _window[WPrefix][id];
|
1727
|
+
user_callback(frame);
|
1728
|
+
break;
|
1729
|
+
case 1:
|
1730
|
+
// Fake close frame - emit but don't delete hook.
|
1731
|
+
user_callback(frame);
|
1732
|
+
aborting = 2;
|
1733
|
+
break;
|
1734
|
+
case 2:
|
1735
|
+
// Got frame after connection was closed, delete hook, don't emit.
|
1736
|
+
delete _window[WPrefix][id];
|
1737
|
+
break;
|
1738
|
+
}
|
1739
|
+
};
|
1740
|
+
|
1741
|
+
var close_script = constructReceiver(url_id, callback);
|
1742
|
+
_window[WPrefix][id] = close_script;
|
1743
|
+
var stop = function () {
|
1744
|
+
if (_window[WPrefix][id]) {
|
1745
|
+
aborting = 1;
|
1746
|
+
_window[WPrefix][id](utils.closeFrame(1000, "JSONP user aborted read"));
|
1747
|
+
}
|
1748
|
+
};
|
1749
|
+
return stop;
|
1750
|
+
};
|
1751
|
+
// [*] End of lib/trans-jsonp-polling.js
|
1752
|
+
|
1753
|
+
|
1754
|
+
// [*] Including lib/trans-xhr.js
|
1755
|
+
/*
|
1756
|
+
* ***** BEGIN LICENSE BLOCK *****
|
1757
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
1758
|
+
*
|
1759
|
+
* For the license see COPYING.
|
1760
|
+
* ***** END LICENSE BLOCK *****
|
1761
|
+
*/
|
1762
|
+
|
1763
|
+
var AjaxBasedTransport = function () {
|
1764
|
+
};
|
1765
|
+
AjaxBasedTransport.prototype = new BufferedSender();
|
1766
|
+
|
1767
|
+
AjaxBasedTransport.prototype.run = function (ri, trans_url,
|
1768
|
+
url_suffix, Receiver, AjaxObject) {
|
1769
|
+
var that = this;
|
1770
|
+
that.ri = ri;
|
1771
|
+
that.trans_url = trans_url;
|
1772
|
+
that.send_constructor(createAjaxSender(AjaxObject));
|
1773
|
+
that.poll = new Polling(ri, Receiver,
|
1774
|
+
trans_url + url_suffix, AjaxObject);
|
1775
|
+
};
|
1776
|
+
|
1777
|
+
AjaxBasedTransport.prototype.doCleanup = function () {
|
1778
|
+
var that = this;
|
1779
|
+
if (that.poll) {
|
1780
|
+
that.poll.abort();
|
1781
|
+
that.poll = null;
|
1782
|
+
}
|
1783
|
+
};
|
1784
|
+
|
1785
|
+
// xhr-streaming
|
1786
|
+
var XhrStreamingTransport = SockJS['xhr-streaming'] = function (ri, trans_url) {
|
1787
|
+
this.run(ri, trans_url, '/xhr_streaming', XhrReceiver, utils.XHRCorsObject);
|
1788
|
+
};
|
1789
|
+
|
1790
|
+
XhrStreamingTransport.prototype = new AjaxBasedTransport();
|
1791
|
+
|
1792
|
+
XhrStreamingTransport.enabled = function () {
|
1793
|
+
// Support for CORS Ajax aka Ajax2? Opera 12 claims CORS but
|
1794
|
+
// doesn't do streaming.
|
1795
|
+
return (_window.XMLHttpRequest &&
|
1796
|
+
'withCredentials' in new XMLHttpRequest() &&
|
1797
|
+
(!/opera/i.test(navigator.userAgent)));
|
1798
|
+
};
|
1799
|
+
XhrStreamingTransport.roundTrips = 2; // preflight, ajax
|
1800
|
+
|
1801
|
+
// Safari gets confused when a streaming ajax request is started
|
1802
|
+
// before onload. This causes the load indicator to spin indefinetely.
|
1803
|
+
XhrStreamingTransport.need_body = true;
|
1804
|
+
|
1805
|
+
|
1806
|
+
// According to:
|
1807
|
+
// http://stackoverflow.com/questions/1641507/detect-browser-support-for-cross-domain-xmlhttprequests
|
1808
|
+
// http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
|
1809
|
+
|
1810
|
+
|
1811
|
+
// xdr-streaming
|
1812
|
+
var XdrStreamingTransport = SockJS['xdr-streaming'] = function (ri, trans_url) {
|
1813
|
+
this.run(ri, trans_url, '/xhr_streaming', XhrReceiver, utils.XDRObject);
|
1814
|
+
};
|
1815
|
+
|
1816
|
+
XdrStreamingTransport.prototype = new AjaxBasedTransport();
|
1817
|
+
|
1818
|
+
XdrStreamingTransport.enabled = function () {
|
1819
|
+
return !!_window.XDomainRequest;
|
1820
|
+
};
|
1821
|
+
XdrStreamingTransport.roundTrips = 2; // preflight, ajax
|
1822
|
+
|
1823
|
+
|
1824
|
+
// xhr-polling
|
1825
|
+
var XhrPollingTransport = SockJS['xhr-polling'] = function (ri, trans_url) {
|
1826
|
+
this.run(ri, trans_url, '/xhr', XhrReceiver, utils.XHRCorsObject);
|
1827
|
+
};
|
1828
|
+
|
1829
|
+
XhrPollingTransport.prototype = new AjaxBasedTransport();
|
1830
|
+
|
1831
|
+
XhrPollingTransport.enabled = XhrStreamingTransport.enabled;
|
1832
|
+
XhrPollingTransport.roundTrips = 2; // preflight, ajax
|
1833
|
+
|
1834
|
+
|
1835
|
+
// xdr-polling
|
1836
|
+
var XdrPollingTransport = SockJS['xdr-polling'] = function (ri, trans_url) {
|
1837
|
+
this.run(ri, trans_url, '/xhr', XhrReceiver, utils.XDRObject);
|
1838
|
+
};
|
1839
|
+
|
1840
|
+
XdrPollingTransport.prototype = new AjaxBasedTransport();
|
1841
|
+
|
1842
|
+
XdrPollingTransport.enabled = XdrStreamingTransport.enabled;
|
1843
|
+
XdrPollingTransport.roundTrips = 2; // preflight, ajax
|
1844
|
+
// [*] End of lib/trans-xhr.js
|
1845
|
+
|
1846
|
+
|
1847
|
+
// [*] Including lib/trans-iframe.js
|
1848
|
+
/*
|
1849
|
+
* ***** BEGIN LICENSE BLOCK *****
|
1850
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
1851
|
+
*
|
1852
|
+
* For the license see COPYING.
|
1853
|
+
* ***** END LICENSE BLOCK *****
|
1854
|
+
*/
|
1855
|
+
|
1856
|
+
// Few cool transports do work only for same-origin. In order to make
|
1857
|
+
// them working cross-domain we shall use iframe, served form the
|
1858
|
+
// remote domain. New browsers, have capabilities to communicate with
|
1859
|
+
// cross domain iframe, using postMessage(). In IE it was implemented
|
1860
|
+
// from IE 8+, but of course, IE got some details wrong:
|
1861
|
+
// http://msdn.microsoft.com/en-us/library/cc197015(v=VS.85).aspx
|
1862
|
+
// http://stevesouders.com/misc/test-postmessage.php
|
1863
|
+
|
1864
|
+
var IframeTransport = function () {
|
1865
|
+
};
|
1866
|
+
|
1867
|
+
IframeTransport.prototype.i_constructor = function (ri, trans_url, base_url) {
|
1868
|
+
var that = this;
|
1869
|
+
that.ri = ri;
|
1870
|
+
that.origin = utils.getOrigin(base_url);
|
1871
|
+
that.base_url = base_url;
|
1872
|
+
that.trans_url = trans_url;
|
1873
|
+
|
1874
|
+
var iframe_url = base_url + '/iframe.html';
|
1875
|
+
if (that.ri._options.devel) {
|
1876
|
+
iframe_url += '?t=' + (+new Date);
|
1877
|
+
}
|
1878
|
+
that.window_id = utils.random_string(8);
|
1879
|
+
iframe_url += '#' + that.window_id;
|
1880
|
+
|
1881
|
+
that.iframeObj = utils.createIframe(iframe_url, function (r) {
|
1882
|
+
that.ri._didClose(1006, "Unable to load an iframe (" + r + ")");
|
1883
|
+
});
|
1884
|
+
|
1885
|
+
that.onmessage_cb = utils.bind(that.onmessage, that);
|
1886
|
+
utils.attachMessage(that.onmessage_cb);
|
1887
|
+
};
|
1888
|
+
|
1889
|
+
IframeTransport.prototype.doCleanup = function () {
|
1890
|
+
var that = this;
|
1891
|
+
if (that.iframeObj) {
|
1892
|
+
utils.detachMessage(that.onmessage_cb);
|
1893
|
+
try {
|
1894
|
+
// When the iframe is not loaded, IE raises an exception
|
1895
|
+
// on 'contentWindow'.
|
1896
|
+
if (that.iframeObj.iframe.contentWindow) {
|
1897
|
+
that.postMessage('c');
|
1898
|
+
}
|
1899
|
+
} catch (x) {
|
1900
|
+
}
|
1901
|
+
that.iframeObj.cleanup();
|
1902
|
+
that.iframeObj = null;
|
1903
|
+
that.onmessage_cb = that.iframeObj = null;
|
1904
|
+
}
|
1905
|
+
};
|
1906
|
+
|
1907
|
+
IframeTransport.prototype.onmessage = function (e) {
|
1908
|
+
var that = this;
|
1909
|
+
if (e.origin !== that.origin) return;
|
1910
|
+
var window_id = e.data.slice(0, 8);
|
1911
|
+
var type = e.data.slice(8, 9);
|
1912
|
+
var data = e.data.slice(9);
|
1913
|
+
|
1914
|
+
if (window_id !== that.window_id) return;
|
1915
|
+
|
1916
|
+
switch (type) {
|
1917
|
+
case 's':
|
1918
|
+
that.iframeObj.loaded();
|
1919
|
+
that.postMessage('s', JSON.stringify([SockJS.version, that.protocol, that.trans_url, that.base_url]));
|
1920
|
+
break;
|
1921
|
+
case 't':
|
1922
|
+
that.ri._didMessage(data);
|
1923
|
+
break;
|
1924
|
+
}
|
1925
|
+
};
|
1926
|
+
|
1927
|
+
IframeTransport.prototype.postMessage = function (type, data) {
|
1928
|
+
var that = this;
|
1929
|
+
that.iframeObj.post(that.window_id + type + (data || ''), that.origin);
|
1930
|
+
};
|
1931
|
+
|
1932
|
+
IframeTransport.prototype.doSend = function (message) {
|
1933
|
+
this.postMessage('m', message);
|
1934
|
+
};
|
1935
|
+
|
1936
|
+
IframeTransport.enabled = function () {
|
1937
|
+
// postMessage misbehaves in konqueror 4.6.5 - the messages are delivered with
|
1938
|
+
// huge delay, or not at all.
|
1939
|
+
var konqueror = navigator && navigator.userAgent && navigator.userAgent.indexOf('Konqueror') !== -1;
|
1940
|
+
return ((typeof _window.postMessage === 'function' ||
|
1941
|
+
typeof _window.postMessage === 'object') && (!konqueror));
|
1942
|
+
};
|
1943
|
+
// [*] End of lib/trans-iframe.js
|
1944
|
+
|
1945
|
+
|
1946
|
+
// [*] Including lib/trans-iframe-within.js
|
1947
|
+
/*
|
1948
|
+
* ***** BEGIN LICENSE BLOCK *****
|
1949
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
1950
|
+
*
|
1951
|
+
* For the license see COPYING.
|
1952
|
+
* ***** END LICENSE BLOCK *****
|
1953
|
+
*/
|
1954
|
+
|
1955
|
+
var curr_window_id;
|
1956
|
+
|
1957
|
+
var postMessage = function (type, data) {
|
1958
|
+
if (parent !== _window) {
|
1959
|
+
parent.postMessage(curr_window_id + type + (data || ''), '*');
|
1960
|
+
} else {
|
1961
|
+
utils.log("Can't postMessage, no parent window.", type, data);
|
1962
|
+
}
|
1963
|
+
};
|
1964
|
+
|
1965
|
+
var FacadeJS = function () {
|
1966
|
+
};
|
1967
|
+
FacadeJS.prototype._didClose = function (code, reason) {
|
1968
|
+
postMessage('t', utils.closeFrame(code, reason));
|
1969
|
+
};
|
1970
|
+
FacadeJS.prototype._didMessage = function (frame) {
|
1971
|
+
postMessage('t', frame);
|
1972
|
+
};
|
1973
|
+
FacadeJS.prototype._doSend = function (data) {
|
1974
|
+
this._transport.doSend(data);
|
1975
|
+
};
|
1976
|
+
FacadeJS.prototype._doCleanup = function () {
|
1977
|
+
this._transport.doCleanup();
|
1978
|
+
};
|
1979
|
+
|
1980
|
+
utils.parent_origin = undefined;
|
1981
|
+
|
1982
|
+
SockJS.bootstrap_iframe = function () {
|
1983
|
+
var facade;
|
1984
|
+
curr_window_id = _document.location.hash.slice(1);
|
1985
|
+
var onMessage = function (e) {
|
1986
|
+
if (e.source !== parent) return;
|
1987
|
+
if (typeof utils.parent_origin === 'undefined')
|
1988
|
+
utils.parent_origin = e.origin;
|
1989
|
+
if (e.origin !== utils.parent_origin) return;
|
1990
|
+
|
1991
|
+
var window_id = e.data.slice(0, 8);
|
1992
|
+
var type = e.data.slice(8, 9);
|
1993
|
+
var data = e.data.slice(9);
|
1994
|
+
if (window_id !== curr_window_id) return;
|
1995
|
+
switch (type) {
|
1996
|
+
case 's':
|
1997
|
+
var p = JSON.parse(data);
|
1998
|
+
var version = p[0];
|
1999
|
+
var protocol = p[1];
|
2000
|
+
var trans_url = p[2];
|
2001
|
+
var base_url = p[3];
|
2002
|
+
if (version !== SockJS.version) {
|
2003
|
+
utils.log("Incompatibile SockJS! Main site uses:" +
|
2004
|
+
" \"" + version + "\", the iframe:" +
|
2005
|
+
" \"" + SockJS.version + "\".");
|
2006
|
+
}
|
2007
|
+
if (!utils.flatUrl(trans_url) || !utils.flatUrl(base_url)) {
|
2008
|
+
utils.log("Only basic urls are supported in SockJS");
|
2009
|
+
return;
|
2010
|
+
}
|
2011
|
+
|
2012
|
+
if (!utils.isSameOriginUrl(trans_url) ||
|
2013
|
+
!utils.isSameOriginUrl(base_url)) {
|
2014
|
+
utils.log("Can't connect to different domain from within an " +
|
2015
|
+
"iframe. (" + JSON.stringify([_window.location.href, trans_url, base_url]) +
|
2016
|
+
")");
|
2017
|
+
return;
|
2018
|
+
}
|
2019
|
+
facade = new FacadeJS();
|
2020
|
+
facade._transport = new FacadeJS[protocol](facade, trans_url, base_url);
|
2021
|
+
break;
|
2022
|
+
case 'm':
|
2023
|
+
facade._doSend(data);
|
2024
|
+
break;
|
2025
|
+
case 'c':
|
2026
|
+
if (facade)
|
2027
|
+
facade._doCleanup();
|
2028
|
+
facade = null;
|
2029
|
+
break;
|
2030
|
+
}
|
2031
|
+
};
|
2032
|
+
|
2033
|
+
// alert('test ticker');
|
2034
|
+
// facade = new FacadeJS();
|
2035
|
+
// facade._transport = new FacadeJS['w-iframe-xhr-polling'](facade, 'http://host.com:9999/ticker/12/basd');
|
2036
|
+
|
2037
|
+
utils.attachMessage(onMessage);
|
2038
|
+
|
2039
|
+
// Start
|
2040
|
+
postMessage('s');
|
2041
|
+
};
|
2042
|
+
// [*] End of lib/trans-iframe-within.js
|
2043
|
+
|
2044
|
+
|
2045
|
+
// [*] Including lib/info.js
|
2046
|
+
/*
|
2047
|
+
* ***** BEGIN LICENSE BLOCK *****
|
2048
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
2049
|
+
*
|
2050
|
+
* For the license see COPYING.
|
2051
|
+
* ***** END LICENSE BLOCK *****
|
2052
|
+
*/
|
2053
|
+
|
2054
|
+
var InfoReceiver = function (base_url, AjaxObject) {
|
2055
|
+
var that = this;
|
2056
|
+
utils.delay(function () {
|
2057
|
+
that.doXhr(base_url, AjaxObject);
|
2058
|
+
});
|
2059
|
+
};
|
2060
|
+
|
2061
|
+
InfoReceiver.prototype = new EventEmitter(['finish']);
|
2062
|
+
|
2063
|
+
InfoReceiver.prototype.doXhr = function (base_url, AjaxObject) {
|
2064
|
+
var that = this;
|
2065
|
+
var t0 = (new Date()).getTime();
|
2066
|
+
var xo = new AjaxObject('GET', base_url + '/info');
|
2067
|
+
|
2068
|
+
var tref = utils.delay(8000,
|
2069
|
+
function () {
|
2070
|
+
xo.ontimeout();
|
2071
|
+
});
|
2072
|
+
|
2073
|
+
xo.onfinish = function (status, text) {
|
2074
|
+
clearTimeout(tref);
|
2075
|
+
tref = null;
|
2076
|
+
if (status === 200) {
|
2077
|
+
var rtt = (new Date()).getTime() - t0;
|
2078
|
+
var info = JSON.parse(text);
|
2079
|
+
if (typeof info !== 'object') info = {};
|
2080
|
+
that.emit('finish', info, rtt);
|
2081
|
+
} else {
|
2082
|
+
that.emit('finish');
|
2083
|
+
}
|
2084
|
+
};
|
2085
|
+
xo.ontimeout = function () {
|
2086
|
+
xo.close();
|
2087
|
+
that.emit('finish');
|
2088
|
+
};
|
2089
|
+
};
|
2090
|
+
|
2091
|
+
var InfoReceiverIframe = function (base_url) {
|
2092
|
+
var that = this;
|
2093
|
+
var go = function () {
|
2094
|
+
var ifr = new IframeTransport();
|
2095
|
+
ifr.protocol = 'w-iframe-info-receiver';
|
2096
|
+
var fun = function (r) {
|
2097
|
+
if (typeof r === 'string' && r.substr(0, 1) === 'm') {
|
2098
|
+
var d = JSON.parse(r.substr(1));
|
2099
|
+
var info = d[0], rtt = d[1];
|
2100
|
+
that.emit('finish', info, rtt);
|
2101
|
+
} else {
|
2102
|
+
that.emit('finish');
|
2103
|
+
}
|
2104
|
+
ifr.doCleanup();
|
2105
|
+
ifr = null;
|
2106
|
+
};
|
2107
|
+
var mock_ri = {
|
2108
|
+
_options: {},
|
2109
|
+
_didClose: fun,
|
2110
|
+
_didMessage: fun
|
2111
|
+
};
|
2112
|
+
ifr.i_constructor(mock_ri, base_url, base_url);
|
2113
|
+
}
|
2114
|
+
if (!_document.body) {
|
2115
|
+
utils.attachEvent('load', go);
|
2116
|
+
} else {
|
2117
|
+
go();
|
2118
|
+
}
|
2119
|
+
};
|
2120
|
+
InfoReceiverIframe.prototype = new EventEmitter(['finish']);
|
2121
|
+
|
2122
|
+
|
2123
|
+
var InfoReceiverFake = function () {
|
2124
|
+
// It may not be possible to do cross domain AJAX to get the info
|
2125
|
+
// data, for example for IE7. But we want to run JSONP, so let's
|
2126
|
+
// fake the response, with rtt=2s (rto=6s).
|
2127
|
+
var that = this;
|
2128
|
+
utils.delay(function () {
|
2129
|
+
that.emit('finish', {}, 2000);
|
2130
|
+
});
|
2131
|
+
};
|
2132
|
+
InfoReceiverFake.prototype = new EventEmitter(['finish']);
|
2133
|
+
|
2134
|
+
var createInfoReceiver = function (base_url) {
|
2135
|
+
if (utils.isSameOriginUrl(base_url)) {
|
2136
|
+
// If, for some reason, we have SockJS locally - there's no
|
2137
|
+
// need to start up the complex machinery. Just use ajax.
|
2138
|
+
return new InfoReceiver(base_url, utils.XHRLocalObject);
|
2139
|
+
}
|
2140
|
+
switch (utils.isXHRCorsCapable()) {
|
2141
|
+
case 1:
|
2142
|
+
// XHRLocalObject -> no_credentials=true
|
2143
|
+
return new InfoReceiver(base_url, utils.XHRLocalObject);
|
2144
|
+
case 2:
|
2145
|
+
return new InfoReceiver(base_url, utils.XDRObject);
|
2146
|
+
case 3:
|
2147
|
+
// Opera
|
2148
|
+
return new InfoReceiverIframe(base_url);
|
2149
|
+
default:
|
2150
|
+
// IE 7
|
2151
|
+
return new InfoReceiverFake();
|
2152
|
+
}
|
2153
|
+
;
|
2154
|
+
};
|
2155
|
+
|
2156
|
+
|
2157
|
+
var WInfoReceiverIframe = FacadeJS['w-iframe-info-receiver'] = function (ri, _trans_url, base_url) {
|
2158
|
+
var ir = new InfoReceiver(base_url, utils.XHRLocalObject);
|
2159
|
+
ir.onfinish = function (info, rtt) {
|
2160
|
+
ri._didMessage('m' + JSON.stringify([info, rtt]));
|
2161
|
+
ri._didClose();
|
2162
|
+
}
|
2163
|
+
};
|
2164
|
+
WInfoReceiverIframe.prototype.doCleanup = function () {
|
2165
|
+
};
|
2166
|
+
// [*] End of lib/info.js
|
2167
|
+
|
2168
|
+
|
2169
|
+
// [*] Including lib/trans-iframe-eventsource.js
|
2170
|
+
/*
|
2171
|
+
* ***** BEGIN LICENSE BLOCK *****
|
2172
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
2173
|
+
*
|
2174
|
+
* For the license see COPYING.
|
2175
|
+
* ***** END LICENSE BLOCK *****
|
2176
|
+
*/
|
2177
|
+
|
2178
|
+
var EventSourceIframeTransport = SockJS['iframe-eventsource'] = function () {
|
2179
|
+
var that = this;
|
2180
|
+
that.protocol = 'w-iframe-eventsource';
|
2181
|
+
that.i_constructor.apply(that, arguments);
|
2182
|
+
};
|
2183
|
+
|
2184
|
+
EventSourceIframeTransport.prototype = new IframeTransport();
|
2185
|
+
|
2186
|
+
EventSourceIframeTransport.enabled = function () {
|
2187
|
+
return ('EventSource' in _window) && IframeTransport.enabled();
|
2188
|
+
};
|
2189
|
+
|
2190
|
+
EventSourceIframeTransport.need_body = true;
|
2191
|
+
EventSourceIframeTransport.roundTrips = 3; // html, javascript, eventsource
|
2192
|
+
|
2193
|
+
|
2194
|
+
// w-iframe-eventsource
|
2195
|
+
var EventSourceTransport = FacadeJS['w-iframe-eventsource'] = function (ri, trans_url) {
|
2196
|
+
this.run(ri, trans_url, '/eventsource', EventSourceReceiver, utils.XHRLocalObject);
|
2197
|
+
}
|
2198
|
+
EventSourceTransport.prototype = new AjaxBasedTransport();
|
2199
|
+
// [*] End of lib/trans-iframe-eventsource.js
|
2200
|
+
|
2201
|
+
|
2202
|
+
// [*] Including lib/trans-iframe-xhr-polling.js
|
2203
|
+
/*
|
2204
|
+
* ***** BEGIN LICENSE BLOCK *****
|
2205
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
2206
|
+
*
|
2207
|
+
* For the license see COPYING.
|
2208
|
+
* ***** END LICENSE BLOCK *****
|
2209
|
+
*/
|
2210
|
+
|
2211
|
+
var XhrPollingIframeTransport = SockJS['iframe-xhr-polling'] = function () {
|
2212
|
+
var that = this;
|
2213
|
+
that.protocol = 'w-iframe-xhr-polling';
|
2214
|
+
that.i_constructor.apply(that, arguments);
|
2215
|
+
};
|
2216
|
+
|
2217
|
+
XhrPollingIframeTransport.prototype = new IframeTransport();
|
2218
|
+
|
2219
|
+
XhrPollingIframeTransport.enabled = function () {
|
2220
|
+
return _window.XMLHttpRequest && IframeTransport.enabled();
|
2221
|
+
};
|
2222
|
+
|
2223
|
+
XhrPollingIframeTransport.need_body = true;
|
2224
|
+
XhrPollingIframeTransport.roundTrips = 3; // html, javascript, xhr
|
2225
|
+
|
2226
|
+
|
2227
|
+
// w-iframe-xhr-polling
|
2228
|
+
var XhrPollingITransport = FacadeJS['w-iframe-xhr-polling'] = function (ri, trans_url) {
|
2229
|
+
this.run(ri, trans_url, '/xhr', XhrReceiver, utils.XHRLocalObject);
|
2230
|
+
};
|
2231
|
+
|
2232
|
+
XhrPollingITransport.prototype = new AjaxBasedTransport();
|
2233
|
+
// [*] End of lib/trans-iframe-xhr-polling.js
|
2234
|
+
|
2235
|
+
|
2236
|
+
// [*] Including lib/trans-iframe-htmlfile.js
|
2237
|
+
/*
|
2238
|
+
* ***** BEGIN LICENSE BLOCK *****
|
2239
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
2240
|
+
*
|
2241
|
+
* For the license see COPYING.
|
2242
|
+
* ***** END LICENSE BLOCK *****
|
2243
|
+
*/
|
2244
|
+
|
2245
|
+
// This transport generally works in any browser, but will cause a
|
2246
|
+
// spinning cursor to appear in any browser other than IE.
|
2247
|
+
// We may test this transport in all browsers - why not, but in
|
2248
|
+
// production it should be only run in IE.
|
2249
|
+
|
2250
|
+
var HtmlFileIframeTransport = SockJS['iframe-htmlfile'] = function () {
|
2251
|
+
var that = this;
|
2252
|
+
that.protocol = 'w-iframe-htmlfile';
|
2253
|
+
that.i_constructor.apply(that, arguments);
|
2254
|
+
};
|
2255
|
+
|
2256
|
+
// Inheritance.
|
2257
|
+
HtmlFileIframeTransport.prototype = new IframeTransport();
|
2258
|
+
|
2259
|
+
HtmlFileIframeTransport.enabled = function () {
|
2260
|
+
return IframeTransport.enabled();
|
2261
|
+
};
|
2262
|
+
|
2263
|
+
HtmlFileIframeTransport.need_body = true;
|
2264
|
+
HtmlFileIframeTransport.roundTrips = 3; // html, javascript, htmlfile
|
2265
|
+
|
2266
|
+
|
2267
|
+
// w-iframe-htmlfile
|
2268
|
+
var HtmlFileTransport = FacadeJS['w-iframe-htmlfile'] = function (ri, trans_url) {
|
2269
|
+
this.run(ri, trans_url, '/htmlfile', HtmlfileReceiver, utils.XHRLocalObject);
|
2270
|
+
};
|
2271
|
+
HtmlFileTransport.prototype = new AjaxBasedTransport();
|
2272
|
+
// [*] End of lib/trans-iframe-htmlfile.js
|
2273
|
+
|
2274
|
+
|
2275
|
+
// [*] Including lib/trans-polling.js
|
2276
|
+
/*
|
2277
|
+
* ***** BEGIN LICENSE BLOCK *****
|
2278
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
2279
|
+
*
|
2280
|
+
* For the license see COPYING.
|
2281
|
+
* ***** END LICENSE BLOCK *****
|
2282
|
+
*/
|
2283
|
+
|
2284
|
+
var Polling = function (ri, Receiver, recv_url, AjaxObject) {
|
2285
|
+
var that = this;
|
2286
|
+
that.ri = ri;
|
2287
|
+
that.Receiver = Receiver;
|
2288
|
+
that.recv_url = recv_url;
|
2289
|
+
that.AjaxObject = AjaxObject;
|
2290
|
+
that._scheduleRecv();
|
2291
|
+
};
|
2292
|
+
|
2293
|
+
Polling.prototype._scheduleRecv = function () {
|
2294
|
+
var that = this;
|
2295
|
+
var poll = that.poll = new that.Receiver(that.recv_url, that.AjaxObject);
|
2296
|
+
var msg_counter = 0;
|
2297
|
+
poll.onmessage = function (e) {
|
2298
|
+
msg_counter += 1;
|
2299
|
+
that.ri._didMessage(e.data);
|
2300
|
+
};
|
2301
|
+
poll.onclose = function (e) {
|
2302
|
+
that.poll = poll = poll.onmessage = poll.onclose = null;
|
2303
|
+
if (!that.poll_is_closing) {
|
2304
|
+
if (e.reason === 'permanent') {
|
2305
|
+
that.ri._didClose(1006, 'Polling error (' + e.reason + ')');
|
2306
|
+
} else {
|
2307
|
+
that._scheduleRecv();
|
2308
|
+
}
|
2309
|
+
}
|
2310
|
+
};
|
2311
|
+
};
|
2312
|
+
|
2313
|
+
Polling.prototype.abort = function () {
|
2314
|
+
var that = this;
|
2315
|
+
that.poll_is_closing = true;
|
2316
|
+
if (that.poll) {
|
2317
|
+
that.poll.abort();
|
2318
|
+
}
|
2319
|
+
};
|
2320
|
+
// [*] End of lib/trans-polling.js
|
2321
|
+
|
2322
|
+
|
2323
|
+
// [*] Including lib/trans-receiver-eventsource.js
|
2324
|
+
/*
|
2325
|
+
* ***** BEGIN LICENSE BLOCK *****
|
2326
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
2327
|
+
*
|
2328
|
+
* For the license see COPYING.
|
2329
|
+
* ***** END LICENSE BLOCK *****
|
2330
|
+
*/
|
2331
|
+
|
2332
|
+
var EventSourceReceiver = function (url) {
|
2333
|
+
var that = this;
|
2334
|
+
var es = new EventSource(url);
|
2335
|
+
es.onmessage = function (e) {
|
2336
|
+
that.dispatchEvent(new SimpleEvent('message',
|
2337
|
+
{'data': unescape(e.data)}));
|
2338
|
+
};
|
2339
|
+
that.es_close = es.onerror = function (e, abort_reason) {
|
2340
|
+
// ES on reconnection has readyState = 0 or 1.
|
2341
|
+
// on network error it's CLOSED = 2
|
2342
|
+
var reason = abort_reason ? 'user' :
|
2343
|
+
(es.readyState !== 2 ? 'network' : 'permanent');
|
2344
|
+
that.es_close = es.onmessage = es.onerror = null;
|
2345
|
+
// EventSource reconnects automatically.
|
2346
|
+
es.close();
|
2347
|
+
es = null;
|
2348
|
+
// Safari and chrome < 15 crash if we close window before
|
2349
|
+
// waiting for ES cleanup. See:
|
2350
|
+
// https://code.google.com/p/chromium/issues/detail?id=89155
|
2351
|
+
utils.delay(200, function () {
|
2352
|
+
that.dispatchEvent(new SimpleEvent('close', {reason: reason}));
|
2353
|
+
});
|
2354
|
+
};
|
2355
|
+
};
|
2356
|
+
|
2357
|
+
EventSourceReceiver.prototype = new REventTarget();
|
2358
|
+
|
2359
|
+
EventSourceReceiver.prototype.abort = function () {
|
2360
|
+
var that = this;
|
2361
|
+
if (that.es_close) {
|
2362
|
+
that.es_close({}, true);
|
2363
|
+
}
|
2364
|
+
};
|
2365
|
+
// [*] End of lib/trans-receiver-eventsource.js
|
2366
|
+
|
2367
|
+
|
2368
|
+
// [*] Including lib/trans-receiver-htmlfile.js
|
2369
|
+
/*
|
2370
|
+
* ***** BEGIN LICENSE BLOCK *****
|
2371
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
2372
|
+
*
|
2373
|
+
* For the license see COPYING.
|
2374
|
+
* ***** END LICENSE BLOCK *****
|
2375
|
+
*/
|
2376
|
+
|
2377
|
+
var _is_ie_htmlfile_capable;
|
2378
|
+
var isIeHtmlfileCapable = function () {
|
2379
|
+
if (_is_ie_htmlfile_capable === undefined) {
|
2380
|
+
if ('ActiveXObject' in _window) {
|
2381
|
+
try {
|
2382
|
+
_is_ie_htmlfile_capable = !!new ActiveXObject('htmlfile');
|
2383
|
+
} catch (x) {
|
2384
|
+
}
|
2385
|
+
} else {
|
2386
|
+
_is_ie_htmlfile_capable = false;
|
2387
|
+
}
|
2388
|
+
}
|
2389
|
+
return _is_ie_htmlfile_capable;
|
2390
|
+
};
|
2391
|
+
|
2392
|
+
|
2393
|
+
var HtmlfileReceiver = function (url) {
|
2394
|
+
var that = this;
|
2395
|
+
utils.polluteGlobalNamespace();
|
2396
|
+
|
2397
|
+
that.id = 'a' + utils.random_string(6, 26);
|
2398
|
+
url += ((url.indexOf('?') === -1) ? '?' : '&') +
|
2399
|
+
'c=' + escape(WPrefix + '.' + that.id);
|
2400
|
+
|
2401
|
+
var constructor = isIeHtmlfileCapable() ?
|
2402
|
+
utils.createHtmlfile : utils.createIframe;
|
2403
|
+
|
2404
|
+
var iframeObj;
|
2405
|
+
_window[WPrefix][that.id] = {
|
2406
|
+
start: function () {
|
2407
|
+
iframeObj.loaded();
|
2408
|
+
},
|
2409
|
+
message: function (data) {
|
2410
|
+
that.dispatchEvent(new SimpleEvent('message', {'data': data}));
|
2411
|
+
},
|
2412
|
+
stop: function () {
|
2413
|
+
that.iframe_close({}, 'network');
|
2414
|
+
}
|
2415
|
+
};
|
2416
|
+
that.iframe_close = function (e, abort_reason) {
|
2417
|
+
iframeObj.cleanup();
|
2418
|
+
that.iframe_close = iframeObj = null;
|
2419
|
+
delete _window[WPrefix][that.id];
|
2420
|
+
that.dispatchEvent(new SimpleEvent('close', {reason: abort_reason}));
|
2421
|
+
};
|
2422
|
+
iframeObj = constructor(url, function (e) {
|
2423
|
+
that.iframe_close({}, 'permanent');
|
2424
|
+
});
|
2425
|
+
};
|
2426
|
+
|
2427
|
+
HtmlfileReceiver.prototype = new REventTarget();
|
2428
|
+
|
2429
|
+
HtmlfileReceiver.prototype.abort = function () {
|
2430
|
+
var that = this;
|
2431
|
+
if (that.iframe_close) {
|
2432
|
+
that.iframe_close({}, 'user');
|
2433
|
+
}
|
2434
|
+
};
|
2435
|
+
// [*] End of lib/trans-receiver-htmlfile.js
|
2436
|
+
|
2437
|
+
|
2438
|
+
// [*] Including lib/trans-receiver-xhr.js
|
2439
|
+
/*
|
2440
|
+
* ***** BEGIN LICENSE BLOCK *****
|
2441
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
2442
|
+
*
|
2443
|
+
* For the license see COPYING.
|
2444
|
+
* ***** END LICENSE BLOCK *****
|
2445
|
+
*/
|
2446
|
+
|
2447
|
+
var XhrReceiver = function (url, AjaxObject) {
|
2448
|
+
var that = this;
|
2449
|
+
var buf_pos = 0;
|
2450
|
+
|
2451
|
+
that.xo = new AjaxObject('POST', url, null);
|
2452
|
+
that.xo.onchunk = function (status, text) {
|
2453
|
+
if (status !== 200) return;
|
2454
|
+
while (1) {
|
2455
|
+
var buf = text.slice(buf_pos);
|
2456
|
+
var p = buf.indexOf('\n');
|
2457
|
+
if (p === -1) break;
|
2458
|
+
buf_pos += p + 1;
|
2459
|
+
var msg = buf.slice(0, p);
|
2460
|
+
that.dispatchEvent(new SimpleEvent('message', {data: msg}));
|
2461
|
+
}
|
2462
|
+
};
|
2463
|
+
that.xo.onfinish = function (status, text) {
|
2464
|
+
that.xo.onchunk(status, text);
|
2465
|
+
that.xo = null;
|
2466
|
+
var reason = status === 200 ? 'network' : 'permanent';
|
2467
|
+
that.dispatchEvent(new SimpleEvent('close', {reason: reason}));
|
2468
|
+
}
|
2469
|
+
};
|
2470
|
+
|
2471
|
+
XhrReceiver.prototype = new REventTarget();
|
2472
|
+
|
2473
|
+
XhrReceiver.prototype.abort = function () {
|
2474
|
+
var that = this;
|
2475
|
+
if (that.xo) {
|
2476
|
+
that.xo.close();
|
2477
|
+
that.dispatchEvent(new SimpleEvent('close', {reason: 'user'}));
|
2478
|
+
that.xo = null;
|
2479
|
+
}
|
2480
|
+
};
|
2481
|
+
// [*] End of lib/trans-receiver-xhr.js
|
2482
|
+
|
2483
|
+
|
2484
|
+
// [*] Including lib/test-hooks.js
|
2485
|
+
/*
|
2486
|
+
* ***** BEGIN LICENSE BLOCK *****
|
2487
|
+
* Copyright (c) 2011-2012 VMware, Inc.
|
2488
|
+
*
|
2489
|
+
* For the license see COPYING.
|
2490
|
+
* ***** END LICENSE BLOCK *****
|
2491
|
+
*/
|
2492
|
+
|
2493
|
+
// For testing
|
2494
|
+
SockJS.getUtils = function () {
|
2495
|
+
return utils;
|
2496
|
+
};
|
2497
|
+
|
2498
|
+
SockJS.getIframeTransport = function () {
|
2499
|
+
return IframeTransport;
|
2500
|
+
};
|
2501
|
+
// [*] End of lib/test-hooks.js
|
2502
|
+
|
2503
|
+
return SockJS;
|
2504
|
+
})();
|
2505
|
+
if ('_sockjs_onload' in window) setTimeout(_sockjs_onload, 1);
|
2506
|
+
|
2507
|
+
// AMD compliance
|
2508
|
+
if (typeof define === 'function' && define.amd) {
|
2509
|
+
define('sockjs', [], function () {
|
2510
|
+
return SockJS;
|
2511
|
+
});
|
2512
|
+
}
|
2513
|
+
// [*] End of lib/index.js
|
2514
|
+
|
2515
|
+
// [*] End of lib/all.js
|
2516
|
+
|