ue-softphone-sdk 2.1.9 → 2.2.1
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 +1 -2
- package/package.json +6 -6
- package/{new-rollup.config.mjs → rollup-new.config.mjs} +1 -1
- package/rollup.config.js +14 -15
- package/src/index.ts +23 -49
- 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/lib/socket.io.esm.min.js +0 -7
- package/src/main.ts +0 -26
- package/src/new-index.ts +0 -2478
- 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
|
@@ -1,938 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import {
|
|
3
|
-
BodyAndContentType,
|
|
4
|
-
SessionDescriptionHandler as SessionDescriptionHandlerDefinition,
|
|
5
|
-
SessionDescriptionHandlerModifier
|
|
6
|
-
} from "../../../api";
|
|
7
|
-
import { Logger } from "../../../core";
|
|
8
|
-
import { MediaStreamFactory } from "./media-stream-factory";
|
|
9
|
-
import { SessionDescriptionHandlerConfiguration } from "./session-description-handler-configuration";
|
|
10
|
-
import { SessionDescriptionHandlerOptions } from "./session-description-handler-options";
|
|
11
|
-
import { PeerConnectionDelegate } from "./peer-connection-delegate";
|
|
12
|
-
|
|
13
|
-
type ResolveFunction = () => void;
|
|
14
|
-
type RejectFunction = (reason: Error) => void;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A base class implementing a WebRTC session description handler for sip.js.
|
|
18
|
-
* @remarks
|
|
19
|
-
* It is expected/intended to be extended by specific WebRTC based applications.
|
|
20
|
-
* @privateRemarks
|
|
21
|
-
* So do not put application specific implementation in here.
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
export class SessionDescriptionHandler implements SessionDescriptionHandlerDefinition {
|
|
25
|
-
/** Logger. */
|
|
26
|
-
protected logger: Logger;
|
|
27
|
-
/** Media stream factory. */
|
|
28
|
-
protected mediaStreamFactory: MediaStreamFactory;
|
|
29
|
-
/** Configuration options. */
|
|
30
|
-
protected sessionDescriptionHandlerConfiguration?: SessionDescriptionHandlerConfiguration;
|
|
31
|
-
|
|
32
|
-
/** The local media stream. */
|
|
33
|
-
protected _localMediaStream: MediaStream;
|
|
34
|
-
/** The remote media stream. */
|
|
35
|
-
protected _remoteMediaStream: MediaStream;
|
|
36
|
-
/** The data channel. Undefined before created. */
|
|
37
|
-
protected _dataChannel: RTCDataChannel | undefined;
|
|
38
|
-
/** The peer connection. Undefined after SessionDescriptionHandler.close(). */
|
|
39
|
-
protected _peerConnection: RTCPeerConnection | undefined;
|
|
40
|
-
/** The peer connection delegate. */
|
|
41
|
-
protected _peerConnectionDelegate: PeerConnectionDelegate | undefined;
|
|
42
|
-
|
|
43
|
-
private iceGatheringCompletePromise: Promise<void> | undefined;
|
|
44
|
-
private iceGatheringCompleteTimeoutId: number | undefined;
|
|
45
|
-
private iceGatheringCompleteResolve: ResolveFunction | undefined;
|
|
46
|
-
private iceGatheringCompleteReject: RejectFunction | undefined;
|
|
47
|
-
private localMediaStreamConstraints: MediaStreamConstraints | undefined;
|
|
48
|
-
private onDataChannel: ((dataChannel: RTCDataChannel) => void) | undefined;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Constructor
|
|
52
|
-
* @param logger - A logger
|
|
53
|
-
* @param mediaStreamFactory - A factory to provide a MediaStream
|
|
54
|
-
* @param options - Options passed from the SessionDescriptionHandleFactory
|
|
55
|
-
*/
|
|
56
|
-
constructor(
|
|
57
|
-
logger: Logger,
|
|
58
|
-
mediaStreamFactory: MediaStreamFactory,
|
|
59
|
-
sessionDescriptionHandlerConfiguration?: SessionDescriptionHandlerConfiguration
|
|
60
|
-
) {
|
|
61
|
-
logger.debug("SessionDescriptionHandler.constructor");
|
|
62
|
-
this.logger = logger;
|
|
63
|
-
this.mediaStreamFactory = mediaStreamFactory;
|
|
64
|
-
this.sessionDescriptionHandlerConfiguration = sessionDescriptionHandlerConfiguration;
|
|
65
|
-
this._localMediaStream = new MediaStream();
|
|
66
|
-
this._remoteMediaStream = new MediaStream();
|
|
67
|
-
this._peerConnection = new RTCPeerConnection(sessionDescriptionHandlerConfiguration?.peerConnectionConfiguration);
|
|
68
|
-
this.initPeerConnectionEventHandlers();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* The local media stream currently being sent.
|
|
73
|
-
*
|
|
74
|
-
* @remarks
|
|
75
|
-
* The local media stream initially has no tracks, so the presence of tracks
|
|
76
|
-
* should not be assumed. Furthermore, tracks may be added or removed if the
|
|
77
|
-
* local media changes - for example, on upgrade from audio only to a video session.
|
|
78
|
-
* At any given time there will be at most one audio track and one video track
|
|
79
|
-
* (it's possible that this restriction may not apply to sub-classes).
|
|
80
|
-
* Use `MediaStream.onaddtrack` or add a listener for the `addtrack` event
|
|
81
|
-
* to detect when a new track becomes available:
|
|
82
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/MediaStream/onaddtrack
|
|
83
|
-
*/
|
|
84
|
-
get localMediaStream(): MediaStream {
|
|
85
|
-
return this._localMediaStream;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* The remote media stream currently being received.
|
|
90
|
-
*
|
|
91
|
-
* @remarks
|
|
92
|
-
* The remote media stream initially has no tracks, so the presence of tracks
|
|
93
|
-
* should not be assumed. Furthermore, tracks may be added or removed if the
|
|
94
|
-
* remote media changes - for example, on upgrade from audio only to a video session.
|
|
95
|
-
* At any given time there will be at most one audio track and one video track
|
|
96
|
-
* (it's possible that this restriction may not apply to sub-classes).
|
|
97
|
-
* Use `MediaStream.onaddtrack` or add a listener for the `addtrack` event
|
|
98
|
-
* to detect when a new track becomes available:
|
|
99
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/MediaStream/onaddtrack
|
|
100
|
-
*/
|
|
101
|
-
get remoteMediaStream(): MediaStream {
|
|
102
|
-
return this._remoteMediaStream;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* The data channel. Undefined before it is created.
|
|
107
|
-
*/
|
|
108
|
-
get dataChannel(): RTCDataChannel | undefined {
|
|
109
|
-
return this._dataChannel;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* The peer connection. Undefined if peer connection has closed.
|
|
114
|
-
*
|
|
115
|
-
* @remarks
|
|
116
|
-
* While access to the underlying `RTCPeerConnection` is provided, note that
|
|
117
|
-
* using methods with modify it may break the operation of this class.
|
|
118
|
-
* In particular, this class depends on exclusive access to the
|
|
119
|
-
* event handler properties. If you need access to the peer connection
|
|
120
|
-
* events, either register for events using `addEventListener()` on
|
|
121
|
-
* the `RTCPeerConnection` or set the `peerConnectionDelegate` on
|
|
122
|
-
* this `SessionDescriptionHandler`.
|
|
123
|
-
*/
|
|
124
|
-
get peerConnection(): RTCPeerConnection | undefined {
|
|
125
|
-
return this._peerConnection;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* A delegate which provides access to the peer connection event handlers.
|
|
130
|
-
*
|
|
131
|
-
* @remarks
|
|
132
|
-
* Setting the peer connection event handlers directly is not supported
|
|
133
|
-
* and may break this class. As this class depends on exclusive access
|
|
134
|
-
* to them, a delegate may be set which provides alternative access to
|
|
135
|
-
* the event handlers in a fashion which is supported.
|
|
136
|
-
*/
|
|
137
|
-
get peerConnectionDelegate(): PeerConnectionDelegate | undefined {
|
|
138
|
-
return this._peerConnectionDelegate;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
set peerConnectionDelegate(delegate: PeerConnectionDelegate | undefined) {
|
|
142
|
-
this._peerConnectionDelegate = delegate;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// The addtrack event does not get fired when JavaScript code explicitly adds tracks to the stream (by calling addTrack()).
|
|
146
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/MediaStream/onaddtrack
|
|
147
|
-
private static dispatchAddTrackEvent(stream: MediaStream, track: MediaStreamTrack): void {
|
|
148
|
-
stream.dispatchEvent(new MediaStreamTrackEvent("addtrack", { track }));
|
|
149
|
-
}
|
|
150
|
-
// The removetrack event does not get fired when JavaScript code explicitly removes tracks from the stream (by calling removeTrack()).
|
|
151
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/MediaStream/onremovetrack
|
|
152
|
-
private static dispatchRemoveTrackEvent(stream: MediaStream, track: MediaStreamTrack): void {
|
|
153
|
-
stream.dispatchEvent(new MediaStreamTrackEvent("removetrack", { track }));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Stop tracks and close peer connection.
|
|
158
|
-
*/
|
|
159
|
-
public close(): void {
|
|
160
|
-
this.logger.debug("SessionDescriptionHandler.close");
|
|
161
|
-
if (this._peerConnection === undefined) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
this._peerConnection.getReceivers().forEach((receiver) => {
|
|
165
|
-
receiver.track && receiver.track.stop();
|
|
166
|
-
});
|
|
167
|
-
this._peerConnection.getSenders().forEach((sender) => {
|
|
168
|
-
sender.track && sender.track.stop();
|
|
169
|
-
});
|
|
170
|
-
if (this._dataChannel) {
|
|
171
|
-
this._dataChannel.close();
|
|
172
|
-
}
|
|
173
|
-
this._peerConnection.close();
|
|
174
|
-
this._peerConnection = undefined;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Creates an offer or answer.
|
|
179
|
-
* @param options - Options bucket.
|
|
180
|
-
* @param modifiers - Modifiers.
|
|
181
|
-
*/
|
|
182
|
-
public getDescription(
|
|
183
|
-
options?: SessionDescriptionHandlerOptions,
|
|
184
|
-
modifiers?: Array<SessionDescriptionHandlerModifier>
|
|
185
|
-
): Promise<BodyAndContentType> {
|
|
186
|
-
this.logger.debug("SessionDescriptionHandler.getDescription");
|
|
187
|
-
if (this._peerConnection === undefined) {
|
|
188
|
-
return Promise.reject(new Error("Peer connection closed."));
|
|
189
|
-
}
|
|
190
|
-
// Callback on data channel creation
|
|
191
|
-
this.onDataChannel = options?.onDataChannel;
|
|
192
|
-
|
|
193
|
-
// ICE will restart upon applying an offer created with the iceRestart option
|
|
194
|
-
const iceRestart = options?.offerOptions?.iceRestart;
|
|
195
|
-
|
|
196
|
-
// ICE gathering timeout may be set on a per call basis, otherwise the configured default is used
|
|
197
|
-
const iceTimeout =
|
|
198
|
-
options?.iceGatheringTimeout === undefined
|
|
199
|
-
? this.sessionDescriptionHandlerConfiguration?.iceGatheringTimeout
|
|
200
|
-
: options?.iceGatheringTimeout;
|
|
201
|
-
|
|
202
|
-
return this.getLocalMediaStream(options)
|
|
203
|
-
.then(() => this.updateDirection(options))
|
|
204
|
-
.then(() => this.createDataChannel(options))
|
|
205
|
-
.then(() => this.createLocalOfferOrAnswer(options))
|
|
206
|
-
.then((sessionDescription) => this.applyModifiers(sessionDescription, modifiers))
|
|
207
|
-
.then((sessionDescription) => this.setLocalSessionDescription(sessionDescription))
|
|
208
|
-
.then(() => this.waitForIceGatheringComplete(iceRestart, iceTimeout))
|
|
209
|
-
.then(() => this.getLocalSessionDescription())
|
|
210
|
-
.then((sessionDescription) => {
|
|
211
|
-
return {
|
|
212
|
-
body: sessionDescription.sdp,
|
|
213
|
-
contentType: "application/sdp"
|
|
214
|
-
};
|
|
215
|
-
})
|
|
216
|
-
.catch((error) => {
|
|
217
|
-
this.logger.error("SessionDescriptionHandler.getDescription failed - " + error);
|
|
218
|
-
throw error;
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Returns true if the SessionDescriptionHandler can handle the Content-Type described by a SIP message.
|
|
224
|
-
* @param contentType - The content type that is in the SIP Message.
|
|
225
|
-
*/
|
|
226
|
-
public hasDescription(contentType: string): boolean {
|
|
227
|
-
this.logger.debug("SessionDescriptionHandler.hasDescription");
|
|
228
|
-
return contentType === "application/sdp";
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Send DTMF via RTP (RFC 4733).
|
|
233
|
-
* Returns true if DTMF send is successful, false otherwise.
|
|
234
|
-
* @param tones - A string containing DTMF digits.
|
|
235
|
-
* @param options - Options object to be used by sendDtmf.
|
|
236
|
-
*/
|
|
237
|
-
public sendDtmf(tones: string, options?: { duration: number; interToneGap: number }): boolean {
|
|
238
|
-
this.logger.debug("SessionDescriptionHandler.sendDtmf");
|
|
239
|
-
if (this._peerConnection === undefined) {
|
|
240
|
-
this.logger.error("SessionDescriptionHandler.sendDtmf failed - peer connection closed");
|
|
241
|
-
return false;
|
|
242
|
-
}
|
|
243
|
-
const senders = this._peerConnection.getSenders();
|
|
244
|
-
if (senders.length === 0) {
|
|
245
|
-
this.logger.error("SessionDescriptionHandler.sendDtmf failed - no senders");
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
const dtmfSender = senders[0].dtmf;
|
|
249
|
-
if (!dtmfSender) {
|
|
250
|
-
this.logger.error("SessionDescriptionHandler.sendDtmf failed - no DTMF sender");
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
|
-
const duration = options?.duration;
|
|
254
|
-
const interToneGap = options?.interToneGap;
|
|
255
|
-
try {
|
|
256
|
-
dtmfSender.insertDTMF(tones, duration, interToneGap);
|
|
257
|
-
} catch (e) {
|
|
258
|
-
this.logger.error(e);
|
|
259
|
-
return false;
|
|
260
|
-
}
|
|
261
|
-
this.logger.log("SessionDescriptionHandler.sendDtmf sent via RTP: " + tones.toString());
|
|
262
|
-
return true;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Sets an offer or answer.
|
|
267
|
-
* @param sdp - The session description.
|
|
268
|
-
* @param options - Options bucket.
|
|
269
|
-
* @param modifiers - Modifiers.
|
|
270
|
-
*/
|
|
271
|
-
public setDescription(
|
|
272
|
-
sdp: string,
|
|
273
|
-
options?: SessionDescriptionHandlerOptions,
|
|
274
|
-
modifiers?: Array<SessionDescriptionHandlerModifier>
|
|
275
|
-
): Promise<void> {
|
|
276
|
-
this.logger.debug("SessionDescriptionHandler.setDescription");
|
|
277
|
-
if (this._peerConnection === undefined) {
|
|
278
|
-
return Promise.reject(new Error("Peer connection closed."));
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Callback on data channel creation
|
|
282
|
-
this.onDataChannel = options?.onDataChannel;
|
|
283
|
-
|
|
284
|
-
// SDP type
|
|
285
|
-
const type = this._peerConnection.signalingState === "have-local-offer" ? "answer" : "offer";
|
|
286
|
-
|
|
287
|
-
return this.getLocalMediaStream(options)
|
|
288
|
-
.then(() => this.applyModifiers({ sdp, type }, modifiers))
|
|
289
|
-
.then((sessionDescription) => this.setRemoteSessionDescription(sessionDescription))
|
|
290
|
-
.catch((error) => {
|
|
291
|
-
this.logger.error("SessionDescriptionHandler.setDescription failed - " + error);
|
|
292
|
-
throw error;
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Applies modifiers to SDP prior to setting the local or remote description.
|
|
298
|
-
* @param sdp - SDP to modify.
|
|
299
|
-
* @param modifiers - Modifiers to apply.
|
|
300
|
-
*/
|
|
301
|
-
protected applyModifiers(
|
|
302
|
-
sdp: RTCSessionDescriptionInit,
|
|
303
|
-
modifiers?: Array<SessionDescriptionHandlerModifier>
|
|
304
|
-
): Promise<RTCSessionDescriptionInit> {
|
|
305
|
-
this.logger.debug("SessionDescriptionHandler.applyModifiers");
|
|
306
|
-
if (!modifiers || modifiers.length === 0) {
|
|
307
|
-
return Promise.resolve(sdp);
|
|
308
|
-
}
|
|
309
|
-
return modifiers
|
|
310
|
-
.reduce((cur, next) => cur.then(next), Promise.resolve(sdp))
|
|
311
|
-
.then((modified) => {
|
|
312
|
-
this.logger.debug("SessionDescriptionHandler.applyModifiers - modified sdp");
|
|
313
|
-
if (!modified.sdp || !modified.type) {
|
|
314
|
-
throw new Error("Invalid SDP.");
|
|
315
|
-
}
|
|
316
|
-
return { sdp: modified.sdp, type: modified.type };
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Create a data channel.
|
|
322
|
-
* @remarks
|
|
323
|
-
* Only creates a data channel if SessionDescriptionHandlerOptions.dataChannel is true.
|
|
324
|
-
* Only creates a data channel if creating a local offer.
|
|
325
|
-
* Only if one does not already exist.
|
|
326
|
-
* @param options - Session description handler options.
|
|
327
|
-
*/
|
|
328
|
-
protected createDataChannel(options?: SessionDescriptionHandlerOptions): Promise<void> {
|
|
329
|
-
if (this._peerConnection === undefined) {
|
|
330
|
-
return Promise.reject(new Error("Peer connection closed."));
|
|
331
|
-
}
|
|
332
|
-
// only create a data channel if requested
|
|
333
|
-
if (options?.dataChannel !== true) {
|
|
334
|
-
return Promise.resolve();
|
|
335
|
-
}
|
|
336
|
-
// do not create a data channel if we already have one
|
|
337
|
-
if (this._dataChannel) {
|
|
338
|
-
return Promise.resolve();
|
|
339
|
-
}
|
|
340
|
-
switch (this._peerConnection.signalingState) {
|
|
341
|
-
case "stable":
|
|
342
|
-
// if we are stable, assume we are creating a local offer so create a data channel
|
|
343
|
-
this.logger.debug("SessionDescriptionHandler.createDataChannel - creating data channel");
|
|
344
|
-
try {
|
|
345
|
-
this._dataChannel = this._peerConnection.createDataChannel(
|
|
346
|
-
options?.dataChannelLabel || "",
|
|
347
|
-
options?.dataChannelOptions
|
|
348
|
-
);
|
|
349
|
-
if (this.onDataChannel) {
|
|
350
|
-
this.onDataChannel(this._dataChannel);
|
|
351
|
-
}
|
|
352
|
-
return Promise.resolve();
|
|
353
|
-
} catch (error) {
|
|
354
|
-
return Promise.reject(error);
|
|
355
|
-
}
|
|
356
|
-
case "have-remote-offer":
|
|
357
|
-
return Promise.resolve();
|
|
358
|
-
case "have-local-offer":
|
|
359
|
-
case "have-local-pranswer":
|
|
360
|
-
case "have-remote-pranswer":
|
|
361
|
-
case "closed":
|
|
362
|
-
default:
|
|
363
|
-
return Promise.reject(new Error("Invalid signaling state " + this._peerConnection.signalingState));
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Depending on current signaling state, create a local offer or answer.
|
|
369
|
-
* @param options - Session description handler options.
|
|
370
|
-
*/
|
|
371
|
-
protected createLocalOfferOrAnswer(options?: SessionDescriptionHandlerOptions): Promise<RTCSessionDescriptionInit> {
|
|
372
|
-
if (this._peerConnection === undefined) {
|
|
373
|
-
return Promise.reject(new Error("Peer connection closed."));
|
|
374
|
-
}
|
|
375
|
-
switch (this._peerConnection.signalingState) {
|
|
376
|
-
case "stable":
|
|
377
|
-
// if we are stable, assume we are creating a local offer
|
|
378
|
-
this.logger.debug("SessionDescriptionHandler.createLocalOfferOrAnswer - creating SDP offer");
|
|
379
|
-
return this._peerConnection.createOffer(options?.offerOptions);
|
|
380
|
-
case "have-remote-offer":
|
|
381
|
-
// if we have a remote offer, assume we are creating a local answer
|
|
382
|
-
this.logger.debug("SessionDescriptionHandler.createLocalOfferOrAnswer - creating SDP answer");
|
|
383
|
-
return this._peerConnection.createAnswer(options?.answerOptions);
|
|
384
|
-
case "have-local-offer":
|
|
385
|
-
case "have-local-pranswer":
|
|
386
|
-
case "have-remote-pranswer":
|
|
387
|
-
case "closed":
|
|
388
|
-
default:
|
|
389
|
-
return Promise.reject(new Error("Invalid signaling state " + this._peerConnection.signalingState));
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Get a media stream from the media stream factory and set the local media stream.
|
|
395
|
-
* @param options - Session description handler options.
|
|
396
|
-
*/
|
|
397
|
-
protected getLocalMediaStream(options?: SessionDescriptionHandlerOptions): Promise<void> {
|
|
398
|
-
this.logger.debug("SessionDescriptionHandler.getLocalMediaStream");
|
|
399
|
-
if (this._peerConnection === undefined) {
|
|
400
|
-
return Promise.reject(new Error("Peer connection closed."));
|
|
401
|
-
}
|
|
402
|
-
let constraints: MediaStreamConstraints = { ...options?.constraints };
|
|
403
|
-
|
|
404
|
-
// if we already have a local media stream...
|
|
405
|
-
if (this.localMediaStreamConstraints) {
|
|
406
|
-
// ignore constraint "downgrades"
|
|
407
|
-
constraints.audio = constraints.audio || this.localMediaStreamConstraints.audio;
|
|
408
|
-
constraints.video = constraints.video || this.localMediaStreamConstraints.video;
|
|
409
|
-
|
|
410
|
-
// if constraints have not changed, do not get a new media stream
|
|
411
|
-
if (
|
|
412
|
-
JSON.stringify(this.localMediaStreamConstraints.audio) === JSON.stringify(constraints.audio) &&
|
|
413
|
-
JSON.stringify(this.localMediaStreamConstraints.video) === JSON.stringify(constraints.video)
|
|
414
|
-
) {
|
|
415
|
-
return Promise.resolve();
|
|
416
|
-
}
|
|
417
|
-
} else {
|
|
418
|
-
// if no constraints have been specified, default to audio for initial media stream
|
|
419
|
-
if (constraints.audio === undefined && constraints.video === undefined) {
|
|
420
|
-
constraints = { audio: true };
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
this.localMediaStreamConstraints = constraints;
|
|
425
|
-
return this.mediaStreamFactory(constraints, this).then((mediaStream) => this.setLocalMediaStream(mediaStream));
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Sets the peer connection's sender tracks and local media stream tracks.
|
|
430
|
-
*
|
|
431
|
-
* @remarks
|
|
432
|
-
* Only the first audio and video tracks of the provided MediaStream are utilized.
|
|
433
|
-
* Adds tracks if audio and/or video tracks are not already present, otherwise replaces tracks.
|
|
434
|
-
*
|
|
435
|
-
* @param stream - Media stream containing tracks to be utilized.
|
|
436
|
-
*/
|
|
437
|
-
protected setLocalMediaStream(stream: MediaStream): Promise<void> {
|
|
438
|
-
this.logger.debug("SessionDescriptionHandler.setLocalMediaStream");
|
|
439
|
-
|
|
440
|
-
if (!this._peerConnection) {
|
|
441
|
-
throw new Error("Peer connection undefined.");
|
|
442
|
-
}
|
|
443
|
-
const pc = this._peerConnection;
|
|
444
|
-
|
|
445
|
-
const localStream = this._localMediaStream;
|
|
446
|
-
|
|
447
|
-
const trackUpdates: Array<Promise<void>> = [];
|
|
448
|
-
|
|
449
|
-
const updateTrack = (newTrack: MediaStreamTrack): void => {
|
|
450
|
-
const kind = newTrack.kind;
|
|
451
|
-
if (kind !== "audio" && kind !== "video") {
|
|
452
|
-
throw new Error(`Unknown new track kind ${kind}.`);
|
|
453
|
-
}
|
|
454
|
-
const sender = pc.getSenders().find((sender) => sender.track && sender.track.kind === kind);
|
|
455
|
-
if (sender) {
|
|
456
|
-
trackUpdates.push(
|
|
457
|
-
new Promise<void>((resolve) => {
|
|
458
|
-
this.logger.debug(`SessionDescriptionHandler.setLocalMediaStream - replacing sender ${kind} track`);
|
|
459
|
-
resolve();
|
|
460
|
-
}).then(() =>
|
|
461
|
-
sender
|
|
462
|
-
.replaceTrack(newTrack)
|
|
463
|
-
.then(() => {
|
|
464
|
-
const oldTrack = localStream.getTracks().find((localTrack) => localTrack.kind === kind);
|
|
465
|
-
if (oldTrack) {
|
|
466
|
-
oldTrack.stop();
|
|
467
|
-
localStream.removeTrack(oldTrack);
|
|
468
|
-
SessionDescriptionHandler.dispatchRemoveTrackEvent(localStream, oldTrack);
|
|
469
|
-
}
|
|
470
|
-
localStream.addTrack(newTrack);
|
|
471
|
-
SessionDescriptionHandler.dispatchAddTrackEvent(localStream, newTrack);
|
|
472
|
-
})
|
|
473
|
-
.catch((error: Error) => {
|
|
474
|
-
this.logger.error(
|
|
475
|
-
`SessionDescriptionHandler.setLocalMediaStream - failed to replace sender ${kind} track`
|
|
476
|
-
);
|
|
477
|
-
throw error;
|
|
478
|
-
})
|
|
479
|
-
)
|
|
480
|
-
);
|
|
481
|
-
} else {
|
|
482
|
-
trackUpdates.push(
|
|
483
|
-
new Promise<void>((resolve) => {
|
|
484
|
-
this.logger.debug(`SessionDescriptionHandler.setLocalMediaStream - adding sender ${kind} track`);
|
|
485
|
-
resolve();
|
|
486
|
-
}).then(() => {
|
|
487
|
-
// Review: could make streamless tracks a configurable option?
|
|
488
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addTrack#Usage_notes
|
|
489
|
-
try {
|
|
490
|
-
pc.addTrack(newTrack, localStream);
|
|
491
|
-
} catch (error) {
|
|
492
|
-
this.logger.error(`SessionDescriptionHandler.setLocalMediaStream - failed to add sender ${kind} track`);
|
|
493
|
-
throw error;
|
|
494
|
-
}
|
|
495
|
-
localStream.addTrack(newTrack);
|
|
496
|
-
SessionDescriptionHandler.dispatchAddTrackEvent(localStream, newTrack);
|
|
497
|
-
})
|
|
498
|
-
);
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
// update peer connection audio tracks
|
|
503
|
-
const audioTracks = stream.getAudioTracks();
|
|
504
|
-
if (audioTracks.length) {
|
|
505
|
-
updateTrack(audioTracks[0]);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
// update peer connection video tracks
|
|
509
|
-
const videoTracks = stream.getVideoTracks();
|
|
510
|
-
if (videoTracks.length) {
|
|
511
|
-
updateTrack(videoTracks[0]);
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
return trackUpdates.reduce((p, x) => p.then(() => x), Promise.resolve());
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Gets the peer connection's local session description.
|
|
519
|
-
*/
|
|
520
|
-
protected getLocalSessionDescription(): Promise<RTCSessionDescription> {
|
|
521
|
-
this.logger.debug("SessionDescriptionHandler.getLocalSessionDescription");
|
|
522
|
-
if (this._peerConnection === undefined) {
|
|
523
|
-
return Promise.reject(new Error("Peer connection closed."));
|
|
524
|
-
}
|
|
525
|
-
const sdp = this._peerConnection.localDescription;
|
|
526
|
-
if (!sdp) {
|
|
527
|
-
return Promise.reject(new Error("Failed to get local session description"));
|
|
528
|
-
}
|
|
529
|
-
return Promise.resolve(sdp);
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* Sets the peer connection's local session description.
|
|
534
|
-
* @param sessionDescription - sessionDescription The session description.
|
|
535
|
-
*/
|
|
536
|
-
protected setLocalSessionDescription(sessionDescription: RTCSessionDescriptionInit): Promise<void> {
|
|
537
|
-
this.logger.debug("SessionDescriptionHandler.setLocalSessionDescription");
|
|
538
|
-
if (this._peerConnection === undefined) {
|
|
539
|
-
return Promise.reject(new Error("Peer connection closed."));
|
|
540
|
-
}
|
|
541
|
-
return this._peerConnection.setLocalDescription(sessionDescription);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Sets the peer connection's remote session description.
|
|
546
|
-
* @param sessionDescription - The session description.
|
|
547
|
-
*/
|
|
548
|
-
protected setRemoteSessionDescription(sessionDescription: RTCSessionDescriptionInit): Promise<void> {
|
|
549
|
-
this.logger.debug("SessionDescriptionHandler.setRemoteSessionDescription");
|
|
550
|
-
if (this._peerConnection === undefined) {
|
|
551
|
-
return Promise.reject(new Error("Peer connection closed."));
|
|
552
|
-
}
|
|
553
|
-
const sdp = sessionDescription.sdp;
|
|
554
|
-
let type: RTCSdpType;
|
|
555
|
-
switch (this._peerConnection.signalingState) {
|
|
556
|
-
case "stable":
|
|
557
|
-
// if we are stable assume this is a remote offer
|
|
558
|
-
type = "offer";
|
|
559
|
-
break;
|
|
560
|
-
case "have-local-offer":
|
|
561
|
-
// if we made an offer, assume this is a remote answer
|
|
562
|
-
type = "answer";
|
|
563
|
-
break;
|
|
564
|
-
case "have-local-pranswer":
|
|
565
|
-
case "have-remote-offer":
|
|
566
|
-
case "have-remote-pranswer":
|
|
567
|
-
case "closed":
|
|
568
|
-
default:
|
|
569
|
-
return Promise.reject(new Error("Invalid signaling state " + this._peerConnection.signalingState));
|
|
570
|
-
}
|
|
571
|
-
if (!sdp) {
|
|
572
|
-
this.logger.error("SessionDescriptionHandler.setRemoteSessionDescription failed - cannot set null sdp");
|
|
573
|
-
return Promise.reject(new Error("SDP is undefined"));
|
|
574
|
-
}
|
|
575
|
-
return this._peerConnection.setRemoteDescription({ sdp, type });
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
/**
|
|
579
|
-
* Sets a remote media stream track.
|
|
580
|
-
*
|
|
581
|
-
* @remarks
|
|
582
|
-
* Adds tracks if audio and/or video tracks are not already present, otherwise replaces tracks.
|
|
583
|
-
*
|
|
584
|
-
* @param track - Media stream track to be utilized.
|
|
585
|
-
*/
|
|
586
|
-
protected setRemoteTrack(track: MediaStreamTrack): void {
|
|
587
|
-
this.logger.debug("SessionDescriptionHandler.setRemoteTrack");
|
|
588
|
-
|
|
589
|
-
const remoteStream = this._remoteMediaStream;
|
|
590
|
-
|
|
591
|
-
if (remoteStream.getTrackById(track.id)) {
|
|
592
|
-
this.logger.debug(`SessionDescriptionHandler.setRemoteTrack - have remote ${track.kind} track`);
|
|
593
|
-
} else if (track.kind === "audio") {
|
|
594
|
-
this.logger.debug(`SessionDescriptionHandler.setRemoteTrack - adding remote ${track.kind} track`);
|
|
595
|
-
remoteStream.getAudioTracks().forEach((track) => {
|
|
596
|
-
track.stop();
|
|
597
|
-
remoteStream.removeTrack(track);
|
|
598
|
-
SessionDescriptionHandler.dispatchRemoveTrackEvent(remoteStream, track);
|
|
599
|
-
});
|
|
600
|
-
remoteStream.addTrack(track);
|
|
601
|
-
SessionDescriptionHandler.dispatchAddTrackEvent(remoteStream, track);
|
|
602
|
-
} else if (track.kind === "video") {
|
|
603
|
-
this.logger.debug(`SessionDescriptionHandler.setRemoteTrack - adding remote ${track.kind} track`);
|
|
604
|
-
remoteStream.getVideoTracks().forEach((track) => {
|
|
605
|
-
track.stop();
|
|
606
|
-
remoteStream.removeTrack(track);
|
|
607
|
-
SessionDescriptionHandler.dispatchRemoveTrackEvent(remoteStream, track);
|
|
608
|
-
});
|
|
609
|
-
remoteStream.addTrack(track);
|
|
610
|
-
SessionDescriptionHandler.dispatchAddTrackEvent(remoteStream, track);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
/**
|
|
615
|
-
* Depending on the current signaling state and the session hold state, update transceiver direction.
|
|
616
|
-
* @param options - Session description handler options.
|
|
617
|
-
*/
|
|
618
|
-
protected updateDirection(options?: SessionDescriptionHandlerOptions): Promise<void> {
|
|
619
|
-
if (this._peerConnection === undefined) {
|
|
620
|
-
return Promise.reject(new Error("Peer connection closed."));
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
// 4.2.3. setDirection
|
|
624
|
-
//
|
|
625
|
-
// The setDirection method sets the direction of a transceiver, which
|
|
626
|
-
// affects the direction property of the associated "m=" section on
|
|
627
|
-
// future calls to createOffer and createAnswer. The permitted values
|
|
628
|
-
// for direction are "recvonly", "sendrecv", "sendonly", and "inactive",
|
|
629
|
-
// mirroring the identically named direction attributes defined in
|
|
630
|
-
// [RFC4566], Section 6.
|
|
631
|
-
//
|
|
632
|
-
// When creating offers, the transceiver direction is directly reflected
|
|
633
|
-
// in the output, even for re-offers. When creating answers, the
|
|
634
|
-
// transceiver direction is intersected with the offered direction, as
|
|
635
|
-
// explained in Section 5.3 below.
|
|
636
|
-
//
|
|
637
|
-
// Note that while setDirection sets the direction property of the
|
|
638
|
-
// transceiver immediately (Section 4.2.4), this property does not
|
|
639
|
-
// immediately affect whether the transceiver's RtpSender will send or
|
|
640
|
-
// its RtpReceiver will receive. The direction in effect is represented
|
|
641
|
-
// by the currentDirection property, which is only updated when an
|
|
642
|
-
// answer is applied.
|
|
643
|
-
//
|
|
644
|
-
// 4.2.4. direction
|
|
645
|
-
//
|
|
646
|
-
// The direction property indicates the last value passed into
|
|
647
|
-
// setDirection. If setDirection has never been called, it is set to
|
|
648
|
-
// the direction the transceiver was initialized with.
|
|
649
|
-
//
|
|
650
|
-
// 4.2.5. currentDirection
|
|
651
|
-
//
|
|
652
|
-
// The currentDirection property indicates the last negotiated direction
|
|
653
|
-
// for the transceiver's associated "m=" section. More specifically, it
|
|
654
|
-
// indicates the direction attribute [RFC3264] of the associated "m="
|
|
655
|
-
// section in the last applied answer (including provisional answers),
|
|
656
|
-
// with "send" and "recv" directions reversed if it was a remote answer.
|
|
657
|
-
// For example, if the direction attribute for the associated "m="
|
|
658
|
-
// section in a remote answer is "recvonly", currentDirection is set to
|
|
659
|
-
// "sendonly".
|
|
660
|
-
//
|
|
661
|
-
// If an answer that references this transceiver has not yet been
|
|
662
|
-
// applied or if the transceiver is stopped, currentDirection is set to
|
|
663
|
-
// "null".
|
|
664
|
-
// https://tools.ietf.org/html/rfc8829#section-4.2.3
|
|
665
|
-
//
|
|
666
|
-
// * A direction attribute, determined by applying the rules regarding
|
|
667
|
-
// the offered direction specified in [RFC3264], Section 6.1, and
|
|
668
|
-
// then intersecting with the direction of the associated
|
|
669
|
-
// RtpTransceiver. For example, in the case where an "m=" section is
|
|
670
|
-
// offered as "sendonly" and the local transceiver is set to
|
|
671
|
-
// "sendrecv", the result in the answer is a "recvonly" direction.
|
|
672
|
-
// https://tools.ietf.org/html/rfc8829#section-5.3.1
|
|
673
|
-
//
|
|
674
|
-
// If a stream is offered as sendonly, the corresponding stream MUST be
|
|
675
|
-
// marked as recvonly or inactive in the answer. If a media stream is
|
|
676
|
-
// listed as recvonly in the offer, the answer MUST be marked as
|
|
677
|
-
// sendonly or inactive in the answer. If an offered media stream is
|
|
678
|
-
// listed as sendrecv (or if there is no direction attribute at the
|
|
679
|
-
// media or session level, in which case the stream is sendrecv by
|
|
680
|
-
// default), the corresponding stream in the answer MAY be marked as
|
|
681
|
-
// sendonly, recvonly, sendrecv, or inactive. If an offered media
|
|
682
|
-
// stream is listed as inactive, it MUST be marked as inactive in the
|
|
683
|
-
// answer.
|
|
684
|
-
// https://tools.ietf.org/html/rfc3264#section-6.1
|
|
685
|
-
|
|
686
|
-
switch (this._peerConnection.signalingState) {
|
|
687
|
-
case "stable":
|
|
688
|
-
// if we are stable, assume we are creating a local offer
|
|
689
|
-
this.logger.debug("SessionDescriptionHandler.updateDirection - setting offer direction");
|
|
690
|
-
{
|
|
691
|
-
// determine the direction to offer given the current direction and hold state
|
|
692
|
-
const directionToOffer = (currentDirection: RTCRtpTransceiverDirection): RTCRtpTransceiverDirection => {
|
|
693
|
-
switch (currentDirection) {
|
|
694
|
-
case "inactive":
|
|
695
|
-
return options?.hold ? "inactive" : "recvonly";
|
|
696
|
-
case "recvonly":
|
|
697
|
-
return options?.hold ? "inactive" : "recvonly";
|
|
698
|
-
case "sendonly":
|
|
699
|
-
return options?.hold ? "sendonly" : "sendrecv";
|
|
700
|
-
case "sendrecv":
|
|
701
|
-
return options?.hold ? "sendonly" : "sendrecv";
|
|
702
|
-
case "stopped":
|
|
703
|
-
return "stopped";
|
|
704
|
-
default:
|
|
705
|
-
throw new Error("Should never happen");
|
|
706
|
-
}
|
|
707
|
-
};
|
|
708
|
-
// set the transceiver direction to the offer direction
|
|
709
|
-
this._peerConnection.getTransceivers().forEach((transceiver) => {
|
|
710
|
-
if (transceiver.direction /* guarding, but should always be true */) {
|
|
711
|
-
const offerDirection = directionToOffer(transceiver.direction);
|
|
712
|
-
if (transceiver.direction !== offerDirection) {
|
|
713
|
-
transceiver.direction = offerDirection;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
break;
|
|
719
|
-
case "have-remote-offer":
|
|
720
|
-
// if we have a remote offer, assume we are creating a local answer
|
|
721
|
-
this.logger.debug("SessionDescriptionHandler.updateDirection - setting answer direction");
|
|
722
|
-
|
|
723
|
-
// FIXME: This is not the correct way to determine the answer direction as it is only
|
|
724
|
-
// considering first match in the offered SDP and using that to determine the answer direction.
|
|
725
|
-
// While that may be fine for our current use cases, it is not a generally correct approach.
|
|
726
|
-
{
|
|
727
|
-
// determine the offered direction
|
|
728
|
-
const offeredDirection = ((): "inactive" | "recvonly" | "sendonly" | "sendrecv" => {
|
|
729
|
-
const description = this._peerConnection.remoteDescription;
|
|
730
|
-
if (!description) {
|
|
731
|
-
throw new Error("Failed to read remote offer");
|
|
732
|
-
}
|
|
733
|
-
const searchResult = /a=sendrecv\r\n|a=sendonly\r\n|a=recvonly\r\n|a=inactive\r\n/.exec(description.sdp);
|
|
734
|
-
if (searchResult) {
|
|
735
|
-
switch (searchResult[0]) {
|
|
736
|
-
case "a=inactive\r\n":
|
|
737
|
-
return "inactive";
|
|
738
|
-
case "a=recvonly\r\n":
|
|
739
|
-
return "recvonly";
|
|
740
|
-
case "a=sendonly\r\n":
|
|
741
|
-
return "sendonly";
|
|
742
|
-
case "a=sendrecv\r\n":
|
|
743
|
-
return "sendrecv";
|
|
744
|
-
default:
|
|
745
|
-
throw new Error("Should never happen");
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
return "sendrecv";
|
|
749
|
-
})();
|
|
750
|
-
|
|
751
|
-
// determine the answer direction based on the offered direction and our hold state
|
|
752
|
-
const answerDirection = ((): "inactive" | "recvonly" | "sendonly" | "sendrecv" => {
|
|
753
|
-
switch (offeredDirection) {
|
|
754
|
-
case "inactive":
|
|
755
|
-
return "inactive";
|
|
756
|
-
case "recvonly":
|
|
757
|
-
return "sendonly";
|
|
758
|
-
case "sendonly":
|
|
759
|
-
return options?.hold ? "inactive" : "recvonly";
|
|
760
|
-
case "sendrecv":
|
|
761
|
-
return options?.hold ? "sendonly" : "sendrecv";
|
|
762
|
-
default:
|
|
763
|
-
throw new Error("Should never happen");
|
|
764
|
-
}
|
|
765
|
-
})();
|
|
766
|
-
|
|
767
|
-
// set the transceiver direction to the answer direction
|
|
768
|
-
this._peerConnection.getTransceivers().forEach((transceiver) => {
|
|
769
|
-
if (transceiver.direction /* guarding, but should always be true */) {
|
|
770
|
-
if (transceiver.direction !== "stopped" && transceiver.direction !== answerDirection) {
|
|
771
|
-
transceiver.direction = answerDirection;
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
});
|
|
775
|
-
}
|
|
776
|
-
break;
|
|
777
|
-
case "have-local-offer":
|
|
778
|
-
case "have-local-pranswer":
|
|
779
|
-
case "have-remote-pranswer":
|
|
780
|
-
case "closed":
|
|
781
|
-
default:
|
|
782
|
-
return Promise.reject(new Error("Invalid signaling state " + this._peerConnection.signalingState));
|
|
783
|
-
}
|
|
784
|
-
return Promise.resolve();
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
/**
|
|
788
|
-
* Called when ICE gathering completes and resolves any waiting promise.
|
|
789
|
-
*/
|
|
790
|
-
protected iceGatheringComplete(): void {
|
|
791
|
-
this.logger.debug("SessionDescriptionHandler.iceGatheringComplete");
|
|
792
|
-
// clear timer if need be
|
|
793
|
-
if (this.iceGatheringCompleteTimeoutId !== undefined) {
|
|
794
|
-
this.logger.debug("SessionDescriptionHandler.iceGatheringComplete - clearing timeout");
|
|
795
|
-
clearTimeout(this.iceGatheringCompleteTimeoutId);
|
|
796
|
-
this.iceGatheringCompleteTimeoutId = undefined;
|
|
797
|
-
}
|
|
798
|
-
// resolve and cleanup promise if need be
|
|
799
|
-
if (this.iceGatheringCompletePromise !== undefined) {
|
|
800
|
-
this.logger.debug("SessionDescriptionHandler.iceGatheringComplete - resolving promise");
|
|
801
|
-
this.iceGatheringCompleteResolve && this.iceGatheringCompleteResolve();
|
|
802
|
-
this.iceGatheringCompletePromise = undefined;
|
|
803
|
-
this.iceGatheringCompleteResolve = undefined;
|
|
804
|
-
this.iceGatheringCompleteReject = undefined;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
/**
|
|
809
|
-
* Wait for ICE gathering to complete.
|
|
810
|
-
* @param restart - If true, waits if current state is "complete" (waits for transition to "complete").
|
|
811
|
-
* @param timeout - Milliseconds after which waiting times out. No timeout if 0.
|
|
812
|
-
*/
|
|
813
|
-
protected waitForIceGatheringComplete(restart = false, timeout = 0): Promise<void> {
|
|
814
|
-
this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete");
|
|
815
|
-
if (this._peerConnection === undefined) {
|
|
816
|
-
return Promise.reject("Peer connection closed.");
|
|
817
|
-
}
|
|
818
|
-
// guard already complete
|
|
819
|
-
if (!restart && this._peerConnection.iceGatheringState === "complete") {
|
|
820
|
-
this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - already complete");
|
|
821
|
-
return Promise.resolve();
|
|
822
|
-
}
|
|
823
|
-
// only one may be waiting, reject any prior
|
|
824
|
-
if (this.iceGatheringCompletePromise !== undefined) {
|
|
825
|
-
this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - rejecting prior waiting promise");
|
|
826
|
-
this.iceGatheringCompleteReject && this.iceGatheringCompleteReject(new Error("Promise superseded."));
|
|
827
|
-
this.iceGatheringCompletePromise = undefined;
|
|
828
|
-
this.iceGatheringCompleteResolve = undefined;
|
|
829
|
-
this.iceGatheringCompleteReject = undefined;
|
|
830
|
-
}
|
|
831
|
-
this.iceGatheringCompletePromise = new Promise<void>((resolve, reject) => {
|
|
832
|
-
this.iceGatheringCompleteResolve = resolve;
|
|
833
|
-
this.iceGatheringCompleteReject = reject;
|
|
834
|
-
if (timeout > 0) {
|
|
835
|
-
this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - timeout in " + timeout);
|
|
836
|
-
this.iceGatheringCompleteTimeoutId = window.setTimeout(() => {
|
|
837
|
-
this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - timeout");
|
|
838
|
-
this.iceGatheringComplete();
|
|
839
|
-
}, timeout);
|
|
840
|
-
}
|
|
841
|
-
});
|
|
842
|
-
return this.iceGatheringCompletePromise;
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
/**
|
|
846
|
-
* Initializes the peer connection event handlers
|
|
847
|
-
*/
|
|
848
|
-
private initPeerConnectionEventHandlers(): void {
|
|
849
|
-
this.logger.debug("SessionDescriptionHandler.initPeerConnectionEventHandlers");
|
|
850
|
-
|
|
851
|
-
if (!this._peerConnection) throw new Error("Peer connection undefined.");
|
|
852
|
-
const peerConnection = this._peerConnection;
|
|
853
|
-
|
|
854
|
-
peerConnection.onconnectionstatechange = (event): void => {
|
|
855
|
-
const newState = peerConnection.connectionState;
|
|
856
|
-
this.logger.debug(`SessionDescriptionHandler.onconnectionstatechange ${newState}`);
|
|
857
|
-
if (this._peerConnectionDelegate?.onconnectionstatechange) {
|
|
858
|
-
this._peerConnectionDelegate.onconnectionstatechange(event);
|
|
859
|
-
}
|
|
860
|
-
};
|
|
861
|
-
|
|
862
|
-
peerConnection.ondatachannel = (event): void => {
|
|
863
|
-
this.logger.debug(`SessionDescriptionHandler.ondatachannel`);
|
|
864
|
-
this._dataChannel = event.channel;
|
|
865
|
-
if (this.onDataChannel) {
|
|
866
|
-
this.onDataChannel(this._dataChannel);
|
|
867
|
-
}
|
|
868
|
-
if (this._peerConnectionDelegate?.ondatachannel) {
|
|
869
|
-
this._peerConnectionDelegate.ondatachannel(event);
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
|
-
|
|
873
|
-
peerConnection.onicecandidate = (event): void => {
|
|
874
|
-
this.logger.debug(`SessionDescriptionHandler.onicecandidate`);
|
|
875
|
-
if (this._peerConnectionDelegate?.onicecandidate) {
|
|
876
|
-
this._peerConnectionDelegate.onicecandidate(event);
|
|
877
|
-
}
|
|
878
|
-
};
|
|
879
|
-
|
|
880
|
-
peerConnection.onicecandidateerror = (event): void => {
|
|
881
|
-
this.logger.debug(`SessionDescriptionHandler.onicecandidateerror`);
|
|
882
|
-
if (this._peerConnectionDelegate?.onicecandidateerror) {
|
|
883
|
-
this._peerConnectionDelegate.onicecandidateerror(event);
|
|
884
|
-
}
|
|
885
|
-
};
|
|
886
|
-
|
|
887
|
-
peerConnection.oniceconnectionstatechange = (event): void => {
|
|
888
|
-
const newState = peerConnection.iceConnectionState;
|
|
889
|
-
this.logger.debug(`SessionDescriptionHandler.oniceconnectionstatechange ${newState}`);
|
|
890
|
-
if (this._peerConnectionDelegate?.oniceconnectionstatechange) {
|
|
891
|
-
this._peerConnectionDelegate.oniceconnectionstatechange(event);
|
|
892
|
-
}
|
|
893
|
-
};
|
|
894
|
-
|
|
895
|
-
peerConnection.onicegatheringstatechange = (event): void => {
|
|
896
|
-
const newState = peerConnection.iceGatheringState;
|
|
897
|
-
this.logger.debug(`SessionDescriptionHandler.onicegatheringstatechange ${newState}`);
|
|
898
|
-
if (newState === "complete") {
|
|
899
|
-
this.iceGatheringComplete(); // complete waiting for ICE gathering to complete
|
|
900
|
-
}
|
|
901
|
-
if (this._peerConnectionDelegate?.onicegatheringstatechange) {
|
|
902
|
-
this._peerConnectionDelegate.onicegatheringstatechange(event);
|
|
903
|
-
}
|
|
904
|
-
};
|
|
905
|
-
|
|
906
|
-
peerConnection.onnegotiationneeded = (event): void => {
|
|
907
|
-
this.logger.debug(`SessionDescriptionHandler.onnegotiationneeded`);
|
|
908
|
-
if (this._peerConnectionDelegate?.onnegotiationneeded) {
|
|
909
|
-
this._peerConnectionDelegate.onnegotiationneeded(event);
|
|
910
|
-
}
|
|
911
|
-
};
|
|
912
|
-
|
|
913
|
-
peerConnection.onsignalingstatechange = (event): void => {
|
|
914
|
-
const newState = peerConnection.signalingState;
|
|
915
|
-
this.logger.debug(`SessionDescriptionHandler.onsignalingstatechange ${newState}`);
|
|
916
|
-
if (this._peerConnectionDelegate?.onsignalingstatechange) {
|
|
917
|
-
this._peerConnectionDelegate.onsignalingstatechange(event);
|
|
918
|
-
}
|
|
919
|
-
};
|
|
920
|
-
|
|
921
|
-
peerConnection.onstatsended = (event): void => {
|
|
922
|
-
this.logger.debug(`SessionDescriptionHandler.onstatsended`);
|
|
923
|
-
if (this._peerConnectionDelegate?.onstatsended) {
|
|
924
|
-
this._peerConnectionDelegate.onstatsended(event);
|
|
925
|
-
}
|
|
926
|
-
};
|
|
927
|
-
|
|
928
|
-
peerConnection.ontrack = (event): void => {
|
|
929
|
-
const kind = event.track.kind;
|
|
930
|
-
const enabled = event.track.enabled ? "enabled" : "disabled";
|
|
931
|
-
this.logger.debug(`SessionDescriptionHandler.ontrack ${kind} ${enabled}`);
|
|
932
|
-
this.setRemoteTrack(event.track);
|
|
933
|
-
if (this._peerConnectionDelegate?.ontrack) {
|
|
934
|
-
this._peerConnectionDelegate.ontrack(event);
|
|
935
|
-
}
|
|
936
|
-
};
|
|
937
|
-
}
|
|
938
|
-
}
|