ue-softphone-sdk-beta 4.0.1 → 4.0.2

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