ue-softphone-sdk 2.2.2 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/bye.d.ts +16 -0
- package/dist/api/dtmf.d.ts +15 -0
- package/dist/api/emitter.d.ts +88 -0
- package/dist/api/exceptions/content-type-unsupported.d.ts +8 -0
- package/dist/api/exceptions/index.d.ts +5 -0
- package/dist/api/exceptions/request-pending.d.ts +9 -0
- package/dist/api/exceptions/session-description-handler.d.ts +8 -0
- package/dist/api/exceptions/session-terminated.d.ts +8 -0
- package/dist/api/exceptions/state-transition.d.ts +8 -0
- package/dist/api/index.d.ts +58 -0
- package/dist/api/info.d.ts +16 -0
- package/dist/api/invitation-accept-options.d.ts +19 -0
- package/dist/api/invitation-progress-options.d.ts +38 -0
- package/dist/api/invitation-reject-options.d.ts +25 -0
- package/dist/api/invitation.d.ts +179 -0
- package/dist/api/inviter-cancel-options.d.ts +9 -0
- package/dist/api/inviter-invite-options.d.ts +28 -0
- package/dist/api/inviter-options.d.ts +43 -0
- package/dist/api/inviter.d.ts +236 -0
- package/dist/api/message.d.ts +16 -0
- package/dist/api/messager-message-options.d.ts +11 -0
- package/dist/api/messager-options.d.ts +17 -0
- package/dist/api/messager.d.ts +26 -0
- package/dist/api/notification.d.ts +16 -0
- package/dist/api/notifier.d.ts +8 -0
- package/dist/api/publisher-options.d.ts +33 -0
- package/dist/api/publisher-publish-options.d.ts +6 -0
- package/dist/api/publisher-state.d.ts +21 -0
- package/dist/api/publisher-unpublish-options.d.ts +6 -0
- package/dist/api/publisher.d.ts +65 -0
- package/dist/api/referral.d.ts +38 -0
- package/dist/api/registerer-options.d.ts +46 -0
- package/dist/api/registerer-register-options.d.ts +11 -0
- package/dist/api/registerer-state.d.ts +21 -0
- package/dist/api/registerer-unregister-options.d.ts +16 -0
- package/dist/api/registerer.d.ts +144 -0
- package/dist/api/session-bye-options.d.ts +11 -0
- package/dist/api/session-delegate.d.ts +73 -0
- package/dist/api/session-description-handler-factory.d.ts +15 -0
- package/dist/api/session-description-handler.d.ts +74 -0
- package/dist/api/session-info-options.d.ts +11 -0
- package/dist/api/session-invite-options.d.ts +28 -0
- package/dist/api/session-message-options.d.ts +11 -0
- package/dist/api/session-options.d.ts +8 -0
- package/dist/api/session-refer-options.d.ts +14 -0
- package/dist/api/session-state.d.ts +45 -0
- package/dist/api/session.d.ts +359 -0
- package/dist/api/subscriber-options.d.ts +11 -0
- package/dist/api/subscriber-subscribe-options.d.ts +6 -0
- package/dist/api/subscriber.d.ts +94 -0
- package/dist/api/subscription-delegate.d.ts +12 -0
- package/dist/api/subscription-options.d.ts +8 -0
- package/dist/api/subscription-state.d.ts +19 -0
- package/dist/api/subscription-subscribe-options.d.ts +6 -0
- package/dist/api/subscription-unsubscribe-options.d.ts +6 -0
- package/dist/api/subscription.d.ts +84 -0
- package/dist/api/transport-state.d.ts +37 -0
- package/dist/api/transport.d.ts +159 -0
- package/dist/api/user-agent-delegate.d.ts +84 -0
- package/dist/api/user-agent-options.d.ts +253 -0
- package/dist/api/user-agent-state.d.ts +14 -0
- package/dist/api/user-agent.d.ts +200 -0
- package/dist/core/dialogs/dialog-state.d.ts +34 -0
- package/dist/core/dialogs/dialog.d.ts +161 -0
- package/dist/core/dialogs/index.d.ts +4 -0
- package/dist/core/dialogs/session-dialog.d.ts +196 -0
- package/dist/core/dialogs/subscription-dialog.d.ts +120 -0
- package/dist/core/exceptions/exception.d.ts +8 -0
- package/dist/core/exceptions/index.d.ts +3 -0
- package/dist/core/exceptions/transaction-state-error.d.ts +8 -0
- package/dist/core/exceptions/transport-error.d.ts +8 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/log/index.d.ts +3 -0
- package/dist/core/log/levels.d.ts +10 -0
- package/dist/core/log/logger-factory.d.ts +21 -0
- package/dist/core/log/logger.d.ts +19 -0
- package/dist/core/messages/body.d.ts +64 -0
- package/dist/core/messages/digest-authentication.d.ts +51 -0
- package/dist/core/messages/incoming-message.d.ts +79 -0
- package/dist/core/messages/incoming-request-message.d.ts +10 -0
- package/dist/core/messages/incoming-request.d.ts +67 -0
- package/dist/core/messages/incoming-response-message.d.ts +10 -0
- package/dist/core/messages/incoming-response.d.ts +12 -0
- package/dist/core/messages/index.d.ts +13 -0
- package/dist/core/messages/md5.d.ts +32 -0
- package/dist/core/messages/methods/ack.d.ts +18 -0
- package/dist/core/messages/methods/bye.d.ts +21 -0
- package/dist/core/messages/methods/cancel.d.ts +21 -0
- package/dist/core/messages/methods/constants.d.ts +20 -0
- package/dist/core/messages/methods/index.d.ts +13 -0
- package/dist/core/messages/methods/info.d.ts +21 -0
- package/dist/core/messages/methods/invite.d.ts +86 -0
- package/dist/core/messages/methods/message.d.ts +21 -0
- package/dist/core/messages/methods/notify.d.ts +21 -0
- package/dist/core/messages/methods/prack.d.ts +21 -0
- package/dist/core/messages/methods/publish.d.ts +21 -0
- package/dist/core/messages/methods/refer.d.ts +21 -0
- package/dist/core/messages/methods/register.d.ts +21 -0
- package/dist/core/messages/methods/subscribe.d.ts +54 -0
- package/dist/core/messages/outgoing-request-message.d.ts +94 -0
- package/dist/core/messages/outgoing-request.d.ts +67 -0
- package/dist/core/messages/outgoing-response.d.ts +42 -0
- package/dist/core/messages/parser.d.ts +14 -0
- package/dist/core/messages/utils.d.ts +24 -0
- package/dist/core/session/index.d.ts +2 -0
- package/dist/core/session/session-delegate.d.ts +70 -0
- package/dist/core/session/session.d.ts +134 -0
- package/dist/core/subscription/index.d.ts +2 -0
- package/dist/core/subscription/subscription-delegate.d.ts +27 -0
- package/dist/core/subscription/subscription.d.ts +55 -0
- package/dist/core/timers.d.ts +20 -0
- package/dist/core/transactions/client-transaction.d.ts +45 -0
- package/dist/core/transactions/index.d.ts +10 -0
- package/dist/core/transactions/invite-client-transaction.d.ts +116 -0
- package/dist/core/transactions/invite-server-transaction.d.ts +127 -0
- package/dist/core/transactions/non-invite-client-transaction.d.ts +69 -0
- package/dist/core/transactions/non-invite-server-transaction.d.ts +57 -0
- package/dist/core/transactions/server-transaction.d.ts +35 -0
- package/dist/core/transactions/transaction-state.d.ts +13 -0
- package/dist/core/transactions/transaction-user.d.ts +72 -0
- package/dist/core/transactions/transaction.d.ts +79 -0
- package/dist/core/transport.d.ts +31 -0
- package/dist/core/user-agent-core/allowed-methods.d.ts +4 -0
- package/dist/core/user-agent-core/index.d.ts +3 -0
- package/dist/core/user-agent-core/user-agent-core-configuration.d.ts +99 -0
- package/dist/core/user-agent-core/user-agent-core-delegate.d.ts +37 -0
- package/dist/core/user-agent-core/user-agent-core.d.ts +179 -0
- package/dist/core/user-agents/bye-user-agent-client.d.ts +10 -0
- package/dist/core/user-agents/bye-user-agent-server.d.ts +10 -0
- package/dist/core/user-agents/cancel-user-agent-client.d.ts +10 -0
- package/dist/core/user-agents/index.d.ts +26 -0
- package/dist/core/user-agents/info-user-agent-client.d.ts +10 -0
- package/dist/core/user-agents/info-user-agent-server.d.ts +10 -0
- package/dist/core/user-agents/invite-user-agent-client.d.ts +35 -0
- package/dist/core/user-agents/invite-user-agent-server.d.ts +77 -0
- package/dist/core/user-agents/message-user-agent-client.d.ts +10 -0
- package/dist/core/user-agents/message-user-agent-server.d.ts +10 -0
- package/dist/core/user-agents/notify-user-agent-client.d.ts +10 -0
- package/dist/core/user-agents/notify-user-agent-server.d.ts +16 -0
- package/dist/core/user-agents/prack-user-agent-client.d.ts +10 -0
- package/dist/core/user-agents/prack-user-agent-server.d.ts +16 -0
- package/dist/core/user-agents/publish-user-agent-client.d.ts +10 -0
- package/dist/core/user-agents/re-invite-user-agent-client.d.ts +18 -0
- package/dist/core/user-agents/re-invite-user-agent-server.d.ts +41 -0
- package/dist/core/user-agents/re-subscribe-user-agent-client.d.ts +17 -0
- package/dist/core/user-agents/re-subscribe-user-agent-server.d.ts +10 -0
- package/dist/core/user-agents/refer-user-agent-client.d.ts +10 -0
- package/dist/core/user-agents/refer-user-agent-server.d.ts +16 -0
- package/dist/core/user-agents/register-user-agent-client.d.ts +10 -0
- package/dist/core/user-agents/register-user-agent-server.d.ts +11 -0
- package/dist/core/user-agents/subscribe-user-agent-client.d.ts +65 -0
- package/dist/core/user-agents/subscribe-user-agent-server.d.ts +11 -0
- package/dist/core/user-agents/user-agent-client.d.ts +103 -0
- package/dist/core/user-agents/user-agent-server.d.ts +79 -0
- package/dist/grammar/grammar.d.ts +26 -0
- package/dist/grammar/index.d.ts +4 -0
- package/dist/grammar/name-addr-header.d.ts +24 -0
- package/dist/grammar/parameters.d.ts +16 -0
- package/dist/grammar/pegjs/dist/grammar.d.ts +50 -0
- package/dist/grammar/uri.d.ts +62 -0
- package/dist/{types/index.d.ts → index.d.ts} +7 -3
- package/dist/main.d.ts +9 -0
- package/dist/new-index.d.ts +199 -0
- package/dist/platform/web/index.d.ts +4 -0
- package/dist/platform/web/modifiers/index.d.ts +5 -0
- package/dist/platform/web/modifiers/modifiers.d.ts +41 -0
- package/dist/platform/web/session-description-handler/index.d.ts +14 -0
- package/dist/platform/web/session-description-handler/media-stream-factory-default.d.ts +6 -0
- package/dist/platform/web/session-description-handler/media-stream-factory.d.ts +6 -0
- package/dist/platform/web/session-description-handler/peer-connection-configuration-default.d.ts +5 -0
- package/dist/platform/web/session-description-handler/peer-connection-delegate.d.ts +63 -0
- package/dist/platform/web/session-description-handler/session-description-handler-configuration.d.ts +16 -0
- package/dist/platform/web/session-description-handler/session-description-handler-factory-default.d.ts +11 -0
- package/dist/platform/web/session-description-handler/session-description-handler-factory-options.d.ts +9 -0
- package/dist/platform/web/session-description-handler/session-description-handler-factory.d.ts +16 -0
- package/dist/platform/web/session-description-handler/session-description-handler-options.d.ts +47 -0
- package/dist/platform/web/session-description-handler/session-description-handler.d.ts +212 -0
- package/dist/platform/web/simple-user/index.d.ts +7 -0
- package/dist/platform/web/simple-user/simple-user-delegate.d.ts +72 -0
- package/dist/platform/web/simple-user/simple-user-options.d.ts +90 -0
- package/dist/platform/web/simple-user/simple-user.d.ts +226 -0
- package/dist/platform/web/transport/index.d.ts +6 -0
- package/dist/platform/web/transport/transport-options.d.ts +30 -0
- package/dist/platform/web/transport/transport.d.ts +125 -0
- package/dist/ue-softphone-sdk.js +2 -1
- package/dist/ue-softphone-sdk.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/webPhoneSdk.d.ts +24 -0
- package/dist/webrtc.d.ts +17 -0
- package/{rollup-new.config.mjs → new-rollup.config.mjs} +1 -1
- package/package.json +6 -6
- package/rollup.config.js +15 -14
- package/src/api/api-extractor.json +358 -0
- package/src/api/bye.ts +27 -0
- package/src/api/dtmf.ts +27 -0
- package/src/api/emitter.ts +110 -0
- package/src/api/exceptions/content-type-unsupported.ts +11 -0
- package/src/api/exceptions/index.ts +5 -0
- package/src/api/exceptions/request-pending.ts +12 -0
- package/src/api/exceptions/session-description-handler.ts +11 -0
- package/src/api/exceptions/session-terminated.ts +11 -0
- package/src/api/exceptions/state-transition.ts +11 -0
- package/src/api/index.ts +58 -0
- package/src/api/info.ts +27 -0
- package/src/api/invitation-accept-options.ts +20 -0
- package/src/api/invitation-progress-options.ts +36 -0
- package/src/api/invitation-reject-options.ts +22 -0
- package/src/api/invitation.ts +816 -0
- package/src/api/inviter-cancel-options.ts +9 -0
- package/src/api/inviter-invite-options.ts +29 -0
- package/src/api/inviter-options.ts +44 -0
- package/src/api/inviter.ts +1126 -0
- package/src/api/message.ts +27 -0
- package/src/api/messager-message-options.ts +12 -0
- package/src/api/messager-options.ts +18 -0
- package/src/api/messager.ts +89 -0
- package/src/api/notification.ts +27 -0
- package/src/api/notifier.ts +7 -0
- package/src/api/publisher-options.ts +34 -0
- package/src/api/publisher-publish-options.ts +6 -0
- package/src/api/publisher-state.ts +21 -0
- package/src/api/publisher-unpublish-options.ts +6 -0
- package/src/api/publisher.ts +418 -0
- package/src/api/referral.ts +89 -0
- package/src/api/registerer-options.ts +55 -0
- package/src/api/registerer-register-options.ts +12 -0
- package/src/api/registerer-state.ts +21 -0
- package/src/api/registerer-unregister-options.ts +17 -0
- package/src/api/registerer.ts +814 -0
- package/src/api/session-bye-options.ts +12 -0
- package/src/api/session-delegate.ts +80 -0
- package/src/api/session-description-handler-factory.ts +16 -0
- package/src/api/session-description-handler.ts +89 -0
- package/src/api/session-info-options.ts +12 -0
- package/src/api/session-invite-options.ts +29 -0
- package/src/api/session-message-options.ts +12 -0
- package/src/api/session-options.ts +8 -0
- package/src/api/session-refer-options.ts +15 -0
- package/src/api/session-state.ts +45 -0
- package/src/api/session.ts +1448 -0
- package/src/api/subscriber-options.ts +12 -0
- package/src/api/subscriber-subscribe-options.ts +6 -0
- package/src/api/subscriber.ts +536 -0
- package/src/api/subscription-delegate.ts +13 -0
- package/src/api/subscription-options.ts +8 -0
- package/src/api/subscription-state.ts +19 -0
- package/src/api/subscription-subscribe-options.ts +6 -0
- package/src/api/subscription-unsubscribe-options.ts +6 -0
- package/src/api/subscription.ts +161 -0
- package/src/api/transport-state.ts +37 -0
- package/src/api/transport.ts +169 -0
- package/src/api/user-agent-delegate.ts +95 -0
- package/src/api/user-agent-options.ts +322 -0
- package/src/api/user-agent-state.ts +14 -0
- package/src/api/user-agent.ts +1014 -0
- package/src/core/api-extractor.json +358 -0
- package/src/core/dialogs/dialog-state.ts +35 -0
- package/src/core/dialogs/dialog.ts +605 -0
- package/src/core/dialogs/index.ts +4 -0
- package/src/core/dialogs/session-dialog.ts +996 -0
- package/src/core/dialogs/subscription-dialog.ts +557 -0
- package/src/core/exceptions/exception.ts +11 -0
- package/src/core/exceptions/index.ts +3 -0
- package/src/core/exceptions/transaction-state-error.ts +11 -0
- package/src/core/exceptions/transport-error.ts +11 -0
- package/src/core/index.ts +19 -0
- package/src/core/log/index.ts +3 -0
- package/src/core/log/levels.ts +10 -0
- package/src/core/log/logger-factory.ts +119 -0
- package/src/core/log/logger.ts +42 -0
- package/src/core/messages/body.ts +171 -0
- package/src/core/messages/digest-authentication.ts +190 -0
- package/src/core/messages/incoming-message.ts +152 -0
- package/src/core/messages/incoming-request-message.ts +14 -0
- package/src/core/messages/incoming-request.ts +75 -0
- package/src/core/messages/incoming-response-message.ts +14 -0
- package/src/core/messages/incoming-response.ts +13 -0
- package/src/core/messages/index.ts +18 -0
- package/src/core/messages/md5.ts +437 -0
- package/src/core/messages/methods/ack.ts +22 -0
- package/src/core/messages/methods/bye.ts +22 -0
- package/src/core/messages/methods/cancel.ts +22 -0
- package/src/core/messages/methods/constants.ts +21 -0
- package/src/core/messages/methods/index.ts +13 -0
- package/src/core/messages/methods/info.ts +22 -0
- package/src/core/messages/methods/invite.ts +104 -0
- package/src/core/messages/methods/message.ts +22 -0
- package/src/core/messages/methods/notify.ts +22 -0
- package/src/core/messages/methods/prack.ts +22 -0
- package/src/core/messages/methods/publish.ts +22 -0
- package/src/core/messages/methods/refer.ts +22 -0
- package/src/core/messages/methods/register.ts +22 -0
- package/src/core/messages/methods/subscribe.ts +59 -0
- package/src/core/messages/outgoing-request-message.ts +299 -0
- package/src/core/messages/outgoing-request.ts +77 -0
- package/src/core/messages/outgoing-response.ts +174 -0
- package/src/core/messages/parser.ts +265 -0
- package/src/core/messages/utils.ts +144 -0
- package/src/core/session/index.ts +2 -0
- package/src/core/session/session-delegate.ts +88 -0
- package/src/core/session/session.ts +158 -0
- package/src/core/subscription/index.ts +2 -0
- package/src/core/subscription/subscription-delegate.ts +30 -0
- package/src/core/subscription/subscription.ts +61 -0
- package/src/core/timers.ts +24 -0
- package/src/core/transactions/client-transaction.ts +78 -0
- package/src/core/transactions/index.ts +10 -0
- package/src/core/transactions/invite-client-transaction.ts +504 -0
- package/src/core/transactions/invite-server-transaction.ts +432 -0
- package/src/core/transactions/non-invite-client-transaction.ts +257 -0
- package/src/core/transactions/non-invite-server-transaction.ts +241 -0
- package/src/core/transactions/server-transaction.ts +47 -0
- package/src/core/transactions/transaction-state.ts +13 -0
- package/src/core/transactions/transaction-user.ts +82 -0
- package/src/core/transactions/transaction.ts +149 -0
- package/src/core/transport.ts +32 -0
- package/src/core/user-agent-core/allowed-methods.ts +19 -0
- package/src/core/user-agent-core/index.ts +3 -0
- package/src/core/user-agent-core/user-agent-core-configuration.ts +111 -0
- package/src/core/user-agent-core/user-agent-core-delegate.ts +50 -0
- package/src/core/user-agent-core/user-agent-core.ts +905 -0
- package/src/core/user-agents/bye-user-agent-client.ts +16 -0
- package/src/core/user-agents/bye-user-agent-server.ts +14 -0
- package/src/core/user-agents/cancel-user-agent-client.ts +14 -0
- package/src/core/user-agents/index.ts +26 -0
- package/src/core/user-agents/info-user-agent-client.ts +15 -0
- package/src/core/user-agents/info-user-agent-server.ts +14 -0
- package/src/core/user-agents/invite-user-agent-client.ts +405 -0
- package/src/core/user-agents/invite-user-agent-server.ts +269 -0
- package/src/core/user-agents/message-user-agent-client.ts +14 -0
- package/src/core/user-agents/message-user-agent-server.ts +14 -0
- package/src/core/user-agents/notify-user-agent-client.ts +15 -0
- package/src/core/user-agents/notify-user-agent-server.ts +30 -0
- package/src/core/user-agents/prack-user-agent-client.ts +16 -0
- package/src/core/user-agents/prack-user-agent-server.ts +37 -0
- package/src/core/user-agents/publish-user-agent-client.ts +14 -0
- package/src/core/user-agents/re-invite-user-agent-client.ts +127 -0
- package/src/core/user-agents/re-invite-user-agent-server.ts +109 -0
- package/src/core/user-agents/re-subscribe-user-agent-client.ts +78 -0
- package/src/core/user-agents/re-subscribe-user-agent-server.ts +14 -0
- package/src/core/user-agents/refer-user-agent-client.ts +15 -0
- package/src/core/user-agents/refer-user-agent-server.ts +30 -0
- package/src/core/user-agents/register-user-agent-client.ts +14 -0
- package/src/core/user-agents/register-user-agent-server.ts +14 -0
- package/src/core/user-agents/subscribe-user-agent-client.ts +341 -0
- package/src/core/user-agents/subscribe-user-agent-server.ts +14 -0
- package/src/core/user-agents/user-agent-client.ts +378 -0
- package/src/core/user-agents/user-agent-server.ts +276 -0
- package/src/grammar/grammar.ts +55 -0
- package/src/grammar/index.ts +4 -0
- package/src/grammar/name-addr-header.ts +58 -0
- package/src/grammar/parameters.ts +45 -0
- package/src/grammar/pegjs/README.md +9 -0
- package/src/grammar/pegjs/dist/grammar.ts +1557 -0
- package/src/grammar/pegjs/src/grammar.pegjs +1009 -0
- package/src/grammar/uri.ts +370 -0
- package/src/index.ts +59 -28
- package/src/lib/socket.io.esm.min.js +7 -0
- package/src/main.ts +26 -0
- package/src/new-index.ts +2478 -0
- package/src/platform/react/README.md +1 -0
- package/src/platform/web/index.ts +4 -0
- package/src/platform/web/modifiers/index.ts +5 -0
- package/src/platform/web/modifiers/modifiers.ts +180 -0
- package/src/platform/web/session-description-handler/api-extractor.json +358 -0
- package/src/platform/web/session-description-handler/index.ts +14 -0
- package/src/platform/web/session-description-handler/media-stream-factory-default.ts +22 -0
- package/src/platform/web/session-description-handler/media-stream-factory.ts +10 -0
- package/src/platform/web/session-description-handler/peer-connection-configuration-default.ts +17 -0
- package/src/platform/web/session-description-handler/peer-connection-delegate.ts +72 -0
- package/src/platform/web/session-description-handler/session-description-handler-configuration.ts +17 -0
- package/src/platform/web/session-description-handler/session-description-handler-factory-default.ts +45 -0
- package/src/platform/web/session-description-handler/session-description-handler-factory-options.ts +10 -0
- package/src/platform/web/session-description-handler/session-description-handler-factory.ts +17 -0
- package/src/platform/web/session-description-handler/session-description-handler-options.ts +56 -0
- package/src/platform/web/session-description-handler/session-description-handler.ts +938 -0
- package/src/platform/web/simple-user/api-extractor.json +358 -0
- package/src/platform/web/simple-user/index.ts +7 -0
- package/src/platform/web/simple-user/simple-user-delegate.ts +82 -0
- package/src/platform/web/simple-user/simple-user-options.ts +102 -0
- package/src/platform/web/simple-user/simple-user.ts +1099 -0
- package/src/platform/web/transport/api-extractor.json +358 -0
- package/src/platform/web/transport/index.ts +6 -0
- package/src/platform/web/transport/transport-options.ts +34 -0
- package/src/platform/web/transport/transport.ts +742 -0
- package/src/version.ts +8 -0
- package/src/webPhoneSdk.ts +67 -0
- package/src/webrtc.ts +318 -0
- package/tsconfig.json +26 -10
- /package/dist/{types/config.d.ts → config.d.ts} +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SubscriptionOptions } from "./subscription-options";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link Subscriber} constructor.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface SubscriberOptions extends SubscriptionOptions {
|
|
8
|
+
expires?: number;
|
|
9
|
+
extraHeaders?: Array<string>;
|
|
10
|
+
body?: string;
|
|
11
|
+
contentType?: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
import {
|
|
2
|
+
C,
|
|
3
|
+
fromBodyLegacy,
|
|
4
|
+
IncomingNotifyRequest,
|
|
5
|
+
IncomingRequestWithSubscription,
|
|
6
|
+
IncomingResponse,
|
|
7
|
+
Logger,
|
|
8
|
+
OutgoingRequestMessage,
|
|
9
|
+
OutgoingSubscribeRequest,
|
|
10
|
+
RequestOptions,
|
|
11
|
+
Subscription as SubscriptionDialog,
|
|
12
|
+
SubscriptionState as SubscriptionDialogState,
|
|
13
|
+
URI,
|
|
14
|
+
UserAgentCore
|
|
15
|
+
} from "../core";
|
|
16
|
+
import { AllowedMethods } from "../core/user-agent-core/allowed-methods";
|
|
17
|
+
import { Notification } from "./notification";
|
|
18
|
+
import { BodyAndContentType } from "./session-description-handler";
|
|
19
|
+
import { SubscriberOptions } from "./subscriber-options";
|
|
20
|
+
import { SubscriberSubscribeOptions } from "./subscriber-subscribe-options";
|
|
21
|
+
import { Subscription } from "./subscription";
|
|
22
|
+
import { SubscriptionState } from "./subscription-state";
|
|
23
|
+
import { SubscriptionUnsubscribeOptions } from "./subscription-unsubscribe-options";
|
|
24
|
+
import { UserAgent } from "./user-agent";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A subscriber establishes a {@link Subscription} (outgoing SUBSCRIBE).
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* This is (more or less) an implementation of a "subscriber" as
|
|
31
|
+
* defined in RFC 6665 "SIP-Specific Event Notifications".
|
|
32
|
+
* https://tools.ietf.org/html/rfc6665
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* // Create a new subscriber.
|
|
37
|
+
* const targetURI = new URI("sip", "alice", "example.com");
|
|
38
|
+
* const eventType = "example-name"; // https://www.iana.org/assignments/sip-events/sip-events.xhtml
|
|
39
|
+
* const subscriber = new Subscriber(userAgent, targetURI, eventType);
|
|
40
|
+
*
|
|
41
|
+
* // Add delegate to handle event notifications.
|
|
42
|
+
* subscriber.delegate = {
|
|
43
|
+
* onNotify: (notification: Notification) => {
|
|
44
|
+
* // handle notification here
|
|
45
|
+
* }
|
|
46
|
+
* };
|
|
47
|
+
*
|
|
48
|
+
* // Monitor subscription state changes.
|
|
49
|
+
* subscriber.stateChange.addListener((newState: SubscriptionState) => {
|
|
50
|
+
* if (newState === SubscriptionState.Terminated) {
|
|
51
|
+
* // handle state change here
|
|
52
|
+
* }
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* // Attempt to establish the subscription
|
|
56
|
+
* subscriber.subscribe();
|
|
57
|
+
*
|
|
58
|
+
* // Sometime later when done with subscription
|
|
59
|
+
* subscriber.unsubscribe();
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export class Subscriber extends Subscription {
|
|
65
|
+
// TODO: Cleanup these internals
|
|
66
|
+
private id: string;
|
|
67
|
+
private body: BodyAndContentType | undefined = undefined;
|
|
68
|
+
private event: string;
|
|
69
|
+
private expires: number;
|
|
70
|
+
private extraHeaders: Array<string>;
|
|
71
|
+
private logger: Logger;
|
|
72
|
+
private outgoingRequestMessage: OutgoingRequestMessage;
|
|
73
|
+
private retryAfterTimer: number | undefined;
|
|
74
|
+
private subscriberRequest: SubscriberRequest;
|
|
75
|
+
private targetURI: URI;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Constructor.
|
|
79
|
+
* @param userAgent - User agent. See {@link UserAgent} for details.
|
|
80
|
+
* @param targetURI - The request URI identifying the subscribed event.
|
|
81
|
+
* @param eventType - The event type identifying the subscribed event.
|
|
82
|
+
* @param options - Options bucket. See {@link SubscriberOptions} for details.
|
|
83
|
+
*/
|
|
84
|
+
public constructor(userAgent: UserAgent, targetURI: URI, eventType: string, options: SubscriberOptions = {}) {
|
|
85
|
+
super(userAgent, options);
|
|
86
|
+
|
|
87
|
+
this.logger = userAgent.getLogger("sip.Subscriber");
|
|
88
|
+
if (options.body) {
|
|
89
|
+
this.body = {
|
|
90
|
+
body: options.body,
|
|
91
|
+
contentType: options.contentType ? options.contentType : "application/sdp"
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.targetURI = targetURI;
|
|
96
|
+
|
|
97
|
+
// Subscription event
|
|
98
|
+
this.event = eventType;
|
|
99
|
+
|
|
100
|
+
// Subscription expires
|
|
101
|
+
if (options.expires === undefined) {
|
|
102
|
+
this.expires = 3600;
|
|
103
|
+
} else if (typeof options.expires !== "number") {
|
|
104
|
+
// pre-typescript type guard
|
|
105
|
+
this.logger.warn(`Option "expires" must be a number. Using default of 3600.`);
|
|
106
|
+
this.expires = 3600;
|
|
107
|
+
} else {
|
|
108
|
+
this.expires = options.expires;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Subscription extra headers
|
|
112
|
+
this.extraHeaders = (options.extraHeaders || []).slice();
|
|
113
|
+
|
|
114
|
+
// Subscription context.
|
|
115
|
+
this.subscriberRequest = this.initSubscriberRequest();
|
|
116
|
+
|
|
117
|
+
this.outgoingRequestMessage = this.subscriberRequest.message;
|
|
118
|
+
|
|
119
|
+
// Add to UserAgent's collection
|
|
120
|
+
this.id = this.outgoingRequestMessage.callId + this.outgoingRequestMessage.from.parameters.tag + this.event;
|
|
121
|
+
this._userAgent._subscriptions[this.id] = this;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Destructor.
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
128
|
+
public dispose(): Promise<void> {
|
|
129
|
+
if (this.disposed) {
|
|
130
|
+
return Promise.resolve();
|
|
131
|
+
}
|
|
132
|
+
this.logger.log(`Subscription ${this.id} in state ${this.state} is being disposed`);
|
|
133
|
+
|
|
134
|
+
// Remove from the user agent's subscription collection
|
|
135
|
+
delete this._userAgent._subscriptions[this.id];
|
|
136
|
+
|
|
137
|
+
// Clear timers
|
|
138
|
+
if (this.retryAfterTimer) {
|
|
139
|
+
clearTimeout(this.retryAfterTimer);
|
|
140
|
+
this.retryAfterTimer = undefined;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Dispose subscriber request
|
|
144
|
+
this.subscriberRequest.dispose();
|
|
145
|
+
|
|
146
|
+
// Make sure to dispose of our parent, then unsubscribe the
|
|
147
|
+
// subscription dialog (if need be) and resolve when it has terminated.
|
|
148
|
+
return super.dispose().then(() => {
|
|
149
|
+
// If we have never subscribed there is nothing to wait on.
|
|
150
|
+
// If we are already transitioned to terminated there is no need to unsubscribe again.
|
|
151
|
+
if (this.state !== SubscriptionState.Subscribed) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (!this._dialog) {
|
|
155
|
+
throw new Error("Dialog undefined.");
|
|
156
|
+
}
|
|
157
|
+
if (
|
|
158
|
+
this._dialog.subscriptionState === SubscriptionDialogState.Pending ||
|
|
159
|
+
this._dialog.subscriptionState === SubscriptionDialogState.Active
|
|
160
|
+
) {
|
|
161
|
+
const dialog = this._dialog;
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
dialog.delegate = {
|
|
165
|
+
onTerminated: (): void => resolve()
|
|
166
|
+
};
|
|
167
|
+
dialog.unsubscribe();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Subscribe to event notifications.
|
|
175
|
+
*
|
|
176
|
+
* @remarks
|
|
177
|
+
* Send an initial SUBSCRIBE request if no subscription as been established.
|
|
178
|
+
* Sends a re-SUBSCRIBE request if the subscription is "active".
|
|
179
|
+
*/
|
|
180
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
181
|
+
public subscribe(options: SubscriberSubscribeOptions = {}): Promise<void> {
|
|
182
|
+
switch (this.subscriberRequest.state) {
|
|
183
|
+
case SubscriptionDialogState.Initial:
|
|
184
|
+
// we can end up here when retrying so only state transition if in SubscriptionState.Initial state
|
|
185
|
+
if (this.state === SubscriptionState.Initial) {
|
|
186
|
+
this.stateTransition(SubscriptionState.NotifyWait);
|
|
187
|
+
}
|
|
188
|
+
this.subscriberRequest.subscribe().then((result) => {
|
|
189
|
+
if (result.success) {
|
|
190
|
+
if (result.success.subscription) {
|
|
191
|
+
this._dialog = result.success.subscription;
|
|
192
|
+
this._dialog.delegate = {
|
|
193
|
+
onNotify: (request): void => this.onNotify(request),
|
|
194
|
+
onRefresh: (request): void => this.onRefresh(request),
|
|
195
|
+
onTerminated: (): void => {
|
|
196
|
+
// If a call to unsubscribe will state transition to SubscriptionState.Terminated,
|
|
197
|
+
// but we can end up here after that if the NOTIFY never arrives and timer N fires.
|
|
198
|
+
if (this.state !== SubscriptionState.Terminated) {
|
|
199
|
+
this.stateTransition(SubscriptionState.Terminated);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
this.onNotify(result.success.request);
|
|
205
|
+
} else if (result.failure) {
|
|
206
|
+
this.unsubscribe();
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
break;
|
|
210
|
+
case SubscriptionDialogState.NotifyWait:
|
|
211
|
+
break;
|
|
212
|
+
case SubscriptionDialogState.Pending:
|
|
213
|
+
break;
|
|
214
|
+
case SubscriptionDialogState.Active:
|
|
215
|
+
if (this._dialog) {
|
|
216
|
+
const request = this._dialog.refresh();
|
|
217
|
+
request.delegate = {
|
|
218
|
+
onAccept: (response): void => this.onAccepted(response),
|
|
219
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
220
|
+
onRedirect: (response): Promise<void> => this.unsubscribe(),
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
222
|
+
onReject: (response): Promise<void> => this.unsubscribe()
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
break;
|
|
226
|
+
case SubscriptionDialogState.Terminated:
|
|
227
|
+
break;
|
|
228
|
+
default:
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
return Promise.resolve();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* {@inheritDoc Subscription.unsubscribe}
|
|
236
|
+
*/
|
|
237
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
238
|
+
public unsubscribe(options: SubscriptionUnsubscribeOptions = {}): Promise<void> {
|
|
239
|
+
if (this.disposed) {
|
|
240
|
+
return Promise.resolve();
|
|
241
|
+
}
|
|
242
|
+
switch (this.subscriberRequest.state) {
|
|
243
|
+
case SubscriptionDialogState.Initial:
|
|
244
|
+
break;
|
|
245
|
+
case SubscriptionDialogState.NotifyWait:
|
|
246
|
+
break;
|
|
247
|
+
case SubscriptionDialogState.Pending:
|
|
248
|
+
if (this._dialog) {
|
|
249
|
+
this._dialog.unsubscribe();
|
|
250
|
+
// responses intentionally ignored
|
|
251
|
+
}
|
|
252
|
+
break;
|
|
253
|
+
case SubscriptionDialogState.Active:
|
|
254
|
+
if (this._dialog) {
|
|
255
|
+
this._dialog.unsubscribe();
|
|
256
|
+
// responses intentionally ignored
|
|
257
|
+
}
|
|
258
|
+
break;
|
|
259
|
+
case SubscriptionDialogState.Terminated:
|
|
260
|
+
break;
|
|
261
|
+
default:
|
|
262
|
+
throw new Error("Unknown state.");
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
this.stateTransition(SubscriptionState.Terminated);
|
|
266
|
+
return Promise.resolve();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Sends a re-SUBSCRIBE request if the subscription is "active".
|
|
271
|
+
* @deprecated Use `subscribe` instead.
|
|
272
|
+
* @internal
|
|
273
|
+
*/
|
|
274
|
+
public _refresh(): Promise<void> {
|
|
275
|
+
if (this.subscriberRequest.state === SubscriptionDialogState.Active) {
|
|
276
|
+
return this.subscribe();
|
|
277
|
+
}
|
|
278
|
+
return Promise.resolve();
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** @internal */
|
|
282
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
283
|
+
protected onAccepted(response: IncomingResponse): void {
|
|
284
|
+
// NOTE: If you think you should do something with this response,
|
|
285
|
+
// please make sure you understand what it is you are doing and why.
|
|
286
|
+
// Per the RFC, the first NOTIFY is all that actually matters.
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** @internal */
|
|
290
|
+
protected onNotify(request: IncomingNotifyRequest): void {
|
|
291
|
+
// If we've set state to done, no further processing should take place
|
|
292
|
+
// and we are only interested in cleaning up after the appropriate NOTIFY.
|
|
293
|
+
if (this.disposed) {
|
|
294
|
+
request.accept();
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// State transition if needed.
|
|
299
|
+
if (this.state !== SubscriptionState.Subscribed) {
|
|
300
|
+
this.stateTransition(SubscriptionState.Subscribed);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Delegate notification.
|
|
304
|
+
if (this.delegate && this.delegate.onNotify) {
|
|
305
|
+
const notification = new Notification(request);
|
|
306
|
+
this.delegate.onNotify(notification);
|
|
307
|
+
} else {
|
|
308
|
+
request.accept();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// If the "Subscription-State" value is SubscriptionState.Terminated, the subscriber
|
|
312
|
+
// MUST consider the subscription terminated. The "expires" parameter
|
|
313
|
+
// has no semantics for SubscriptionState.Terminated -- notifiers SHOULD NOT include an
|
|
314
|
+
// "expires" parameter on a "Subscription-State" header field with a
|
|
315
|
+
// value of SubscriptionState.Terminated, and subscribers MUST ignore any such
|
|
316
|
+
// parameter, if present. If a reason code is present, the client
|
|
317
|
+
// should behave as described below. If no reason code or an unknown
|
|
318
|
+
// reason code is present, the client MAY attempt to re-subscribe at any
|
|
319
|
+
// time (unless a "retry-after" parameter is present, in which case the
|
|
320
|
+
// client SHOULD NOT attempt re-subscription until after the number of
|
|
321
|
+
// seconds specified by the "retry-after" parameter). The reason codes
|
|
322
|
+
// defined by this document are:
|
|
323
|
+
// https://tools.ietf.org/html/rfc6665#section-4.1.3
|
|
324
|
+
const subscriptionState = request.message.parseHeader("Subscription-State");
|
|
325
|
+
if (subscriptionState && subscriptionState.state) {
|
|
326
|
+
switch (subscriptionState.state) {
|
|
327
|
+
case "terminated":
|
|
328
|
+
if (subscriptionState.reason) {
|
|
329
|
+
this.logger.log(`Terminated subscription with reason ${subscriptionState.reason}`);
|
|
330
|
+
switch (subscriptionState.reason) {
|
|
331
|
+
case "deactivated":
|
|
332
|
+
case "timeout":
|
|
333
|
+
this.initSubscriberRequest();
|
|
334
|
+
this.subscribe();
|
|
335
|
+
return;
|
|
336
|
+
case "probation":
|
|
337
|
+
case "giveup":
|
|
338
|
+
this.initSubscriberRequest();
|
|
339
|
+
if (subscriptionState.params && subscriptionState.params["retry-after"]) {
|
|
340
|
+
this.retryAfterTimer = window.setTimeout(() => {
|
|
341
|
+
this.subscribe();
|
|
342
|
+
}, subscriptionState.params["retry-after"]);
|
|
343
|
+
} else {
|
|
344
|
+
this.subscribe();
|
|
345
|
+
}
|
|
346
|
+
return;
|
|
347
|
+
case "rejected":
|
|
348
|
+
case "noresource":
|
|
349
|
+
case "invariant":
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
this.unsubscribe();
|
|
354
|
+
break;
|
|
355
|
+
default:
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** @internal */
|
|
362
|
+
protected onRefresh(request: OutgoingSubscribeRequest): void {
|
|
363
|
+
request.delegate = {
|
|
364
|
+
onAccept: (response): void => this.onAccepted(response)
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
private initSubscriberRequest(): SubscriberRequest {
|
|
369
|
+
const options = {
|
|
370
|
+
extraHeaders: this.extraHeaders,
|
|
371
|
+
body: this.body ? fromBodyLegacy(this.body) : undefined
|
|
372
|
+
};
|
|
373
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
374
|
+
this.subscriberRequest = new SubscriberRequest(
|
|
375
|
+
this._userAgent.userAgentCore,
|
|
376
|
+
this.targetURI,
|
|
377
|
+
this.event,
|
|
378
|
+
this.expires,
|
|
379
|
+
options
|
|
380
|
+
);
|
|
381
|
+
this.subscriberRequest.delegate = {
|
|
382
|
+
onAccept: (response): void => this.onAccepted(response)
|
|
383
|
+
};
|
|
384
|
+
return this.subscriberRequest;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
interface SubscriberRequestDelegate {
|
|
389
|
+
/**
|
|
390
|
+
* This SUBSCRIBE request will be confirmed with a final response.
|
|
391
|
+
* 200-class responses indicate that the subscription has been accepted
|
|
392
|
+
* and that a NOTIFY request will be sent immediately.
|
|
393
|
+
* https://tools.ietf.org/html/rfc6665#section-4.1.2.1
|
|
394
|
+
*
|
|
395
|
+
* Called for initial SUBSCRIBE request only.
|
|
396
|
+
* @param response 200-class incoming response.
|
|
397
|
+
*/
|
|
398
|
+
onAccept?(response: IncomingResponse): void;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
interface SubscribeResult {
|
|
402
|
+
/** Exists if successfully established a subscription, otherwise undefined. */
|
|
403
|
+
success?: IncomingRequestWithSubscription;
|
|
404
|
+
/** Exists if failed to establish a subscription, otherwise undefined. */
|
|
405
|
+
failure?: {
|
|
406
|
+
/**
|
|
407
|
+
* The negative final response to the SUBSCRIBE, if one was received.
|
|
408
|
+
* Otherwise a timeout occurred waiting for the initial NOTIFY.
|
|
409
|
+
*/
|
|
410
|
+
response?: IncomingResponse;
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
class SubscriberRequest {
|
|
415
|
+
public delegate: SubscriberRequestDelegate | undefined;
|
|
416
|
+
public message: OutgoingRequestMessage;
|
|
417
|
+
|
|
418
|
+
private logger: Logger;
|
|
419
|
+
private request: OutgoingSubscribeRequest | undefined;
|
|
420
|
+
private subscription: SubscriptionDialog | undefined;
|
|
421
|
+
|
|
422
|
+
private subscribed = false;
|
|
423
|
+
|
|
424
|
+
public constructor(
|
|
425
|
+
private core: UserAgentCore,
|
|
426
|
+
private target: URI,
|
|
427
|
+
private event: string,
|
|
428
|
+
private expires: number,
|
|
429
|
+
options: RequestOptions,
|
|
430
|
+
delegate?: SubscriberRequestDelegate
|
|
431
|
+
) {
|
|
432
|
+
this.logger = core.loggerFactory.getLogger("sip.Subscriber");
|
|
433
|
+
this.delegate = delegate;
|
|
434
|
+
|
|
435
|
+
const allowHeader = "Allow: " + AllowedMethods.toString();
|
|
436
|
+
const extraHeaders = ((options && options.extraHeaders) || []).slice();
|
|
437
|
+
extraHeaders.push(allowHeader);
|
|
438
|
+
extraHeaders.push("Event: " + this.event);
|
|
439
|
+
extraHeaders.push("Expires: " + this.expires);
|
|
440
|
+
extraHeaders.push("Contact: " + this.core.configuration.contact.toString());
|
|
441
|
+
|
|
442
|
+
const body = options && options.body;
|
|
443
|
+
|
|
444
|
+
this.message = core.makeOutgoingRequestMessage(
|
|
445
|
+
C.SUBSCRIBE,
|
|
446
|
+
this.target,
|
|
447
|
+
this.core.configuration.aor,
|
|
448
|
+
this.target,
|
|
449
|
+
{},
|
|
450
|
+
extraHeaders,
|
|
451
|
+
body
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** Destructor. */
|
|
456
|
+
public dispose(): void {
|
|
457
|
+
if (this.request) {
|
|
458
|
+
this.request.waitNotifyStop();
|
|
459
|
+
this.request.dispose();
|
|
460
|
+
this.request = undefined;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** Subscription state. */
|
|
465
|
+
public get state(): SubscriptionDialogState {
|
|
466
|
+
if (this.subscription) {
|
|
467
|
+
return this.subscription.subscriptionState;
|
|
468
|
+
} else if (this.subscribed) {
|
|
469
|
+
return SubscriptionDialogState.NotifyWait;
|
|
470
|
+
} else {
|
|
471
|
+
return SubscriptionDialogState.Initial;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Establish subscription.
|
|
477
|
+
* @param options Options bucket.
|
|
478
|
+
*/
|
|
479
|
+
public subscribe(): Promise<SubscribeResult> {
|
|
480
|
+
if (this.subscribed) {
|
|
481
|
+
return Promise.reject(new Error("Not in initial state. Did you call subscribe more than once?"));
|
|
482
|
+
}
|
|
483
|
+
this.subscribed = true;
|
|
484
|
+
|
|
485
|
+
return new Promise((resolve) => {
|
|
486
|
+
if (!this.message) {
|
|
487
|
+
throw new Error("Message undefined.");
|
|
488
|
+
}
|
|
489
|
+
this.request = this.core.subscribe(this.message, {
|
|
490
|
+
// This SUBSCRIBE request will be confirmed with a final response.
|
|
491
|
+
// 200-class responses indicate that the subscription has been accepted
|
|
492
|
+
// and that a NOTIFY request will be sent immediately.
|
|
493
|
+
// https://tools.ietf.org/html/rfc6665#section-4.1.2.1
|
|
494
|
+
onAccept: (response) => {
|
|
495
|
+
if (this.delegate && this.delegate.onAccept) {
|
|
496
|
+
this.delegate.onAccept(response);
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
// Due to the potential for out-of-order messages, packet loss, and
|
|
500
|
+
// forking, the subscriber MUST be prepared to receive NOTIFY requests
|
|
501
|
+
// before the SUBSCRIBE transaction has completed.
|
|
502
|
+
// https://tools.ietf.org/html/rfc6665#section-4.1.2.4
|
|
503
|
+
onNotify: (requestWithSubscription): void => {
|
|
504
|
+
this.subscription = requestWithSubscription.subscription;
|
|
505
|
+
if (this.subscription) {
|
|
506
|
+
this.subscription.autoRefresh = true;
|
|
507
|
+
}
|
|
508
|
+
resolve({ success: requestWithSubscription });
|
|
509
|
+
},
|
|
510
|
+
// If this Timer N expires prior to the receipt of a NOTIFY request,
|
|
511
|
+
// the subscriber considers the subscription failed, and cleans up
|
|
512
|
+
// any state associated with the subscription attempt.
|
|
513
|
+
// https://tools.ietf.org/html/rfc6665#section-4.1.2.4
|
|
514
|
+
onNotifyTimeout: () => {
|
|
515
|
+
resolve({ failure: {} });
|
|
516
|
+
},
|
|
517
|
+
// This SUBSCRIBE request will be confirmed with a final response.
|
|
518
|
+
// Non-200-class final responses indicate that no subscription or new
|
|
519
|
+
// dialog usage has been created, and no subsequent NOTIFY request will
|
|
520
|
+
// be sent.
|
|
521
|
+
// https://tools.ietf.org/html/rfc6665#section-4.1.2.1
|
|
522
|
+
onRedirect: (response) => {
|
|
523
|
+
resolve({ failure: { response } });
|
|
524
|
+
},
|
|
525
|
+
// This SUBSCRIBE request will be confirmed with a final response.
|
|
526
|
+
// Non-200-class final responses indicate that no subscription or new
|
|
527
|
+
// dialog usage has been created, and no subsequent NOTIFY request will
|
|
528
|
+
// be sent.
|
|
529
|
+
// https://tools.ietf.org/html/rfc6665#section-4.1.2.1
|
|
530
|
+
onReject: (response) => {
|
|
531
|
+
resolve({ failure: { response } });
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Notification } from "./notification";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Delegate for {@link Subscription}.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface SubscriptionDelegate {
|
|
8
|
+
/**
|
|
9
|
+
* Called upon receiving an incoming NOTIFY request.
|
|
10
|
+
* @param notification - A notification. See {@link Notification} for details.
|
|
11
|
+
*/
|
|
12
|
+
onNotify(notification: Notification): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* {@link Subscription} state.
|
|
3
|
+
* @remarks
|
|
4
|
+
* The {@link Subscription} behaves in a deterministic manner according to the following
|
|
5
|
+
* Finite State Machine (FSM).
|
|
6
|
+
* ```txt
|
|
7
|
+
* _______________________________________
|
|
8
|
+
* Subscription | v
|
|
9
|
+
* Constructed -> Initial -> NotifyWait -> Subscribed -> Terminated
|
|
10
|
+
* |____________________________^
|
|
11
|
+
* ```
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export enum SubscriptionState {
|
|
15
|
+
Initial = "Initial",
|
|
16
|
+
NotifyWait = "NotifyWait",
|
|
17
|
+
Subscribed = "Subscribed",
|
|
18
|
+
Terminated = "Terminated"
|
|
19
|
+
}
|