ue-softphone-sdk 2.2.5 → 2.2.6
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/{index.d.ts → types/index.d.ts} +3 -7
- package/dist/ue-softphone-sdk.js +7 -2
- package/package.json +5 -6
- package/{new-rollup.config.mjs → rollup-new.config.mjs} +1 -1
- package/rollup.config.js +14 -15
- package/src/index.ts +28 -53
- package/tsconfig.json +10 -26
- package/dist/api/bye.d.ts +0 -16
- package/dist/api/dtmf.d.ts +0 -15
- package/dist/api/emitter.d.ts +0 -88
- package/dist/api/exceptions/content-type-unsupported.d.ts +0 -8
- package/dist/api/exceptions/index.d.ts +0 -5
- package/dist/api/exceptions/request-pending.d.ts +0 -9
- package/dist/api/exceptions/session-description-handler.d.ts +0 -8
- package/dist/api/exceptions/session-terminated.d.ts +0 -8
- package/dist/api/exceptions/state-transition.d.ts +0 -8
- package/dist/api/index.d.ts +0 -58
- package/dist/api/info.d.ts +0 -16
- package/dist/api/invitation-accept-options.d.ts +0 -19
- package/dist/api/invitation-progress-options.d.ts +0 -38
- package/dist/api/invitation-reject-options.d.ts +0 -25
- package/dist/api/invitation.d.ts +0 -179
- package/dist/api/inviter-cancel-options.d.ts +0 -9
- package/dist/api/inviter-invite-options.d.ts +0 -28
- package/dist/api/inviter-options.d.ts +0 -43
- package/dist/api/inviter.d.ts +0 -236
- package/dist/api/message.d.ts +0 -16
- package/dist/api/messager-message-options.d.ts +0 -11
- package/dist/api/messager-options.d.ts +0 -17
- package/dist/api/messager.d.ts +0 -26
- package/dist/api/notification.d.ts +0 -16
- package/dist/api/notifier.d.ts +0 -8
- package/dist/api/publisher-options.d.ts +0 -33
- package/dist/api/publisher-publish-options.d.ts +0 -6
- package/dist/api/publisher-state.d.ts +0 -21
- package/dist/api/publisher-unpublish-options.d.ts +0 -6
- package/dist/api/publisher.d.ts +0 -65
- package/dist/api/referral.d.ts +0 -38
- package/dist/api/registerer-options.d.ts +0 -46
- package/dist/api/registerer-register-options.d.ts +0 -11
- package/dist/api/registerer-state.d.ts +0 -21
- package/dist/api/registerer-unregister-options.d.ts +0 -16
- package/dist/api/registerer.d.ts +0 -144
- package/dist/api/session-bye-options.d.ts +0 -11
- package/dist/api/session-delegate.d.ts +0 -73
- package/dist/api/session-description-handler-factory.d.ts +0 -15
- package/dist/api/session-description-handler.d.ts +0 -74
- package/dist/api/session-info-options.d.ts +0 -11
- package/dist/api/session-invite-options.d.ts +0 -28
- package/dist/api/session-message-options.d.ts +0 -11
- package/dist/api/session-options.d.ts +0 -8
- package/dist/api/session-refer-options.d.ts +0 -14
- package/dist/api/session-state.d.ts +0 -45
- package/dist/api/session.d.ts +0 -359
- package/dist/api/subscriber-options.d.ts +0 -11
- package/dist/api/subscriber-subscribe-options.d.ts +0 -6
- package/dist/api/subscriber.d.ts +0 -94
- package/dist/api/subscription-delegate.d.ts +0 -12
- package/dist/api/subscription-options.d.ts +0 -8
- package/dist/api/subscription-state.d.ts +0 -19
- package/dist/api/subscription-subscribe-options.d.ts +0 -6
- package/dist/api/subscription-unsubscribe-options.d.ts +0 -6
- package/dist/api/subscription.d.ts +0 -84
- package/dist/api/transport-state.d.ts +0 -37
- package/dist/api/transport.d.ts +0 -159
- package/dist/api/user-agent-delegate.d.ts +0 -84
- package/dist/api/user-agent-options.d.ts +0 -253
- package/dist/api/user-agent-state.d.ts +0 -14
- package/dist/api/user-agent.d.ts +0 -200
- package/dist/core/dialogs/dialog-state.d.ts +0 -34
- package/dist/core/dialogs/dialog.d.ts +0 -161
- package/dist/core/dialogs/index.d.ts +0 -4
- package/dist/core/dialogs/session-dialog.d.ts +0 -196
- package/dist/core/dialogs/subscription-dialog.d.ts +0 -120
- package/dist/core/exceptions/exception.d.ts +0 -8
- package/dist/core/exceptions/index.d.ts +0 -3
- package/dist/core/exceptions/transaction-state-error.d.ts +0 -8
- package/dist/core/exceptions/transport-error.d.ts +0 -8
- package/dist/core/index.d.ts +0 -15
- package/dist/core/log/index.d.ts +0 -3
- package/dist/core/log/levels.d.ts +0 -10
- package/dist/core/log/logger-factory.d.ts +0 -21
- package/dist/core/log/logger.d.ts +0 -19
- package/dist/core/messages/body.d.ts +0 -64
- package/dist/core/messages/digest-authentication.d.ts +0 -51
- package/dist/core/messages/incoming-message.d.ts +0 -79
- package/dist/core/messages/incoming-request-message.d.ts +0 -10
- package/dist/core/messages/incoming-request.d.ts +0 -67
- package/dist/core/messages/incoming-response-message.d.ts +0 -10
- package/dist/core/messages/incoming-response.d.ts +0 -12
- package/dist/core/messages/index.d.ts +0 -13
- package/dist/core/messages/md5.d.ts +0 -32
- package/dist/core/messages/methods/ack.d.ts +0 -18
- package/dist/core/messages/methods/bye.d.ts +0 -21
- package/dist/core/messages/methods/cancel.d.ts +0 -21
- package/dist/core/messages/methods/constants.d.ts +0 -20
- package/dist/core/messages/methods/index.d.ts +0 -13
- package/dist/core/messages/methods/info.d.ts +0 -21
- package/dist/core/messages/methods/invite.d.ts +0 -86
- package/dist/core/messages/methods/message.d.ts +0 -21
- package/dist/core/messages/methods/notify.d.ts +0 -21
- package/dist/core/messages/methods/prack.d.ts +0 -21
- package/dist/core/messages/methods/publish.d.ts +0 -21
- package/dist/core/messages/methods/refer.d.ts +0 -21
- package/dist/core/messages/methods/register.d.ts +0 -21
- package/dist/core/messages/methods/subscribe.d.ts +0 -54
- package/dist/core/messages/outgoing-request-message.d.ts +0 -94
- package/dist/core/messages/outgoing-request.d.ts +0 -67
- package/dist/core/messages/outgoing-response.d.ts +0 -42
- package/dist/core/messages/parser.d.ts +0 -14
- package/dist/core/messages/utils.d.ts +0 -24
- package/dist/core/session/index.d.ts +0 -2
- package/dist/core/session/session-delegate.d.ts +0 -70
- package/dist/core/session/session.d.ts +0 -134
- package/dist/core/subscription/index.d.ts +0 -2
- package/dist/core/subscription/subscription-delegate.d.ts +0 -27
- package/dist/core/subscription/subscription.d.ts +0 -55
- package/dist/core/timers.d.ts +0 -20
- package/dist/core/transactions/client-transaction.d.ts +0 -45
- package/dist/core/transactions/index.d.ts +0 -10
- package/dist/core/transactions/invite-client-transaction.d.ts +0 -116
- package/dist/core/transactions/invite-server-transaction.d.ts +0 -127
- package/dist/core/transactions/non-invite-client-transaction.d.ts +0 -69
- package/dist/core/transactions/non-invite-server-transaction.d.ts +0 -57
- package/dist/core/transactions/server-transaction.d.ts +0 -35
- package/dist/core/transactions/transaction-state.d.ts +0 -13
- package/dist/core/transactions/transaction-user.d.ts +0 -72
- package/dist/core/transactions/transaction.d.ts +0 -79
- package/dist/core/transport.d.ts +0 -31
- package/dist/core/user-agent-core/allowed-methods.d.ts +0 -4
- package/dist/core/user-agent-core/index.d.ts +0 -3
- package/dist/core/user-agent-core/user-agent-core-configuration.d.ts +0 -99
- package/dist/core/user-agent-core/user-agent-core-delegate.d.ts +0 -37
- package/dist/core/user-agent-core/user-agent-core.d.ts +0 -179
- package/dist/core/user-agents/bye-user-agent-client.d.ts +0 -10
- package/dist/core/user-agents/bye-user-agent-server.d.ts +0 -10
- package/dist/core/user-agents/cancel-user-agent-client.d.ts +0 -10
- package/dist/core/user-agents/index.d.ts +0 -26
- package/dist/core/user-agents/info-user-agent-client.d.ts +0 -10
- package/dist/core/user-agents/info-user-agent-server.d.ts +0 -10
- package/dist/core/user-agents/invite-user-agent-client.d.ts +0 -35
- package/dist/core/user-agents/invite-user-agent-server.d.ts +0 -77
- package/dist/core/user-agents/message-user-agent-client.d.ts +0 -10
- package/dist/core/user-agents/message-user-agent-server.d.ts +0 -10
- package/dist/core/user-agents/notify-user-agent-client.d.ts +0 -10
- package/dist/core/user-agents/notify-user-agent-server.d.ts +0 -16
- package/dist/core/user-agents/prack-user-agent-client.d.ts +0 -10
- package/dist/core/user-agents/prack-user-agent-server.d.ts +0 -16
- package/dist/core/user-agents/publish-user-agent-client.d.ts +0 -10
- package/dist/core/user-agents/re-invite-user-agent-client.d.ts +0 -18
- package/dist/core/user-agents/re-invite-user-agent-server.d.ts +0 -41
- package/dist/core/user-agents/re-subscribe-user-agent-client.d.ts +0 -17
- package/dist/core/user-agents/re-subscribe-user-agent-server.d.ts +0 -10
- package/dist/core/user-agents/refer-user-agent-client.d.ts +0 -10
- package/dist/core/user-agents/refer-user-agent-server.d.ts +0 -16
- package/dist/core/user-agents/register-user-agent-client.d.ts +0 -10
- package/dist/core/user-agents/register-user-agent-server.d.ts +0 -11
- package/dist/core/user-agents/subscribe-user-agent-client.d.ts +0 -65
- package/dist/core/user-agents/subscribe-user-agent-server.d.ts +0 -11
- package/dist/core/user-agents/user-agent-client.d.ts +0 -103
- package/dist/core/user-agents/user-agent-server.d.ts +0 -79
- package/dist/grammar/grammar.d.ts +0 -26
- package/dist/grammar/index.d.ts +0 -4
- package/dist/grammar/name-addr-header.d.ts +0 -24
- package/dist/grammar/parameters.d.ts +0 -16
- package/dist/grammar/pegjs/dist/grammar.d.ts +0 -50
- package/dist/grammar/uri.d.ts +0 -62
- package/dist/main.d.ts +0 -9
- package/dist/new-index.d.ts +0 -199
- package/dist/platform/web/index.d.ts +0 -4
- package/dist/platform/web/modifiers/index.d.ts +0 -5
- package/dist/platform/web/modifiers/modifiers.d.ts +0 -41
- package/dist/platform/web/session-description-handler/index.d.ts +0 -14
- package/dist/platform/web/session-description-handler/media-stream-factory-default.d.ts +0 -6
- package/dist/platform/web/session-description-handler/media-stream-factory.d.ts +0 -6
- package/dist/platform/web/session-description-handler/peer-connection-configuration-default.d.ts +0 -5
- package/dist/platform/web/session-description-handler/peer-connection-delegate.d.ts +0 -63
- package/dist/platform/web/session-description-handler/session-description-handler-configuration.d.ts +0 -16
- package/dist/platform/web/session-description-handler/session-description-handler-factory-default.d.ts +0 -11
- package/dist/platform/web/session-description-handler/session-description-handler-factory-options.d.ts +0 -9
- package/dist/platform/web/session-description-handler/session-description-handler-factory.d.ts +0 -16
- package/dist/platform/web/session-description-handler/session-description-handler-options.d.ts +0 -47
- package/dist/platform/web/session-description-handler/session-description-handler.d.ts +0 -212
- package/dist/platform/web/simple-user/index.d.ts +0 -7
- package/dist/platform/web/simple-user/simple-user-delegate.d.ts +0 -72
- package/dist/platform/web/simple-user/simple-user-options.d.ts +0 -90
- package/dist/platform/web/simple-user/simple-user.d.ts +0 -226
- package/dist/platform/web/transport/index.d.ts +0 -6
- package/dist/platform/web/transport/transport-options.d.ts +0 -30
- package/dist/platform/web/transport/transport.d.ts +0 -125
- package/dist/ue-softphone-sdk.js.map +0 -1
- package/dist/version.d.ts +0 -1
- package/dist/webPhoneSdk.d.ts +0 -24
- package/dist/webrtc.d.ts +0 -17
- package/src/api/api-extractor.json +0 -358
- package/src/api/bye.ts +0 -27
- package/src/api/dtmf.ts +0 -27
- package/src/api/emitter.ts +0 -110
- package/src/api/exceptions/content-type-unsupported.ts +0 -11
- package/src/api/exceptions/index.ts +0 -5
- package/src/api/exceptions/request-pending.ts +0 -12
- package/src/api/exceptions/session-description-handler.ts +0 -11
- package/src/api/exceptions/session-terminated.ts +0 -11
- package/src/api/exceptions/state-transition.ts +0 -11
- package/src/api/index.ts +0 -58
- package/src/api/info.ts +0 -27
- package/src/api/invitation-accept-options.ts +0 -20
- package/src/api/invitation-progress-options.ts +0 -36
- package/src/api/invitation-reject-options.ts +0 -22
- package/src/api/invitation.ts +0 -816
- package/src/api/inviter-cancel-options.ts +0 -9
- package/src/api/inviter-invite-options.ts +0 -29
- package/src/api/inviter-options.ts +0 -44
- package/src/api/inviter.ts +0 -1126
- package/src/api/message.ts +0 -27
- package/src/api/messager-message-options.ts +0 -12
- package/src/api/messager-options.ts +0 -18
- package/src/api/messager.ts +0 -89
- package/src/api/notification.ts +0 -27
- package/src/api/notifier.ts +0 -7
- package/src/api/publisher-options.ts +0 -34
- package/src/api/publisher-publish-options.ts +0 -6
- package/src/api/publisher-state.ts +0 -21
- package/src/api/publisher-unpublish-options.ts +0 -6
- package/src/api/publisher.ts +0 -418
- package/src/api/referral.ts +0 -89
- package/src/api/registerer-options.ts +0 -55
- package/src/api/registerer-register-options.ts +0 -12
- package/src/api/registerer-state.ts +0 -21
- package/src/api/registerer-unregister-options.ts +0 -17
- package/src/api/registerer.ts +0 -814
- package/src/api/session-bye-options.ts +0 -12
- package/src/api/session-delegate.ts +0 -80
- package/src/api/session-description-handler-factory.ts +0 -16
- package/src/api/session-description-handler.ts +0 -89
- package/src/api/session-info-options.ts +0 -12
- package/src/api/session-invite-options.ts +0 -29
- package/src/api/session-message-options.ts +0 -12
- package/src/api/session-options.ts +0 -8
- package/src/api/session-refer-options.ts +0 -15
- package/src/api/session-state.ts +0 -45
- package/src/api/session.ts +0 -1448
- package/src/api/subscriber-options.ts +0 -12
- package/src/api/subscriber-subscribe-options.ts +0 -6
- package/src/api/subscriber.ts +0 -536
- package/src/api/subscription-delegate.ts +0 -13
- package/src/api/subscription-options.ts +0 -8
- package/src/api/subscription-state.ts +0 -19
- package/src/api/subscription-subscribe-options.ts +0 -6
- package/src/api/subscription-unsubscribe-options.ts +0 -6
- package/src/api/subscription.ts +0 -161
- package/src/api/transport-state.ts +0 -37
- package/src/api/transport.ts +0 -169
- package/src/api/user-agent-delegate.ts +0 -95
- package/src/api/user-agent-options.ts +0 -322
- package/src/api/user-agent-state.ts +0 -14
- package/src/api/user-agent.ts +0 -1014
- package/src/core/api-extractor.json +0 -358
- package/src/core/dialogs/dialog-state.ts +0 -35
- package/src/core/dialogs/dialog.ts +0 -605
- package/src/core/dialogs/index.ts +0 -4
- package/src/core/dialogs/session-dialog.ts +0 -996
- package/src/core/dialogs/subscription-dialog.ts +0 -557
- package/src/core/exceptions/exception.ts +0 -11
- package/src/core/exceptions/index.ts +0 -3
- package/src/core/exceptions/transaction-state-error.ts +0 -11
- package/src/core/exceptions/transport-error.ts +0 -11
- package/src/core/index.ts +0 -19
- package/src/core/log/index.ts +0 -3
- package/src/core/log/levels.ts +0 -10
- package/src/core/log/logger-factory.ts +0 -119
- package/src/core/log/logger.ts +0 -42
- package/src/core/messages/body.ts +0 -171
- package/src/core/messages/digest-authentication.ts +0 -190
- package/src/core/messages/incoming-message.ts +0 -152
- package/src/core/messages/incoming-request-message.ts +0 -14
- package/src/core/messages/incoming-request.ts +0 -75
- package/src/core/messages/incoming-response-message.ts +0 -14
- package/src/core/messages/incoming-response.ts +0 -13
- package/src/core/messages/index.ts +0 -18
- package/src/core/messages/md5.ts +0 -437
- package/src/core/messages/methods/ack.ts +0 -22
- package/src/core/messages/methods/bye.ts +0 -22
- package/src/core/messages/methods/cancel.ts +0 -22
- package/src/core/messages/methods/constants.ts +0 -21
- package/src/core/messages/methods/index.ts +0 -13
- package/src/core/messages/methods/info.ts +0 -22
- package/src/core/messages/methods/invite.ts +0 -104
- package/src/core/messages/methods/message.ts +0 -22
- package/src/core/messages/methods/notify.ts +0 -22
- package/src/core/messages/methods/prack.ts +0 -22
- package/src/core/messages/methods/publish.ts +0 -22
- package/src/core/messages/methods/refer.ts +0 -22
- package/src/core/messages/methods/register.ts +0 -22
- package/src/core/messages/methods/subscribe.ts +0 -59
- package/src/core/messages/outgoing-request-message.ts +0 -299
- package/src/core/messages/outgoing-request.ts +0 -77
- package/src/core/messages/outgoing-response.ts +0 -174
- package/src/core/messages/parser.ts +0 -265
- package/src/core/messages/utils.ts +0 -144
- package/src/core/session/index.ts +0 -2
- package/src/core/session/session-delegate.ts +0 -88
- package/src/core/session/session.ts +0 -158
- package/src/core/subscription/index.ts +0 -2
- package/src/core/subscription/subscription-delegate.ts +0 -30
- package/src/core/subscription/subscription.ts +0 -61
- package/src/core/timers.ts +0 -24
- package/src/core/transactions/client-transaction.ts +0 -78
- package/src/core/transactions/index.ts +0 -10
- package/src/core/transactions/invite-client-transaction.ts +0 -504
- package/src/core/transactions/invite-server-transaction.ts +0 -432
- package/src/core/transactions/non-invite-client-transaction.ts +0 -257
- package/src/core/transactions/non-invite-server-transaction.ts +0 -241
- package/src/core/transactions/server-transaction.ts +0 -47
- package/src/core/transactions/transaction-state.ts +0 -13
- package/src/core/transactions/transaction-user.ts +0 -82
- package/src/core/transactions/transaction.ts +0 -149
- package/src/core/transport.ts +0 -32
- package/src/core/user-agent-core/allowed-methods.ts +0 -19
- package/src/core/user-agent-core/index.ts +0 -3
- package/src/core/user-agent-core/user-agent-core-configuration.ts +0 -111
- package/src/core/user-agent-core/user-agent-core-delegate.ts +0 -50
- package/src/core/user-agent-core/user-agent-core.ts +0 -905
- package/src/core/user-agents/bye-user-agent-client.ts +0 -16
- package/src/core/user-agents/bye-user-agent-server.ts +0 -14
- package/src/core/user-agents/cancel-user-agent-client.ts +0 -14
- package/src/core/user-agents/index.ts +0 -26
- package/src/core/user-agents/info-user-agent-client.ts +0 -15
- package/src/core/user-agents/info-user-agent-server.ts +0 -14
- package/src/core/user-agents/invite-user-agent-client.ts +0 -405
- package/src/core/user-agents/invite-user-agent-server.ts +0 -269
- package/src/core/user-agents/message-user-agent-client.ts +0 -14
- package/src/core/user-agents/message-user-agent-server.ts +0 -14
- package/src/core/user-agents/notify-user-agent-client.ts +0 -15
- package/src/core/user-agents/notify-user-agent-server.ts +0 -30
- package/src/core/user-agents/prack-user-agent-client.ts +0 -16
- package/src/core/user-agents/prack-user-agent-server.ts +0 -37
- package/src/core/user-agents/publish-user-agent-client.ts +0 -14
- package/src/core/user-agents/re-invite-user-agent-client.ts +0 -127
- package/src/core/user-agents/re-invite-user-agent-server.ts +0 -109
- package/src/core/user-agents/re-subscribe-user-agent-client.ts +0 -78
- package/src/core/user-agents/re-subscribe-user-agent-server.ts +0 -14
- package/src/core/user-agents/refer-user-agent-client.ts +0 -15
- package/src/core/user-agents/refer-user-agent-server.ts +0 -30
- package/src/core/user-agents/register-user-agent-client.ts +0 -14
- package/src/core/user-agents/register-user-agent-server.ts +0 -14
- package/src/core/user-agents/subscribe-user-agent-client.ts +0 -341
- package/src/core/user-agents/subscribe-user-agent-server.ts +0 -14
- package/src/core/user-agents/user-agent-client.ts +0 -378
- package/src/core/user-agents/user-agent-server.ts +0 -276
- package/src/grammar/grammar.ts +0 -55
- package/src/grammar/index.ts +0 -4
- package/src/grammar/name-addr-header.ts +0 -58
- package/src/grammar/parameters.ts +0 -45
- package/src/grammar/pegjs/README.md +0 -9
- package/src/grammar/pegjs/dist/grammar.ts +0 -1557
- package/src/grammar/pegjs/src/grammar.pegjs +0 -1009
- package/src/grammar/uri.ts +0 -370
- package/src/main.ts +0 -26
- package/src/new-index.ts +0 -2486
- package/src/platform/react/README.md +0 -1
- package/src/platform/web/index.ts +0 -4
- package/src/platform/web/modifiers/index.ts +0 -5
- package/src/platform/web/modifiers/modifiers.ts +0 -180
- package/src/platform/web/session-description-handler/api-extractor.json +0 -358
- package/src/platform/web/session-description-handler/index.ts +0 -14
- package/src/platform/web/session-description-handler/media-stream-factory-default.ts +0 -22
- package/src/platform/web/session-description-handler/media-stream-factory.ts +0 -10
- package/src/platform/web/session-description-handler/peer-connection-configuration-default.ts +0 -17
- package/src/platform/web/session-description-handler/peer-connection-delegate.ts +0 -72
- package/src/platform/web/session-description-handler/session-description-handler-configuration.ts +0 -17
- package/src/platform/web/session-description-handler/session-description-handler-factory-default.ts +0 -45
- package/src/platform/web/session-description-handler/session-description-handler-factory-options.ts +0 -10
- package/src/platform/web/session-description-handler/session-description-handler-factory.ts +0 -17
- package/src/platform/web/session-description-handler/session-description-handler-options.ts +0 -56
- package/src/platform/web/session-description-handler/session-description-handler.ts +0 -938
- package/src/platform/web/simple-user/api-extractor.json +0 -358
- package/src/platform/web/simple-user/index.ts +0 -7
- package/src/platform/web/simple-user/simple-user-delegate.ts +0 -82
- package/src/platform/web/simple-user/simple-user-options.ts +0 -102
- package/src/platform/web/simple-user/simple-user.ts +0 -1099
- package/src/platform/web/transport/api-extractor.json +0 -358
- package/src/platform/web/transport/index.ts +0 -6
- package/src/platform/web/transport/transport-options.ts +0 -34
- package/src/platform/web/transport/transport.ts +0 -742
- package/src/version.ts +0 -8
- package/src/webPhoneSdk.ts +0 -67
- package/src/webrtc.ts +0 -318
- /package/dist/{config.d.ts → types/config.d.ts} +0 -0
package/src/api/user-agent.ts
DELETED
|
@@ -1,1014 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Contact,
|
|
3
|
-
DigestAuthentication,
|
|
4
|
-
Grammar,
|
|
5
|
-
IncomingInviteRequest,
|
|
6
|
-
IncomingMessageRequest,
|
|
7
|
-
IncomingNotifyRequest,
|
|
8
|
-
IncomingReferRequest,
|
|
9
|
-
IncomingRegisterRequest,
|
|
10
|
-
IncomingRequestMessage,
|
|
11
|
-
IncomingResponseMessage,
|
|
12
|
-
IncomingSubscribeRequest,
|
|
13
|
-
Levels,
|
|
14
|
-
Logger,
|
|
15
|
-
LoggerFactory,
|
|
16
|
-
Parser,
|
|
17
|
-
TransportError,
|
|
18
|
-
URI,
|
|
19
|
-
UserAgentCore,
|
|
20
|
-
UserAgentCoreConfiguration,
|
|
21
|
-
UserAgentCoreDelegate
|
|
22
|
-
} from "../core";
|
|
23
|
-
import { createRandomToken, utf8Length } from "../core/messages/utils";
|
|
24
|
-
import { defaultSessionDescriptionHandlerFactory } from "../platform/web/session-description-handler";
|
|
25
|
-
import { Transport as WebTransport } from "../platform/web/transport";
|
|
26
|
-
import { LIBRARY_VERSION } from "../version";
|
|
27
|
-
import { Emitter, EmitterImpl } from "./emitter";
|
|
28
|
-
import { Invitation } from "./invitation";
|
|
29
|
-
import { Inviter } from "./inviter";
|
|
30
|
-
import { InviterOptions } from "./inviter-options";
|
|
31
|
-
import { Message } from "./message";
|
|
32
|
-
import { Notification } from "./notification";
|
|
33
|
-
import { Publisher } from "./publisher";
|
|
34
|
-
import { Registerer } from "./registerer";
|
|
35
|
-
import { Session } from "./session";
|
|
36
|
-
import { Subscription } from "./subscription";
|
|
37
|
-
import { Transport } from "./transport";
|
|
38
|
-
import { UserAgentDelegate } from "./user-agent-delegate";
|
|
39
|
-
import { SIPExtension, UserAgentOptions, UserAgentRegisteredOptionTags } from "./user-agent-options";
|
|
40
|
-
import { UserAgentState } from "./user-agent-state";
|
|
41
|
-
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
-
declare const chrome: any;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* A user agent sends and receives requests using a `Transport`.
|
|
47
|
-
*
|
|
48
|
-
* @remarks
|
|
49
|
-
* A user agent (UA) is associated with a user via the user's SIP address of record (AOR)
|
|
50
|
-
* and acts on behalf of that user to send and receive SIP requests. The user agent can
|
|
51
|
-
* register to receive incoming requests, as well as create and send outbound messages.
|
|
52
|
-
* The user agent also maintains the Transport over which its signaling travels.
|
|
53
|
-
*
|
|
54
|
-
* @public
|
|
55
|
-
*/
|
|
56
|
-
export class UserAgent {
|
|
57
|
-
/**
|
|
58
|
-
* Property reserved for use by instance owner.
|
|
59
|
-
* @defaultValue `undefined`
|
|
60
|
-
*/
|
|
61
|
-
public data: unknown;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Delegate.
|
|
65
|
-
*/
|
|
66
|
-
public delegate: UserAgentDelegate | undefined;
|
|
67
|
-
|
|
68
|
-
/** @internal */
|
|
69
|
-
public _publishers: { [id: string]: Publisher } = {};
|
|
70
|
-
/** @internal */
|
|
71
|
-
public _registerers: { [id: string]: Registerer } = {};
|
|
72
|
-
/** @internal */
|
|
73
|
-
public _sessions: { [id: string]: Session } = {};
|
|
74
|
-
/** @internal */
|
|
75
|
-
public _subscriptions: { [id: string]: Subscription } = {};
|
|
76
|
-
|
|
77
|
-
private _contact: Contact;
|
|
78
|
-
private _state: UserAgentState = UserAgentState.Stopped;
|
|
79
|
-
private _stateEventEmitter: EmitterImpl<UserAgentState>;
|
|
80
|
-
private _transport: Transport;
|
|
81
|
-
private _userAgentCore: UserAgentCore;
|
|
82
|
-
|
|
83
|
-
/** Logger. */
|
|
84
|
-
private logger: Logger;
|
|
85
|
-
/** LoggerFactory. */
|
|
86
|
-
private loggerFactory: LoggerFactory;
|
|
87
|
-
/** Options. */
|
|
88
|
-
private options: Required<UserAgentOptions>;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Constructs a new instance of the `UserAgent` class.
|
|
92
|
-
* @param options - Options bucket. See {@link UserAgentOptions} for details.
|
|
93
|
-
*/
|
|
94
|
-
public constructor(options: Partial<UserAgentOptions> = {}) {
|
|
95
|
-
// state emitter
|
|
96
|
-
this._stateEventEmitter = new EmitterImpl<UserAgentState>();
|
|
97
|
-
|
|
98
|
-
// initialize delegate
|
|
99
|
-
this.delegate = options.delegate;
|
|
100
|
-
|
|
101
|
-
// initialize configuration
|
|
102
|
-
this.options = {
|
|
103
|
-
// start with the default option values
|
|
104
|
-
...UserAgent.defaultOptions(),
|
|
105
|
-
// add a unique sipjs id for each instance
|
|
106
|
-
...{ sipjsId: createRandomToken(5) },
|
|
107
|
-
// add a unique anonymous uri for each instance
|
|
108
|
-
...{ uri: new URI("sip", "anonymous." + createRandomToken(6), "anonymous.invalid") },
|
|
109
|
-
// add a unique via host for each instance
|
|
110
|
-
...{ viaHost: createRandomToken(12) + ".invalid" },
|
|
111
|
-
// apply any options passed in via the constructor
|
|
112
|
-
...UserAgent.stripUndefinedProperties(options)
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
// viaHost is hack
|
|
116
|
-
if (this.options.hackIpInContact) {
|
|
117
|
-
if (typeof this.options.hackIpInContact === "boolean" && this.options.hackIpInContact) {
|
|
118
|
-
const from = 1;
|
|
119
|
-
const to = 254;
|
|
120
|
-
const octet: number = Math.floor(Math.random() * (to - from + 1) + from);
|
|
121
|
-
// random Test-Net IP (http://tools.ietf.org/html/rfc5735)
|
|
122
|
-
this.options.viaHost = "192.0.2." + octet;
|
|
123
|
-
} else if (this.options.hackIpInContact) {
|
|
124
|
-
this.options.viaHost = this.options.hackIpInContact;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// initialize logger & logger factory
|
|
129
|
-
this.loggerFactory = new LoggerFactory();
|
|
130
|
-
this.logger = this.loggerFactory.getLogger("sip.UserAgent");
|
|
131
|
-
this.loggerFactory.builtinEnabled = this.options.logBuiltinEnabled;
|
|
132
|
-
this.loggerFactory.connector = this.options.logConnector as (
|
|
133
|
-
level: string,
|
|
134
|
-
category: string,
|
|
135
|
-
label: string | undefined,
|
|
136
|
-
content: string
|
|
137
|
-
) => void;
|
|
138
|
-
switch (this.options.logLevel) {
|
|
139
|
-
case "error":
|
|
140
|
-
this.loggerFactory.level = Levels.error;
|
|
141
|
-
break;
|
|
142
|
-
case "warn":
|
|
143
|
-
this.loggerFactory.level = Levels.warn;
|
|
144
|
-
break;
|
|
145
|
-
case "log":
|
|
146
|
-
this.loggerFactory.level = Levels.log;
|
|
147
|
-
break;
|
|
148
|
-
case "debug":
|
|
149
|
-
this.loggerFactory.level = Levels.debug;
|
|
150
|
-
break;
|
|
151
|
-
default:
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (this.options.logConfiguration) {
|
|
156
|
-
this.logger.log("Configuration:");
|
|
157
|
-
Object.keys(this.options).forEach((key) => {
|
|
158
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
159
|
-
const value = (this.options as any)[key];
|
|
160
|
-
switch (key) {
|
|
161
|
-
case "uri":
|
|
162
|
-
case "sessionDescriptionHandlerFactory":
|
|
163
|
-
this.logger.log("· " + key + ": " + value);
|
|
164
|
-
break;
|
|
165
|
-
case "authorizationPassword":
|
|
166
|
-
this.logger.log("· " + key + ": " + "NOT SHOWN");
|
|
167
|
-
break;
|
|
168
|
-
case "transportConstructor":
|
|
169
|
-
this.logger.log("· " + key + ": " + value.name);
|
|
170
|
-
break;
|
|
171
|
-
default:
|
|
172
|
-
this.logger.log("· " + key + ": " + JSON.stringify(value));
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// guard deprecated transport options (remove this in version 16.x)
|
|
178
|
-
if (this.options.transportOptions) {
|
|
179
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
180
|
-
const optionsDeprecated: any = this.options.transportOptions;
|
|
181
|
-
const maxReconnectionAttemptsDeprecated: number | undefined = optionsDeprecated.maxReconnectionAttempts;
|
|
182
|
-
const reconnectionTimeoutDeprecated: number | undefined = optionsDeprecated.reconnectionTimeout;
|
|
183
|
-
if (maxReconnectionAttemptsDeprecated !== undefined) {
|
|
184
|
-
const deprecatedMessage =
|
|
185
|
-
`The transport option "maxReconnectionAttempts" as has apparently been specified and has been deprecated. ` +
|
|
186
|
-
"It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.";
|
|
187
|
-
this.logger.warn(deprecatedMessage);
|
|
188
|
-
}
|
|
189
|
-
if (reconnectionTimeoutDeprecated !== undefined) {
|
|
190
|
-
const deprecatedMessage =
|
|
191
|
-
`The transport option "reconnectionTimeout" as has apparently been specified and has been deprecated. ` +
|
|
192
|
-
"It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.";
|
|
193
|
-
this.logger.warn(deprecatedMessage);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// hack
|
|
197
|
-
if (options.reconnectionDelay === undefined && reconnectionTimeoutDeprecated !== undefined) {
|
|
198
|
-
this.options.reconnectionDelay = reconnectionTimeoutDeprecated;
|
|
199
|
-
}
|
|
200
|
-
if (options.reconnectionAttempts === undefined && maxReconnectionAttemptsDeprecated !== undefined) {
|
|
201
|
-
this.options.reconnectionAttempts = maxReconnectionAttemptsDeprecated;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// guard deprecated user agent options (remove this in version 16.x)
|
|
206
|
-
if (options.reconnectionDelay !== undefined) {
|
|
207
|
-
const deprecatedMessage =
|
|
208
|
-
`The user agent option "reconnectionDelay" as has apparently been specified and has been deprecated. ` +
|
|
209
|
-
"It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.";
|
|
210
|
-
this.logger.warn(deprecatedMessage);
|
|
211
|
-
}
|
|
212
|
-
if (options.reconnectionAttempts !== undefined) {
|
|
213
|
-
const deprecatedMessage =
|
|
214
|
-
`The user agent option "reconnectionAttempts" as has apparently been specified and has been deprecated. ` +
|
|
215
|
-
"It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.";
|
|
216
|
-
this.logger.warn(deprecatedMessage);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Initialize Transport
|
|
220
|
-
this._transport = new this.options.transportConstructor(
|
|
221
|
-
this.getLogger("sip.Transport"),
|
|
222
|
-
this.options.transportOptions
|
|
223
|
-
);
|
|
224
|
-
this.initTransportCallbacks();
|
|
225
|
-
|
|
226
|
-
// Initialize Contact
|
|
227
|
-
this._contact = this.initContact();
|
|
228
|
-
|
|
229
|
-
// Initialize UserAgentCore
|
|
230
|
-
this._userAgentCore = this.initCore();
|
|
231
|
-
|
|
232
|
-
if (this.options.autoStart) {
|
|
233
|
-
this.start();
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Create a URI instance from a string.
|
|
239
|
-
* @param uri - The string to parse.
|
|
240
|
-
*
|
|
241
|
-
* @example
|
|
242
|
-
* ```ts
|
|
243
|
-
* const uri = UserAgent.makeURI("sip:edgar@example.com");
|
|
244
|
-
* ```
|
|
245
|
-
*/
|
|
246
|
-
public static makeURI(uri: string): URI | undefined {
|
|
247
|
-
return Grammar.URIParse(uri);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/** Default user agent options. */
|
|
251
|
-
private static defaultOptions(): Required<UserAgentOptions> {
|
|
252
|
-
return {
|
|
253
|
-
allowLegacyNotifications: false,
|
|
254
|
-
authorizationHa1: "",
|
|
255
|
-
authorizationPassword: "",
|
|
256
|
-
authorizationUsername: "",
|
|
257
|
-
autoStart: false,
|
|
258
|
-
autoStop: true,
|
|
259
|
-
delegate: {},
|
|
260
|
-
contactName: "",
|
|
261
|
-
contactParams: { transport: "ws" },
|
|
262
|
-
displayName: "",
|
|
263
|
-
forceRport: false,
|
|
264
|
-
hackAllowUnregisteredOptionTags: false,
|
|
265
|
-
hackIpInContact: false,
|
|
266
|
-
hackViaTcp: false,
|
|
267
|
-
logBuiltinEnabled: true,
|
|
268
|
-
logConfiguration: true,
|
|
269
|
-
logConnector: (): void => {
|
|
270
|
-
/* noop */
|
|
271
|
-
},
|
|
272
|
-
logLevel: "log",
|
|
273
|
-
noAnswerTimeout: 60,
|
|
274
|
-
preloadedRouteSet: [],
|
|
275
|
-
reconnectionAttempts: 0,
|
|
276
|
-
reconnectionDelay: 4,
|
|
277
|
-
sendInitialProvisionalResponse: true,
|
|
278
|
-
sessionDescriptionHandlerFactory: defaultSessionDescriptionHandlerFactory(),
|
|
279
|
-
sessionDescriptionHandlerFactoryOptions: {},
|
|
280
|
-
sipExtension100rel: SIPExtension.Unsupported,
|
|
281
|
-
sipExtensionReplaces: SIPExtension.Unsupported,
|
|
282
|
-
sipExtensionExtraSupported: [],
|
|
283
|
-
sipjsId: "",
|
|
284
|
-
transportConstructor: WebTransport,
|
|
285
|
-
transportOptions: {},
|
|
286
|
-
uri: new URI("sip", "anonymous", "anonymous.invalid"),
|
|
287
|
-
userAgentString: "SIP.js/" + LIBRARY_VERSION,
|
|
288
|
-
viaHost: ""
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Strip properties with undefined values from options.
|
|
294
|
-
* This is a work around while waiting for missing vs undefined to be addressed (or not)...
|
|
295
|
-
* https://github.com/Microsoft/TypeScript/issues/13195
|
|
296
|
-
* @param options - Options to reduce
|
|
297
|
-
*/
|
|
298
|
-
private static stripUndefinedProperties(options: Partial<UserAgentOptions>): Partial<UserAgentOptions> {
|
|
299
|
-
return Object.keys(options).reduce((object, key) => {
|
|
300
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
301
|
-
if ((options as any)[key] !== undefined) {
|
|
302
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
303
|
-
(object as any)[key] = (options as any)[key];
|
|
304
|
-
}
|
|
305
|
-
return object;
|
|
306
|
-
}, {});
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* User agent configuration.
|
|
311
|
-
*/
|
|
312
|
-
public get configuration(): Required<UserAgentOptions> {
|
|
313
|
-
return this.options;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* User agent contact.
|
|
318
|
-
*/
|
|
319
|
-
public get contact(): Contact {
|
|
320
|
-
return this._contact;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* User agent state.
|
|
325
|
-
*/
|
|
326
|
-
public get state(): UserAgentState {
|
|
327
|
-
return this._state;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* User agent state change emitter.
|
|
332
|
-
*/
|
|
333
|
-
public get stateChange(): Emitter<UserAgentState> {
|
|
334
|
-
return this._stateEventEmitter;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* User agent transport.
|
|
339
|
-
*/
|
|
340
|
-
public get transport(): Transport {
|
|
341
|
-
return this._transport;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* User agent core.
|
|
346
|
-
*/
|
|
347
|
-
public get userAgentCore(): UserAgentCore {
|
|
348
|
-
return this._userAgentCore;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* The logger.
|
|
353
|
-
*/
|
|
354
|
-
public getLogger(category: string, label?: string): Logger {
|
|
355
|
-
return this.loggerFactory.getLogger(category, label);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* The logger factory.
|
|
360
|
-
*/
|
|
361
|
-
public getLoggerFactory(): LoggerFactory {
|
|
362
|
-
return this.loggerFactory;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* True if transport is connected.
|
|
367
|
-
*/
|
|
368
|
-
public isConnected(): boolean {
|
|
369
|
-
return this.transport.isConnected();
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Reconnect the transport.
|
|
374
|
-
*/
|
|
375
|
-
public reconnect(): Promise<void> {
|
|
376
|
-
if (this.state === UserAgentState.Stopped) {
|
|
377
|
-
return Promise.reject(new Error("User agent stopped."));
|
|
378
|
-
}
|
|
379
|
-
// Make sure we don't call synchronously
|
|
380
|
-
return Promise.resolve().then(() => this.transport.connect());
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Start the user agent.
|
|
385
|
-
*
|
|
386
|
-
* @remarks
|
|
387
|
-
* Resolves if transport connects, otherwise rejects.
|
|
388
|
-
*
|
|
389
|
-
* @example
|
|
390
|
-
* ```ts
|
|
391
|
-
* userAgent.start()
|
|
392
|
-
* .then(() => {
|
|
393
|
-
* // userAgent.isConnected() === true
|
|
394
|
-
* })
|
|
395
|
-
* .catch((error: Error) => {
|
|
396
|
-
* // userAgent.isConnected() === false
|
|
397
|
-
* });
|
|
398
|
-
* ```
|
|
399
|
-
*/
|
|
400
|
-
public start(): Promise<void> {
|
|
401
|
-
if (this.state === UserAgentState.Started) {
|
|
402
|
-
this.logger.warn(`User agent already started`);
|
|
403
|
-
return Promise.resolve();
|
|
404
|
-
}
|
|
405
|
-
this.logger.log(`Starting ${this.configuration.uri}`);
|
|
406
|
-
|
|
407
|
-
// Transition state
|
|
408
|
-
this.transitionState(UserAgentState.Started);
|
|
409
|
-
|
|
410
|
-
// TODO: Review this as it is not clear it has any benefit and at worst causes additional load the server.
|
|
411
|
-
// On unload it may be best to simply in most scenarios to do nothing. Furthermore and regardless, this
|
|
412
|
-
// kind of behavior seems more appropriate to be managed by the consumer of the API than the API itself.
|
|
413
|
-
// Should this perhaps be deprecated?
|
|
414
|
-
//
|
|
415
|
-
// Add window unload event listener
|
|
416
|
-
if (this.options.autoStop) {
|
|
417
|
-
// Google Chrome Packaged Apps don't allow 'unload' listeners: unload is not available in packaged apps
|
|
418
|
-
const googleChromePackagedApp = typeof chrome !== "undefined" && chrome.app && chrome.app.runtime ? true : false;
|
|
419
|
-
if (typeof window !== "undefined" && typeof window.addEventListener === "function" && !googleChromePackagedApp) {
|
|
420
|
-
window.addEventListener("unload", this.unloadListener);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
return this.transport.connect();
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* Stop the user agent.
|
|
429
|
-
*
|
|
430
|
-
* @remarks
|
|
431
|
-
* Resolves when the user agent has completed a graceful shutdown.
|
|
432
|
-
* ```txt
|
|
433
|
-
* 1) Sessions terminate.
|
|
434
|
-
* 2) Registerers unregister.
|
|
435
|
-
* 3) Subscribers unsubscribe.
|
|
436
|
-
* 4) Publishers unpublish.
|
|
437
|
-
* 5) Transport disconnects.
|
|
438
|
-
* 6) User Agent Core resets.
|
|
439
|
-
* ```
|
|
440
|
-
* NOTE: While this is a "graceful shutdown", it can also be very slow one if you
|
|
441
|
-
* are waiting for the returned Promise to resolve. The disposal of the clients and
|
|
442
|
-
* dialogs is done serially - waiting on one to finish before moving on to the next.
|
|
443
|
-
* This can be slow if there are lot of subscriptions to unsubscribe for example.
|
|
444
|
-
*
|
|
445
|
-
* THE SLOW PACE IS INTENTIONAL!
|
|
446
|
-
* While one could spin them all down in parallel, this could slam the remote server.
|
|
447
|
-
* It is bad practice to denial of service attack (DoS attack) servers!!!
|
|
448
|
-
* Moreover, production servers will automatically blacklist clients which send too
|
|
449
|
-
* many requests in too short a period of time - dropping any additional requests.
|
|
450
|
-
*
|
|
451
|
-
* If a different approach to disposing is needed, one can implement whatever is
|
|
452
|
-
* needed and execute that prior to calling `stop()`. Alternatively one may simply
|
|
453
|
-
* not wait for the Promise returned by `stop()` to complete.
|
|
454
|
-
*/
|
|
455
|
-
public async stop(): Promise<void> {
|
|
456
|
-
if (this.state === UserAgentState.Stopped) {
|
|
457
|
-
this.logger.warn(`User agent already stopped`);
|
|
458
|
-
return Promise.resolve();
|
|
459
|
-
}
|
|
460
|
-
this.logger.log(`Stopping ${this.configuration.uri}`);
|
|
461
|
-
|
|
462
|
-
// Transition state
|
|
463
|
-
this.transitionState(UserAgentState.Stopped);
|
|
464
|
-
|
|
465
|
-
// TODO: See comments with associated complimentary code in start(). Should this perhaps be deprecated?
|
|
466
|
-
// Remove window unload event listener
|
|
467
|
-
if (this.options.autoStop) {
|
|
468
|
-
// Google Chrome Packaged Apps don't allow 'unload' listeners: unload is not available in packaged apps
|
|
469
|
-
const googleChromePackagedApp = typeof chrome !== "undefined" && chrome.app && chrome.app.runtime ? true : false;
|
|
470
|
-
if (typeof window !== "undefined" && window.removeEventListener && !googleChromePackagedApp) {
|
|
471
|
-
window.removeEventListener("unload", this.unloadListener);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// Be careful here to use a local references as start() can be called
|
|
476
|
-
// again before we complete and we don't want to touch new clients
|
|
477
|
-
// and we don't want to step on the new instances (or vice versa).
|
|
478
|
-
const publishers = { ...this._publishers };
|
|
479
|
-
const registerers = { ...this._registerers };
|
|
480
|
-
const sessions = { ...this._sessions };
|
|
481
|
-
const subscriptions = { ...this._subscriptions };
|
|
482
|
-
const transport = this.transport;
|
|
483
|
-
const userAgentCore = this.userAgentCore;
|
|
484
|
-
|
|
485
|
-
//
|
|
486
|
-
// At this point we have completed the state transition and everything
|
|
487
|
-
// following will effectively run async and MUST NOT cause any issues
|
|
488
|
-
// if UserAgent.start() is called while the following code continues.
|
|
489
|
-
//
|
|
490
|
-
// TODO: Minor optimization.
|
|
491
|
-
// The disposal in all cases involves, in part, sending messages which
|
|
492
|
-
// is not worth doing if the transport is not connected as we know attempting
|
|
493
|
-
// to send messages will be futile. But none of these disposal methods check
|
|
494
|
-
// if that's is the case and it would be easy for them to do so at this point.
|
|
495
|
-
|
|
496
|
-
// Dispose of Registerers
|
|
497
|
-
this.logger.log(`Dispose of registerers`);
|
|
498
|
-
for (const id in registerers) {
|
|
499
|
-
if (registerers[id]) {
|
|
500
|
-
await registerers[id].dispose().catch((error: Error) => {
|
|
501
|
-
this.logger.error(error.message);
|
|
502
|
-
delete this._registerers[id];
|
|
503
|
-
throw error;
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
// Dispose of Sessions
|
|
509
|
-
this.logger.log(`Dispose of sessions`);
|
|
510
|
-
for (const id in sessions) {
|
|
511
|
-
if (sessions[id]) {
|
|
512
|
-
await sessions[id].dispose().catch((error: Error) => {
|
|
513
|
-
this.logger.error(error.message);
|
|
514
|
-
delete this._sessions[id];
|
|
515
|
-
throw error;
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
// Dispose of Subscriptions
|
|
521
|
-
this.logger.log(`Dispose of subscriptions`);
|
|
522
|
-
for (const id in subscriptions) {
|
|
523
|
-
if (subscriptions[id]) {
|
|
524
|
-
await subscriptions[id].dispose().catch((error: Error) => {
|
|
525
|
-
this.logger.error(error.message);
|
|
526
|
-
delete this._subscriptions[id];
|
|
527
|
-
throw error;
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
// Dispose of Publishers
|
|
533
|
-
this.logger.log(`Dispose of publishers`);
|
|
534
|
-
for (const id in publishers) {
|
|
535
|
-
if (publishers[id]) {
|
|
536
|
-
await publishers[id].dispose().catch((error: Error) => {
|
|
537
|
-
this.logger.error(error.message);
|
|
538
|
-
delete this._publishers[id];
|
|
539
|
-
throw error;
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
// Dispose of the transport (disconnecting)
|
|
545
|
-
this.logger.log(`Dispose of transport`);
|
|
546
|
-
await transport.dispose().catch((error: Error) => {
|
|
547
|
-
this.logger.error(error.message);
|
|
548
|
-
throw error;
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
// Dispose of the user agent core (resetting)
|
|
552
|
-
this.logger.log(`Dispose of core`);
|
|
553
|
-
userAgentCore.dispose();
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
/**
|
|
557
|
-
* Used to avoid circular references.
|
|
558
|
-
* @internal
|
|
559
|
-
*/
|
|
560
|
-
public _makeInviter(targetURI: URI, options?: InviterOptions): Inviter {
|
|
561
|
-
return new Inviter(this, targetURI, options);
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
/**
|
|
565
|
-
* Attempt reconnection up to `maxReconnectionAttempts` times.
|
|
566
|
-
* @param reconnectionAttempt - Current attempt number.
|
|
567
|
-
*/
|
|
568
|
-
private attemptReconnection(reconnectionAttempt = 1): void {
|
|
569
|
-
const reconnectionAttempts = this.options.reconnectionAttempts;
|
|
570
|
-
const reconnectionDelay = this.options.reconnectionDelay;
|
|
571
|
-
|
|
572
|
-
if (reconnectionAttempt > reconnectionAttempts) {
|
|
573
|
-
this.logger.log(`Maximum reconnection attempts reached`);
|
|
574
|
-
return;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
this.logger.log(`Reconnection attempt ${reconnectionAttempt} of ${reconnectionAttempts} - trying`);
|
|
578
|
-
setTimeout(
|
|
579
|
-
() => {
|
|
580
|
-
this.reconnect()
|
|
581
|
-
.then(() => {
|
|
582
|
-
this.logger.log(`Reconnection attempt ${reconnectionAttempt} of ${reconnectionAttempts} - succeeded`);
|
|
583
|
-
})
|
|
584
|
-
.catch((error: Error) => {
|
|
585
|
-
this.logger.error(error.message);
|
|
586
|
-
this.logger.log(`Reconnection attempt ${reconnectionAttempt} of ${reconnectionAttempts} - failed`);
|
|
587
|
-
this.attemptReconnection(++reconnectionAttempt);
|
|
588
|
-
});
|
|
589
|
-
},
|
|
590
|
-
reconnectionAttempt === 1 ? 0 : reconnectionDelay * 1000
|
|
591
|
-
);
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
/**
|
|
595
|
-
* Initialize contact.
|
|
596
|
-
*/
|
|
597
|
-
private initContact(): Contact {
|
|
598
|
-
const contactName = this.options.contactName !== "" ? this.options.contactName : createRandomToken(8);
|
|
599
|
-
const contactParams = this.options.contactParams;
|
|
600
|
-
const contact = {
|
|
601
|
-
pubGruu: undefined,
|
|
602
|
-
tempGruu: undefined,
|
|
603
|
-
uri: new URI("sip", contactName, this.options.viaHost, undefined, contactParams),
|
|
604
|
-
toString: (contactToStringOptions: { anonymous?: boolean; outbound?: boolean } = {}): string => {
|
|
605
|
-
const anonymous = contactToStringOptions.anonymous || false;
|
|
606
|
-
const outbound = contactToStringOptions.outbound || false;
|
|
607
|
-
let contactString = "<";
|
|
608
|
-
if (anonymous) {
|
|
609
|
-
contactString +=
|
|
610
|
-
this.contact.tempGruu ||
|
|
611
|
-
`sip:anonymous@anonymous.invalid;transport=${contactParams.transport ? contactParams.transport : "ws"}`;
|
|
612
|
-
} else {
|
|
613
|
-
contactString += this.contact.pubGruu || this.contact.uri;
|
|
614
|
-
}
|
|
615
|
-
if (outbound) {
|
|
616
|
-
contactString += ";ob";
|
|
617
|
-
}
|
|
618
|
-
contactString += ">";
|
|
619
|
-
return contactString;
|
|
620
|
-
}
|
|
621
|
-
};
|
|
622
|
-
return contact;
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
/**
|
|
626
|
-
* Initialize user agent core.
|
|
627
|
-
*/
|
|
628
|
-
private initCore(): UserAgentCore {
|
|
629
|
-
// supported options
|
|
630
|
-
let supportedOptionTags: Array<string> = [];
|
|
631
|
-
supportedOptionTags.push("outbound"); // TODO: is this really supported?
|
|
632
|
-
if (this.options.sipExtension100rel === SIPExtension.Supported) {
|
|
633
|
-
supportedOptionTags.push("100rel");
|
|
634
|
-
}
|
|
635
|
-
if (this.options.sipExtensionReplaces === SIPExtension.Supported) {
|
|
636
|
-
supportedOptionTags.push("replaces");
|
|
637
|
-
}
|
|
638
|
-
if (this.options.sipExtensionExtraSupported) {
|
|
639
|
-
supportedOptionTags.push(...this.options.sipExtensionExtraSupported);
|
|
640
|
-
}
|
|
641
|
-
if (!this.options.hackAllowUnregisteredOptionTags) {
|
|
642
|
-
supportedOptionTags = supportedOptionTags.filter((optionTag) => UserAgentRegisteredOptionTags[optionTag]);
|
|
643
|
-
}
|
|
644
|
-
supportedOptionTags = Array.from(new Set(supportedOptionTags)); // array of unique values
|
|
645
|
-
|
|
646
|
-
// FIXME: TODO: This was ported, but this is and was just plain broken.
|
|
647
|
-
const supportedOptionTagsResponse = supportedOptionTags.slice();
|
|
648
|
-
if (this.contact.pubGruu || this.contact.tempGruu) {
|
|
649
|
-
supportedOptionTagsResponse.push("gruu");
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
// core configuration
|
|
653
|
-
const userAgentCoreConfiguration: UserAgentCoreConfiguration = {
|
|
654
|
-
aor: this.options.uri,
|
|
655
|
-
contact: this.contact,
|
|
656
|
-
displayName: this.options.displayName,
|
|
657
|
-
loggerFactory: this.loggerFactory,
|
|
658
|
-
hackViaTcp: this.options.hackViaTcp,
|
|
659
|
-
routeSet: this.options.preloadedRouteSet,
|
|
660
|
-
supportedOptionTags,
|
|
661
|
-
supportedOptionTagsResponse,
|
|
662
|
-
sipjsId: this.options.sipjsId,
|
|
663
|
-
userAgentHeaderFieldValue: this.options.userAgentString,
|
|
664
|
-
viaForceRport: this.options.forceRport,
|
|
665
|
-
viaHost: this.options.viaHost,
|
|
666
|
-
authenticationFactory: () => {
|
|
667
|
-
const username = this.options.authorizationUsername
|
|
668
|
-
? this.options.authorizationUsername
|
|
669
|
-
: this.options.uri.user; // if authorization username not provided, use uri user as username
|
|
670
|
-
const password = this.options.authorizationPassword ? this.options.authorizationPassword : undefined;
|
|
671
|
-
const ha1 = this.options.authorizationHa1 ? this.options.authorizationHa1 : undefined;
|
|
672
|
-
return new DigestAuthentication(this.getLoggerFactory(), ha1, username, password);
|
|
673
|
-
},
|
|
674
|
-
transportAccessor: () => this.transport
|
|
675
|
-
};
|
|
676
|
-
|
|
677
|
-
const userAgentCoreDelegate: UserAgentCoreDelegate = {
|
|
678
|
-
onInvite: (incomingInviteRequest: IncomingInviteRequest): void => {
|
|
679
|
-
const invitation = new Invitation(this, incomingInviteRequest);
|
|
680
|
-
|
|
681
|
-
incomingInviteRequest.delegate = {
|
|
682
|
-
onCancel: (cancel: IncomingRequestMessage): void => {
|
|
683
|
-
invitation._onCancel(cancel);
|
|
684
|
-
},
|
|
685
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
686
|
-
onTransportError: (error: TransportError): void => {
|
|
687
|
-
// A server transaction MUST NOT discard transaction state based only on
|
|
688
|
-
// encountering a non-recoverable transport error when sending a
|
|
689
|
-
// response. Instead, the associated INVITE server transaction state
|
|
690
|
-
// machine MUST remain in its current state. (Timers will eventually
|
|
691
|
-
// cause it to transition to the "Terminated" state).
|
|
692
|
-
// https://tools.ietf.org/html/rfc6026#section-7.1
|
|
693
|
-
|
|
694
|
-
// As noted in the comment above, we are to leaving it to the transaction
|
|
695
|
-
// timers to eventually cause the transaction to sort itself out in the case
|
|
696
|
-
// of a transport failure in an invite server transaction. This delegate method
|
|
697
|
-
// is here simply here for completeness and to make it clear that it provides
|
|
698
|
-
// nothing more than informational hook into the core. That is, if you think
|
|
699
|
-
// you should be trying to deal with a transport error here, you are likely wrong.
|
|
700
|
-
this.logger.error("A transport error has occurred while handling an incoming INVITE request.");
|
|
701
|
-
}
|
|
702
|
-
};
|
|
703
|
-
|
|
704
|
-
// FIXME: Ported - 100 Trying send should be configurable.
|
|
705
|
-
// Only required if TU will not respond in 200ms.
|
|
706
|
-
// https://tools.ietf.org/html/rfc3261#section-17.2.1
|
|
707
|
-
incomingInviteRequest.trying();
|
|
708
|
-
|
|
709
|
-
// The Replaces header contains information used to match an existing
|
|
710
|
-
// SIP dialog (call-id, to-tag, and from-tag). Upon receiving an INVITE
|
|
711
|
-
// with a Replaces header, the User Agent (UA) attempts to match this
|
|
712
|
-
// information with a confirmed or early dialog.
|
|
713
|
-
// https://tools.ietf.org/html/rfc3891#section-3
|
|
714
|
-
if (this.options.sipExtensionReplaces !== SIPExtension.Unsupported) {
|
|
715
|
-
const message = incomingInviteRequest.message;
|
|
716
|
-
const replaces = message.parseHeader("replaces");
|
|
717
|
-
if (replaces) {
|
|
718
|
-
const callId = replaces.call_id;
|
|
719
|
-
if (typeof callId !== "string") {
|
|
720
|
-
throw new Error("Type of call id is not string");
|
|
721
|
-
}
|
|
722
|
-
const toTag = replaces.replaces_to_tag;
|
|
723
|
-
if (typeof toTag !== "string") {
|
|
724
|
-
throw new Error("Type of to tag is not string");
|
|
725
|
-
}
|
|
726
|
-
const fromTag = replaces.replaces_from_tag;
|
|
727
|
-
if (typeof fromTag !== "string") {
|
|
728
|
-
throw new Error("type of from tag is not string");
|
|
729
|
-
}
|
|
730
|
-
const targetDialogId = callId + toTag + fromTag;
|
|
731
|
-
const targetDialog = this.userAgentCore.dialogs.get(targetDialogId);
|
|
732
|
-
|
|
733
|
-
// If no match is found, the UAS rejects the INVITE and returns a 481
|
|
734
|
-
// Call/Transaction Does Not Exist response. Likewise, if the Replaces
|
|
735
|
-
// header field matches a dialog which was not created with an INVITE,
|
|
736
|
-
// the UAS MUST reject the request with a 481 response.
|
|
737
|
-
// https://tools.ietf.org/html/rfc3891#section-3
|
|
738
|
-
if (!targetDialog) {
|
|
739
|
-
invitation.reject({ statusCode: 481 });
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
// If the Replaces header field matches a confirmed dialog, it checks
|
|
744
|
-
// for the presence of the "early-only" flag in the Replaces header
|
|
745
|
-
// field. (This flag allows the UAC to prevent a potentially
|
|
746
|
-
// undesirable race condition described in Section 7.1.) If the flag is
|
|
747
|
-
// present, the UA rejects the request with a 486 Busy response.
|
|
748
|
-
// https://tools.ietf.org/html/rfc3891#section-3
|
|
749
|
-
if (!targetDialog.early && replaces.early_only === true) {
|
|
750
|
-
invitation.reject({ statusCode: 486 });
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
// Provide a handle on the session being replaced.
|
|
755
|
-
const targetSession = this._sessions[callId + fromTag] || this._sessions[callId + toTag] || undefined;
|
|
756
|
-
if (!targetSession) {
|
|
757
|
-
throw new Error("Session does not exist.");
|
|
758
|
-
}
|
|
759
|
-
invitation._replacee = targetSession;
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
// Delegate invitation handling.
|
|
764
|
-
if (this.delegate?.onInvite) {
|
|
765
|
-
if (invitation.autoSendAnInitialProvisionalResponse) {
|
|
766
|
-
invitation.progress().then(() => {
|
|
767
|
-
if (this.delegate?.onInvite === undefined) {
|
|
768
|
-
throw new Error("onInvite undefined.");
|
|
769
|
-
}
|
|
770
|
-
this.delegate.onInvite(invitation);
|
|
771
|
-
});
|
|
772
|
-
return;
|
|
773
|
-
}
|
|
774
|
-
this.delegate.onInvite(invitation);
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
// A common scenario occurs when the callee is currently not willing or
|
|
779
|
-
// able to take additional calls at this end system. A 486 (Busy Here)
|
|
780
|
-
// SHOULD be returned in such a scenario.
|
|
781
|
-
// https://tools.ietf.org/html/rfc3261#section-13.3.1.3
|
|
782
|
-
invitation.reject({ statusCode: 486 });
|
|
783
|
-
},
|
|
784
|
-
onMessage: (incomingMessageRequest: IncomingMessageRequest): void => {
|
|
785
|
-
if (this.delegate && this.delegate.onMessage) {
|
|
786
|
-
const message = new Message(incomingMessageRequest);
|
|
787
|
-
this.delegate.onMessage(message);
|
|
788
|
-
} else {
|
|
789
|
-
// Accept the MESSAGE request, but do nothing with it.
|
|
790
|
-
incomingMessageRequest.accept();
|
|
791
|
-
}
|
|
792
|
-
},
|
|
793
|
-
onNotify: (incomingNotifyRequest: IncomingNotifyRequest): void => {
|
|
794
|
-
// NOTIFY requests are sent to inform subscribers of changes in state to
|
|
795
|
-
// which the subscriber has a subscription. Subscriptions are created
|
|
796
|
-
// using the SUBSCRIBE method. In legacy implementations, it is
|
|
797
|
-
// possible that other means of subscription creation have been used.
|
|
798
|
-
// However, this specification does not allow the creation of
|
|
799
|
-
// subscriptions except through SUBSCRIBE requests and (for backwards-
|
|
800
|
-
// compatibility) REFER requests [RFC3515].
|
|
801
|
-
// https://tools.ietf.org/html/rfc6665#section-3.2
|
|
802
|
-
if (this.delegate && this.delegate.onNotify) {
|
|
803
|
-
const notification = new Notification(incomingNotifyRequest);
|
|
804
|
-
this.delegate.onNotify(notification);
|
|
805
|
-
} else {
|
|
806
|
-
// Per the above which obsoletes https://tools.ietf.org/html/rfc3265,
|
|
807
|
-
// the use of out of dialog NOTIFY is obsolete, but...
|
|
808
|
-
if (this.options.allowLegacyNotifications) {
|
|
809
|
-
incomingNotifyRequest.accept(); // Accept the NOTIFY request, but do nothing with it.
|
|
810
|
-
} else {
|
|
811
|
-
incomingNotifyRequest.reject({ statusCode: 481 });
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
},
|
|
815
|
-
onRefer: (incomingReferRequest: IncomingReferRequest): void => {
|
|
816
|
-
this.logger.warn("Received an out of dialog REFER request");
|
|
817
|
-
// TOOD: this.delegate.onRefer(...)
|
|
818
|
-
if (this.delegate && this.delegate.onReferRequest) {
|
|
819
|
-
this.delegate.onReferRequest(incomingReferRequest);
|
|
820
|
-
} else {
|
|
821
|
-
incomingReferRequest.reject({ statusCode: 405 });
|
|
822
|
-
}
|
|
823
|
-
},
|
|
824
|
-
onRegister: (incomingRegisterRequest: IncomingRegisterRequest): void => {
|
|
825
|
-
this.logger.warn("Received an out of dialog REGISTER request");
|
|
826
|
-
// TOOD: this.delegate.onRegister(...)
|
|
827
|
-
if (this.delegate && this.delegate.onRegisterRequest) {
|
|
828
|
-
this.delegate.onRegisterRequest(incomingRegisterRequest);
|
|
829
|
-
} else {
|
|
830
|
-
incomingRegisterRequest.reject({ statusCode: 405 });
|
|
831
|
-
}
|
|
832
|
-
},
|
|
833
|
-
onSubscribe: (incomingSubscribeRequest: IncomingSubscribeRequest): void => {
|
|
834
|
-
this.logger.warn("Received an out of dialog SUBSCRIBE request");
|
|
835
|
-
// TOOD: this.delegate.onSubscribe(...)
|
|
836
|
-
if (this.delegate && this.delegate.onSubscribeRequest) {
|
|
837
|
-
this.delegate.onSubscribeRequest(incomingSubscribeRequest);
|
|
838
|
-
} else {
|
|
839
|
-
incomingSubscribeRequest.reject({ statusCode: 405 });
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
};
|
|
843
|
-
|
|
844
|
-
return new UserAgentCore(userAgentCoreConfiguration, userAgentCoreDelegate);
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
private initTransportCallbacks(): void {
|
|
848
|
-
this.transport.onConnect = (): void => this.onTransportConnect();
|
|
849
|
-
this.transport.onDisconnect = (error?: Error): void => this.onTransportDisconnect(error);
|
|
850
|
-
this.transport.onMessage = (message: string): void => this.onTransportMessage(message);
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
private onTransportConnect(): void {
|
|
854
|
-
if (this.state === UserAgentState.Stopped) {
|
|
855
|
-
return;
|
|
856
|
-
}
|
|
857
|
-
if (this.delegate && this.delegate.onConnect) {
|
|
858
|
-
this.delegate.onConnect();
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
private onTransportDisconnect(error?: Error): void {
|
|
863
|
-
if (this.state === UserAgentState.Stopped) {
|
|
864
|
-
return;
|
|
865
|
-
}
|
|
866
|
-
if (this.delegate && this.delegate.onDisconnect) {
|
|
867
|
-
this.delegate.onDisconnect(error);
|
|
868
|
-
}
|
|
869
|
-
// Only attempt to reconnect if network/server dropped the connection.
|
|
870
|
-
if (error && this.options.reconnectionAttempts > 0) {
|
|
871
|
-
this.attemptReconnection();
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
private onTransportMessage(messageString: string): void {
|
|
876
|
-
const message = Parser.parseMessage(messageString, this.getLogger("sip.Parser"));
|
|
877
|
-
if (!message) {
|
|
878
|
-
this.logger.warn("Failed to parse incoming message. Dropping.");
|
|
879
|
-
return;
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
if (this.state === UserAgentState.Stopped && message instanceof IncomingRequestMessage) {
|
|
883
|
-
this.logger.warn(`Received ${message.method} request while stopped. Dropping.`);
|
|
884
|
-
return;
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
// A valid SIP request formulated by a UAC MUST, at a minimum, contain
|
|
888
|
-
// the following header fields: To, From, CSeq, Call-ID, Max-Forwards,
|
|
889
|
-
// and Via; all of these header fields are mandatory in all SIP
|
|
890
|
-
// requests.
|
|
891
|
-
// https://tools.ietf.org/html/rfc3261#section-8.1.1
|
|
892
|
-
const hasMinimumHeaders = (): boolean => {
|
|
893
|
-
const mandatoryHeaders: Array<string> = ["from", "to", "call_id", "cseq", "via"];
|
|
894
|
-
for (const header of mandatoryHeaders) {
|
|
895
|
-
if (!message.hasHeader(header)) {
|
|
896
|
-
this.logger.warn(`Missing mandatory header field : ${header}.`);
|
|
897
|
-
return false;
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
return true;
|
|
901
|
-
};
|
|
902
|
-
|
|
903
|
-
// Request Checks
|
|
904
|
-
if (message instanceof IncomingRequestMessage) {
|
|
905
|
-
// This is port of SanityCheck.minimumHeaders().
|
|
906
|
-
if (!hasMinimumHeaders()) {
|
|
907
|
-
this.logger.warn(`Request missing mandatory header field. Dropping.`);
|
|
908
|
-
return;
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
// FIXME: This is non-standard and should be a configurable behavior (desirable regardless).
|
|
912
|
-
// Custom SIP.js check to reject request from ourself (this instance of SIP.js).
|
|
913
|
-
// This is port of SanityCheck.rfc3261_16_3_4().
|
|
914
|
-
if (!message.toTag && message.callId.substr(0, 5) === this.options.sipjsId) {
|
|
915
|
-
this.userAgentCore.replyStateless(message, { statusCode: 482 });
|
|
916
|
-
return;
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
// FIXME: This should be Transport check before we get here (Section 18).
|
|
920
|
-
// Custom SIP.js check to reject requests if body length wrong.
|
|
921
|
-
// This is port of SanityCheck.rfc3261_18_3_request().
|
|
922
|
-
const len: number = utf8Length(message.body);
|
|
923
|
-
const contentLength: string | undefined = message.getHeader("content-length");
|
|
924
|
-
if (contentLength && len < Number(contentLength)) {
|
|
925
|
-
this.userAgentCore.replyStateless(message, { statusCode: 400 });
|
|
926
|
-
return;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
// Response Checks
|
|
931
|
-
if (message instanceof IncomingResponseMessage) {
|
|
932
|
-
// This is port of SanityCheck.minimumHeaders().
|
|
933
|
-
if (!hasMinimumHeaders()) {
|
|
934
|
-
this.logger.warn(`Response missing mandatory header field. Dropping.`);
|
|
935
|
-
return;
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
// Custom SIP.js check to drop responses if multiple Via headers.
|
|
939
|
-
// This is port of SanityCheck.rfc3261_8_1_3_3().
|
|
940
|
-
if (message.getHeaders("via").length > 1) {
|
|
941
|
-
this.logger.warn("More than one Via header field present in the response. Dropping.");
|
|
942
|
-
return;
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
// FIXME: This should be Transport check before we get here (Section 18).
|
|
946
|
-
// Custom SIP.js check to drop responses if bad Via header.
|
|
947
|
-
// This is port of SanityCheck.rfc3261_18_1_2().
|
|
948
|
-
if (message.via.host !== this.options.viaHost || message.via.port !== undefined) {
|
|
949
|
-
this.logger.warn("Via sent-by in the response does not match UA Via host value. Dropping.");
|
|
950
|
-
return;
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
// FIXME: This should be Transport check before we get here (Section 18).
|
|
954
|
-
// Custom SIP.js check to reject requests if body length wrong.
|
|
955
|
-
// This is port of SanityCheck.rfc3261_18_3_response().
|
|
956
|
-
const len: number = utf8Length(message.body);
|
|
957
|
-
const contentLength: string | undefined = message.getHeader("content-length");
|
|
958
|
-
if (contentLength && len < Number(contentLength)) {
|
|
959
|
-
this.logger.warn("Message body length is lower than the value in Content-Length header field. Dropping.");
|
|
960
|
-
return;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
// Handle Request
|
|
965
|
-
if (message instanceof IncomingRequestMessage) {
|
|
966
|
-
this.userAgentCore.receiveIncomingRequestFromTransport(message);
|
|
967
|
-
return;
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
// Handle Response
|
|
971
|
-
if (message instanceof IncomingResponseMessage) {
|
|
972
|
-
this.userAgentCore.receiveIncomingResponseFromTransport(message);
|
|
973
|
-
return;
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
throw new Error("Invalid message type.");
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
/**
|
|
980
|
-
* Transition state.
|
|
981
|
-
*/
|
|
982
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
983
|
-
private transitionState(newState: UserAgentState, error?: Error): void {
|
|
984
|
-
const invalidTransition = (): void => {
|
|
985
|
-
throw new Error(`Invalid state transition from ${this._state} to ${newState}`);
|
|
986
|
-
};
|
|
987
|
-
|
|
988
|
-
// Validate state transition
|
|
989
|
-
switch (this._state) {
|
|
990
|
-
case UserAgentState.Started:
|
|
991
|
-
if (newState !== UserAgentState.Stopped) {
|
|
992
|
-
invalidTransition();
|
|
993
|
-
}
|
|
994
|
-
break;
|
|
995
|
-
case UserAgentState.Stopped:
|
|
996
|
-
if (newState !== UserAgentState.Started) {
|
|
997
|
-
invalidTransition();
|
|
998
|
-
}
|
|
999
|
-
break;
|
|
1000
|
-
default:
|
|
1001
|
-
throw new Error("Unknown state.");
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
// Update state
|
|
1005
|
-
this.logger.log(`Transitioned from ${this._state} to ${newState}`);
|
|
1006
|
-
this._state = newState;
|
|
1007
|
-
this._stateEventEmitter.emit(this._state);
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
/** Unload listener. */
|
|
1011
|
-
private unloadListener = (): void => {
|
|
1012
|
-
this.stop();
|
|
1013
|
-
};
|
|
1014
|
-
}
|