softphone-vendor-headsets 1.0.1 → 2.0.0-develop.11

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 (216) hide show
  1. package/README.md +319 -3
  2. package/dist/1.softhphone-vendor-headsets.js +1 -1
  3. package/dist/1.softhphone-vendor-headsets.js.map +1 -1
  4. package/dist/2.softhphone-vendor-headsets.js +1 -1
  5. package/dist/2.softhphone-vendor-headsets.js.map +1 -1
  6. package/dist/3.softhphone-vendor-headsets.js +1 -1
  7. package/dist/3.softhphone-vendor-headsets.js.map +1 -1
  8. package/dist/cjs/src/config/i18n.js +1 -0
  9. package/dist/cjs/src/config/i18n.js.map +1 -1
  10. package/dist/cjs/src/library/index.d.ts +0 -1
  11. package/dist/cjs/src/library/index.js +5 -2
  12. package/dist/cjs/src/library/index.js.map +1 -1
  13. package/dist/cjs/src/library/services/headset.d.ts +5 -1
  14. package/dist/cjs/src/library/services/headset.js +170 -18
  15. package/dist/cjs/src/library/services/headset.js.map +1 -1
  16. package/dist/cjs/src/library/services/headset.test.js +503 -21
  17. package/dist/cjs/src/library/services/headset.test.js.map +1 -1
  18. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native.d.ts +5 -4
  19. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native.js +75 -54
  20. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native.js.map +1 -1
  21. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native.test.js +72 -62
  22. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native.test.js.map +1 -1
  23. package/dist/{es/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-types.d.ts → cjs/src/library/services/vendor-implementations/jabra/jabra-native/types.d.ts} +10 -0
  24. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/{jabra-native-types.js → types.js} +9 -2
  25. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/types.js.map +1 -0
  26. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra.d.ts +15 -14
  27. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra.js +177 -118
  28. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra.js.map +1 -1
  29. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra.test.js +371 -258
  30. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra.test.js.map +1 -1
  31. package/dist/cjs/src/library/services/vendor-implementations/jabra/mock-jabra-sdk.d.ts +7 -0
  32. package/dist/cjs/src/library/services/vendor-implementations/jabra/mock-jabra-sdk.js +11 -0
  33. package/dist/cjs/src/library/services/vendor-implementations/jabra/mock-jabra-sdk.js.map +1 -0
  34. package/dist/cjs/src/library/services/vendor-implementations/plantronics/plantronics-call-events.d.ts +11 -1
  35. package/dist/cjs/src/library/services/vendor-implementations/plantronics/plantronics-call-events.js +39 -39
  36. package/dist/cjs/src/library/services/vendor-implementations/plantronics/plantronics-call-events.js.map +1 -1
  37. package/dist/cjs/src/library/services/vendor-implementations/plantronics/plantronics-call-events.test.js +35 -35
  38. package/dist/cjs/src/library/services/vendor-implementations/plantronics/plantronics-call-events.test.js.map +1 -1
  39. package/dist/cjs/src/library/services/vendor-implementations/plantronics/plantronics-test-responses.d.ts +101 -9
  40. package/dist/cjs/src/library/services/vendor-implementations/plantronics/plantronics-test-responses.js +168 -51
  41. package/dist/cjs/src/library/services/vendor-implementations/plantronics/plantronics-test-responses.js.map +1 -1
  42. package/dist/cjs/src/library/services/vendor-implementations/plantronics/plantronics.d.ts +6 -2
  43. package/dist/cjs/src/library/services/vendor-implementations/plantronics/plantronics.js +56 -36
  44. package/dist/cjs/src/library/services/vendor-implementations/plantronics/plantronics.js.map +1 -1
  45. package/dist/cjs/src/library/services/vendor-implementations/plantronics/plantronics.test.js +408 -221
  46. package/dist/cjs/src/library/services/vendor-implementations/plantronics/plantronics.test.js.map +1 -1
  47. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/sennheiser.d.ts +1 -3
  48. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/sennheiser.js +61 -87
  49. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/sennheiser.js.map +1 -1
  50. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/sennheiser.test.js +140 -233
  51. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/sennheiser.test.js.map +1 -1
  52. package/dist/{es/src/library/services/vendor-implementations/sennheiser/sennheiser-events.d.ts → cjs/src/library/services/vendor-implementations/sennheiser/types.d.ts} +19 -0
  53. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/{sennheiser-events.js → types.js} +8 -2
  54. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/types.js.map +1 -0
  55. package/dist/cjs/src/library/services/vendor-implementations/vendor-implementation.d.ts +7 -27
  56. package/dist/cjs/src/library/services/vendor-implementations/vendor-implementation.js +6 -6
  57. package/dist/cjs/src/library/services/vendor-implementations/vendor-implementation.js.map +1 -1
  58. package/dist/cjs/src/library/services/vendor-implementations/vendor-implemntation.test.js.map +1 -1
  59. package/dist/{es/src/library/test-utils.test.d.ts → cjs/src/library/test-utils.d.ts} +1 -1
  60. package/dist/cjs/src/library/{test-utils.test.js → test-utils.js} +12 -9
  61. package/dist/cjs/src/library/test-utils.js.map +1 -0
  62. package/dist/cjs/src/library/types/consumed-headset-events.d.ts +8 -22
  63. package/dist/cjs/src/library/types/consumed-headset-events.js +0 -1
  64. package/dist/cjs/src/library/types/consumed-headset-events.js.map +1 -1
  65. package/dist/cjs/src/library/types/emitted-headset-events.d.ts +14 -11
  66. package/dist/cjs/src/library/types/headset-states.d.ts +10 -0
  67. package/dist/cjs/src/library/types/{jabra-request.js → headset-states.js} +1 -1
  68. package/dist/cjs/src/library/types/headset-states.js.map +1 -0
  69. package/dist/cjs/src/library/utils.js.map +1 -1
  70. package/dist/cjs/src/library/utils.test.js +2 -2
  71. package/dist/cjs/src/library/utils.test.js.map +1 -1
  72. package/dist/cjs/src/mocks/call.js +2 -1
  73. package/dist/cjs/src/mocks/call.js.map +1 -1
  74. package/dist/cjs/src/mocks/device-service.js +1 -0
  75. package/dist/cjs/src/mocks/device-service.js.map +1 -1
  76. package/dist/deploy-info.json +33 -195
  77. package/dist/es/src/config/i18n.js +1 -0
  78. package/dist/es/src/config/i18n.js.map +1 -1
  79. package/dist/es/src/library/index.d.ts +0 -1
  80. package/dist/es/src/library/index.js +0 -1
  81. package/dist/es/src/library/index.js.map +1 -1
  82. package/dist/es/src/library/services/headset.d.ts +5 -1
  83. package/dist/es/src/library/services/headset.js +170 -18
  84. package/dist/es/src/library/services/headset.js.map +1 -1
  85. package/dist/es/src/library/services/headset.test.js +503 -21
  86. package/dist/es/src/library/services/headset.test.js.map +1 -1
  87. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native.d.ts +5 -4
  88. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native.js +60 -39
  89. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native.js.map +1 -1
  90. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native.test.js +20 -14
  91. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native.test.js.map +1 -1
  92. package/dist/{cjs/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-types.d.ts → es/src/library/services/vendor-implementations/jabra/jabra-native/types.d.ts} +10 -0
  93. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/{jabra-native-types.js → types.js} +8 -1
  94. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/types.js.map +1 -0
  95. package/dist/es/src/library/services/vendor-implementations/jabra/jabra.d.ts +15 -14
  96. package/dist/es/src/library/services/vendor-implementations/jabra/jabra.js +181 -122
  97. package/dist/es/src/library/services/vendor-implementations/jabra/jabra.js.map +1 -1
  98. package/dist/es/src/library/services/vendor-implementations/jabra/jabra.test.js +373 -260
  99. package/dist/es/src/library/services/vendor-implementations/jabra/jabra.test.js.map +1 -1
  100. package/dist/es/src/library/services/vendor-implementations/jabra/mock-jabra-sdk.d.ts +7 -0
  101. package/dist/es/src/library/services/vendor-implementations/jabra/mock-jabra-sdk.js +7 -0
  102. package/dist/es/src/library/services/vendor-implementations/jabra/mock-jabra-sdk.js.map +1 -0
  103. package/dist/es/src/library/services/vendor-implementations/plantronics/plantronics-call-events.d.ts +11 -1
  104. package/dist/es/src/library/services/vendor-implementations/plantronics/plantronics-call-events.js +38 -38
  105. package/dist/es/src/library/services/vendor-implementations/plantronics/plantronics-call-events.js.map +1 -1
  106. package/dist/es/src/library/services/vendor-implementations/plantronics/plantronics-call-events.test.js +36 -36
  107. package/dist/es/src/library/services/vendor-implementations/plantronics/plantronics-call-events.test.js.map +1 -1
  108. package/dist/es/src/library/services/vendor-implementations/plantronics/plantronics-test-responses.d.ts +101 -9
  109. package/dist/es/src/library/services/vendor-implementations/plantronics/plantronics-test-responses.js +169 -52
  110. package/dist/es/src/library/services/vendor-implementations/plantronics/plantronics-test-responses.js.map +1 -1
  111. package/dist/es/src/library/services/vendor-implementations/plantronics/plantronics.d.ts +6 -2
  112. package/dist/es/src/library/services/vendor-implementations/plantronics/plantronics.js +56 -36
  113. package/dist/es/src/library/services/vendor-implementations/plantronics/plantronics.js.map +1 -1
  114. package/dist/es/src/library/services/vendor-implementations/plantronics/plantronics.test.js +403 -216
  115. package/dist/es/src/library/services/vendor-implementations/plantronics/plantronics.test.js.map +1 -1
  116. package/dist/es/src/library/services/vendor-implementations/sennheiser/sennheiser.d.ts +1 -3
  117. package/dist/es/src/library/services/vendor-implementations/sennheiser/sennheiser.js +16 -46
  118. package/dist/es/src/library/services/vendor-implementations/sennheiser/sennheiser.js.map +1 -1
  119. package/dist/es/src/library/services/vendor-implementations/sennheiser/sennheiser.test.js +37 -134
  120. package/dist/es/src/library/services/vendor-implementations/sennheiser/sennheiser.test.js.map +1 -1
  121. package/dist/{cjs/src/library/services/vendor-implementations/sennheiser/sennheiser-events.d.ts → es/src/library/services/vendor-implementations/sennheiser/types.d.ts} +19 -0
  122. package/dist/es/src/library/services/vendor-implementations/sennheiser/{sennheiser-events.js → types.js} +7 -1
  123. package/dist/es/src/library/services/vendor-implementations/sennheiser/types.js.map +1 -0
  124. package/dist/es/src/library/services/vendor-implementations/vendor-implementation.d.ts +7 -27
  125. package/dist/es/src/library/services/vendor-implementations/vendor-implementation.js +6 -6
  126. package/dist/es/src/library/services/vendor-implementations/vendor-implementation.js.map +1 -1
  127. package/dist/es/src/library/services/vendor-implementations/vendor-implemntation.test.js.map +1 -1
  128. package/dist/{cjs/src/library/test-utils.test.d.ts → es/src/library/test-utils.d.ts} +1 -1
  129. package/dist/es/src/library/{test-utils.test.js → test-utils.js} +10 -8
  130. package/dist/es/src/library/test-utils.js.map +1 -0
  131. package/dist/es/src/library/types/consumed-headset-events.d.ts +8 -22
  132. package/dist/es/src/library/types/consumed-headset-events.js +0 -1
  133. package/dist/es/src/library/types/consumed-headset-events.js.map +1 -1
  134. package/dist/es/src/library/types/emitted-headset-events.d.ts +14 -11
  135. package/dist/es/src/library/types/headset-states.d.ts +10 -0
  136. package/dist/es/src/library/types/headset-states.js +2 -0
  137. package/dist/es/src/library/types/headset-states.js.map +1 -0
  138. package/dist/es/src/library/utils.js.map +1 -1
  139. package/dist/es/src/mocks/call.js +1 -0
  140. package/dist/es/src/mocks/call.js.map +1 -1
  141. package/dist/es/src/mocks/device-service.js +1 -0
  142. package/dist/es/src/mocks/device-service.js.map +1 -1
  143. package/dist/softhphone-vendor-headsets.js +4 -19
  144. package/dist/softhphone-vendor-headsets.js.map +1 -1
  145. package/package.json +82 -88
  146. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-commands.d.ts +0 -13
  147. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-commands.js +0 -18
  148. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-commands.js.map +0 -1
  149. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-event-translation.d.ts +0 -12
  150. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-event-translation.js +0 -16
  151. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-event-translation.js.map +0 -1
  152. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-requested-events.d.ts +0 -5
  153. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-requested-events.js +0 -10
  154. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-requested-events.js.map +0 -1
  155. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome.d.ts +0 -38
  156. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome.js +0 -251
  157. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome.js.map +0 -1
  158. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome.test.d.ts +0 -1
  159. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome.test.js +0 -573
  160. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome.test.js.map +0 -1
  161. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-commands.d.ts +0 -13
  162. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-commands.js +0 -18
  163. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-commands.js.map +0 -1
  164. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-commands.d.ts +0 -6
  165. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-commands.js +0 -11
  166. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-commands.js.map +0 -1
  167. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-heaset-state.d.ts +0 -4
  168. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-heaset-state.js +0 -3
  169. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-heaset-state.js.map +0 -1
  170. package/dist/cjs/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-types.js.map +0 -1
  171. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/sennheiser-event-types.d.ts +0 -5
  172. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/sennheiser-event-types.js +0 -10
  173. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/sennheiser-event-types.js.map +0 -1
  174. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/sennheiser-events.js.map +0 -1
  175. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/sennheiser-payload.d.ts +0 -16
  176. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/sennheiser-payload.js +0 -3
  177. package/dist/cjs/src/library/services/vendor-implementations/sennheiser/sennheiser-payload.js.map +0 -1
  178. package/dist/cjs/src/library/test-utils.test.js.map +0 -1
  179. package/dist/cjs/src/library/types/jabra-request.d.ts +0 -3
  180. package/dist/cjs/src/library/types/jabra-request.js.map +0 -1
  181. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-commands.d.ts +0 -13
  182. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-commands.js +0 -15
  183. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-commands.js.map +0 -1
  184. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-event-translation.d.ts +0 -12
  185. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-event-translation.js +0 -13
  186. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-event-translation.js.map +0 -1
  187. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-requested-events.d.ts +0 -5
  188. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-requested-events.js +0 -7
  189. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome-requested-events.js.map +0 -1
  190. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome.d.ts +0 -38
  191. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome.js +0 -248
  192. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome.js.map +0 -1
  193. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome.test.d.ts +0 -1
  194. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome.test.js +0 -568
  195. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-chrome/jabra-chrome.test.js.map +0 -1
  196. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-commands.d.ts +0 -13
  197. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-commands.js +0 -15
  198. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-commands.js.map +0 -1
  199. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-commands.d.ts +0 -6
  200. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-commands.js +0 -8
  201. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-commands.js.map +0 -1
  202. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-heaset-state.d.ts +0 -4
  203. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-heaset-state.js +0 -2
  204. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-heaset-state.js.map +0 -1
  205. package/dist/es/src/library/services/vendor-implementations/jabra/jabra-native/jabra-native-types.js.map +0 -1
  206. package/dist/es/src/library/services/vendor-implementations/sennheiser/sennheiser-event-types.d.ts +0 -5
  207. package/dist/es/src/library/services/vendor-implementations/sennheiser/sennheiser-event-types.js +0 -7
  208. package/dist/es/src/library/services/vendor-implementations/sennheiser/sennheiser-event-types.js.map +0 -1
  209. package/dist/es/src/library/services/vendor-implementations/sennheiser/sennheiser-events.js.map +0 -1
  210. package/dist/es/src/library/services/vendor-implementations/sennheiser/sennheiser-payload.d.ts +0 -16
  211. package/dist/es/src/library/services/vendor-implementations/sennheiser/sennheiser-payload.js +0 -2
  212. package/dist/es/src/library/services/vendor-implementations/sennheiser/sennheiser-payload.js.map +0 -1
  213. package/dist/es/src/library/test-utils.test.js.map +0 -1
  214. package/dist/es/src/library/types/jabra-request.d.ts +0 -3
  215. package/dist/es/src/library/types/jabra-request.js +0 -2
  216. package/dist/es/src/library/types/jabra-request.js.map +0 -1
@@ -17,112 +17,65 @@ const rxjs_1 = require("rxjs");
17
17
  const jabra_js_1 = require("@gnaudio/jabra-js");
18
18
  const broadcast_channel_1 = require("broadcast-channel");
19
19
  require("regenerator-runtime");
20
- const test_utils_test_1 = require("../../../test-utils.test");
20
+ const mock_jabra_sdk_1 = require("./mock-jabra-sdk");
21
21
  jest.mock('broadcast-channel');
22
- const testDevice1 = {
23
- deviceName: 'Test Device 1',
24
- ProductName: 'Super Headset',
25
- headsetType: 'Wireless',
26
- };
27
- const testDevice2 = {
28
- deviceName: 'Test Device 2',
29
- ProductName: 'Yellow Headset',
30
- headsetType: 'Wired with buttons',
31
- };
32
- const testDevice3 = {
33
- deviceName: 'Test Device 3',
34
- ProductName: 'Bluetooth Bannana',
35
- headsetType: 'Looks like a fruit',
36
- };
37
22
  const flushPromises = () => Promise.resolve();
38
- function populateDevices(service) {
39
- service.devices.set(testDevice1.deviceName, testDevice1);
40
- service.devices.set(testDevice2.deviceName, testDevice2);
41
- service.devices.set(testDevice3.deviceName, testDevice3);
42
- }
23
+ const exceptionWithType = (message, type) => {
24
+ const error = new Error();
25
+ error.message = message;
26
+ error.type = type;
27
+ return error;
28
+ };
43
29
  const createMockCallControl = (deviceSignalsObservable) => {
44
30
  return {
45
31
  device: jest.fn(),
46
32
  onDisconnect: jest.fn(),
47
33
  deviceSignals: deviceSignalsObservable,
48
- takeCallLock: jest.fn(),
34
+ takeCallLock: jest.fn().mockResolvedValue(null),
49
35
  releaseCallLock: jest.fn(),
50
36
  offHook: jest.fn(),
51
37
  ring: jest.fn(),
52
38
  mute: jest.fn(),
53
- hold: jest.fn()
39
+ hold: jest.fn(),
54
40
  };
55
41
  };
56
- const exceptionWithType = (message, type) => {
57
- const error = new Error();
58
- error.message = message;
59
- error.type = type;
60
- return error;
42
+ const mockDevice1 = {
43
+ id: 123,
44
+ name: 'Test Label 123',
45
+ vendorId: 2830,
46
+ productId: 3648,
47
+ serialNumber: '123456789'
48
+ };
49
+ const mockDevice2 = {
50
+ id: 456,
51
+ name: 'Test Label 456',
52
+ vendorId: 2831,
53
+ productId: 3649,
54
+ serialNumber: '1234567891'
61
55
  };
62
56
  const initializeSdk = (subject) => __awaiter(void 0, void 0, void 0, function* () {
63
- const sdk = yield jabra_js_1.init({
64
- appId: 'softphone-vendor-headsets-test',
65
- appName: 'Softphone Headset Library Test',
66
- transport: jabra_js_1.RequestedBrowserTransport.CHROME_EXTENSION_WITH_WEB_HID_FALLBACK
67
- });
68
- const deviceList = [
69
- {
70
- id: 123,
71
- name: 'Test Label 123',
72
- vendorId: 2830,
73
- productId: 3648,
74
- serialNumber: '123456789',
75
- currentConnections: [{
76
- hidChannel: {
77
- descriptor: [{
78
- reportSize: 1,
79
- reportType: 1,
80
- usage: 23,
81
- usagePage: 65344,
82
- valueType: "absolute"
83
- }],
84
- },
85
- type: 2
86
- }],
87
- type: 255,
88
- browserLabel: 'Test Label 123:3648',
89
- },
90
- {
91
- name: 'Definitely not this'
92
- }
93
- ];
94
- sdk.deviceList = subject.asObservable();
95
- subject.next(deviceList);
96
- return sdk;
57
+ if (!subject) {
58
+ const deviceList = [
59
+ mockDevice1
60
+ ];
61
+ subject = new rxjs_1.BehaviorSubject(deviceList);
62
+ }
63
+ return new mock_jabra_sdk_1.MockJabraSdk(subject);
97
64
  });
98
- const resetJabraService = (service) => {
99
- service.isConnecting = false;
100
- service.isConnected = false;
101
- service.isActive = false;
102
- service.devices = new Map();
103
- service.activeDeviceId = null;
104
- service.logger = test_utils_test_1.mockLogger;
105
- service._connectDeferred = null;
106
- };
107
65
  describe('JabraService', () => {
108
66
  let jabraService;
109
- let jabraSdk;
110
- const subject = new rxjs_1.ReplaySubject(1);
111
- // const deviceSignalsSubject = new Subject<ICallControlSignal>();
112
- // const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
113
- Object.defineProperty(window.navigator, 'hid', { get: () => ({
114
- getDevices: () => { return []; }
115
- }) });
67
+ Object.defineProperty(window.navigator, 'hid', {
68
+ get: () => ({
69
+ getDevices: () => {
70
+ return [];
71
+ },
72
+ }),
73
+ });
116
74
  Object.defineProperty(window.navigator, 'locks', { get: () => ({}) });
117
75
  window.BroadcastChannel = broadcast_channel_1.BroadcastChannel;
118
- beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
119
- jabraSdk = initializeSdk(subject);
76
+ beforeEach(() => {
120
77
  jabraService = jabra_1.default.getInstance({ logger: console, createNew: true });
121
- resetJabraService(jabraService);
122
- }));
123
- afterEach(() => {
124
- jest.resetAllMocks();
125
- jest.restoreAllMocks();
78
+ jabraService.initializeJabraSdk = initializeSdk;
126
79
  });
127
80
  describe('instantiation', () => {
128
81
  it('should be a singleton', () => {
@@ -152,121 +105,91 @@ describe('JabraService', () => {
152
105
  });
153
106
  });
154
107
  describe('initial connection', () => {
155
- beforeEach(() => {
156
- resetJabraService(jabraService);
157
- jest.useFakeTimers();
158
- });
159
- afterEach(() => {
160
- jest.clearAllTimers();
161
- jest.useRealTimers();
162
- });
163
- it('should set the proper values while trying to connect; successfuly connect', () => __awaiter(void 0, void 0, void 0, function* () {
164
- const processEventsSpy = jest.spyOn(jabraService, '_processEvents');
108
+ it('should use existing jabraSdk and connect', () => __awaiter(void 0, void 0, void 0, function* () {
109
+ jabraService.jabraSdk = (yield initializeSdk());
165
110
  const deviceSignalsSubject = new rxjs_1.Subject();
166
111
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
167
- const callControlFactorySpy = jest.spyOn(jabraService, 'createCallControlFactory').mockReturnValue({
112
+ jabraService.callControlFactory = {
168
113
  createCallControl: () => __awaiter(void 0, void 0, void 0, function* () {
169
114
  return callControl;
170
115
  })
171
- });
116
+ };
172
117
  const testLabel = 'test label 123';
173
- jabraService.jabraSdk = jabraSdk;
118
+ const initSdkSpy = jabraService['initializeJabraSdk'] = jest.fn();
174
119
  yield jabraService.connect(testLabel);
175
- jest.runAllTimers();
176
- yield flushPromises();
177
- yield flushPromises();
178
- yield flushPromises();
179
- expect(callControlFactorySpy).toHaveBeenCalled();
180
- expect(processEventsSpy).toHaveBeenCalledWith(callControl);
120
+ expect(initSdkSpy).not.toHaveBeenCalled();
181
121
  expect(jabraService.isConnected).toBe(true);
182
122
  expect(jabraService.isConnecting).toBe(false);
183
123
  }));
184
- it('should set the proper values while trying to connect; failed to connect', () => __awaiter(void 0, void 0, void 0, function* () {
124
+ it('should init jabra sdk and connect', () => __awaiter(void 0, void 0, void 0, function* () {
125
+ const processEventsSpy = jest.spyOn(jabraService, '_processEvents');
185
126
  const deviceSignalsSubject = new rxjs_1.Subject();
186
127
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
187
- jest.spyOn(jabraService, 'createCallControlFactory').mockReturnValue({
128
+ const callControlFactorySpy = jest
129
+ .spyOn(jabraService, 'createCallControlFactory')
130
+ .mockReturnValue({
188
131
  createCallControl: () => __awaiter(void 0, void 0, void 0, function* () {
189
132
  return callControl;
190
- })
133
+ }),
191
134
  });
192
- const deviceConnectionStatusChangedSpy = jest.spyOn(jabraService, 'changeConnectionStatus');
193
- const errorLoggerSpy = jest.spyOn(jabraService.logger, 'error');
194
- const requestWebHidPermissionsSpy = jest.spyOn(jabraService, 'requestWebHidPermissions');
195
- const testLabel = 'test label 456';
196
- jabraService.jabraSdk = jabraSdk;
135
+ const testLabel = 'test label 123';
197
136
  yield jabraService.connect(testLabel);
198
- jest.runAllTimers();
199
- yield flushPromises();
200
- jest.runOnlyPendingTimers();
201
- yield flushPromises();
202
- yield flushPromises();
203
- expect(requestWebHidPermissionsSpy).toHaveBeenCalled();
204
- expect(deviceConnectionStatusChangedSpy).toHaveBeenCalled();
137
+ expect(callControlFactorySpy).toHaveBeenCalled();
138
+ expect(processEventsSpy).toHaveBeenCalledWith(callControl);
139
+ expect(jabraService.isConnected).toBe(true);
205
140
  expect(jabraService.isConnecting).toBe(false);
206
- expect(errorLoggerSpy).toHaveBeenCalled();
207
- }));
208
- it('should set the proper values while trying to connect; failed initial connection, populated afterwards', () => __awaiter(void 0, void 0, void 0, function* () {
209
- const testDevices = [
210
- {
211
- id: 123,
212
- name: 'Test Label 123',
213
- vendorId: 2830,
214
- productId: 3648,
215
- serialNumber: '123456789',
216
- currentConnections: [{
217
- hidChannel: {
218
- descriptor: [{
219
- reportSize: 1,
220
- reportType: 1,
221
- usage: 23,
222
- usagePage: 65344,
223
- valueType: "absolute"
224
- }],
225
- },
226
- type: 2
227
- }],
228
- type: 255,
229
- browserLabel: 'Test Label 123:3648',
230
- },
231
- {
232
- name: 'Definitely not this'
233
- },
234
- {
235
- id: 456,
236
- name: 'Test Label 456'
237
- }
238
- ];
239
- const processEventsSpy = jest.spyOn(jabraService, '_processEvents');
240
- const deviceSignalsSubject = new rxjs_1.Subject();
241
- const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
242
- jest.spyOn(jabraService, 'createCallControlFactory').mockReturnValue({
141
+ }));
142
+ it('should do nothing if trying to connect', () => __awaiter(void 0, void 0, void 0, function* () {
143
+ const statusChangeSpy = jest.spyOn(jabraService, 'changeConnectionStatus');
144
+ jabraService.isConnecting = true;
145
+ yield jabraService.connect('someDevice');
146
+ expect(statusChangeSpy).not.toHaveBeenCalled();
147
+ }));
148
+ it('should connect with previouslyConnectedDevice', () => __awaiter(void 0, void 0, void 0, function* () {
149
+ const statusChangeSpy = jest.spyOn(jabraService, 'changeConnectionStatus');
150
+ jest.spyOn(jabraService, 'getPreviouslyConnectedDevice').mockResolvedValue(mockDevice2);
151
+ const callControl = createMockCallControl(new rxjs_1.Subject().asObservable());
152
+ jest
153
+ .spyOn(jabraService, 'createCallControlFactory')
154
+ .mockReturnValue({
243
155
  createCallControl: () => __awaiter(void 0, void 0, void 0, function* () {
244
156
  return callControl;
245
- })
157
+ }),
246
158
  });
247
- const deviceConnectionStatusChangedSpy = jest.spyOn(jabraService, 'changeConnectionStatus');
248
- const requestWebHidPermissionsSpy = jest.spyOn(jabraService, 'requestWebHidPermissions');
249
- const testLabel = 'test label 456';
250
- jabraService.jabraSdk = jabraSdk;
251
- yield jabraService.connect(testLabel);
252
- jest.advanceTimersByTime(2100);
253
- yield flushPromises();
254
- subject.next(testDevices);
255
- yield flushPromises();
256
- yield flushPromises();
257
- // await flushPromises();
258
- expect(requestWebHidPermissionsSpy).toHaveBeenCalled();
259
- expect(processEventsSpy).toHaveBeenCalledWith(callControl);
260
- expect(deviceConnectionStatusChangedSpy).toHaveBeenCalledWith({ isConnected: true, isConnecting: false });
261
- expect(jabraService.isConnecting).toBe(false);
262
- expect(jabraService.isConnected).toBe(true);
159
+ yield jabraService.connect(mockDevice2.name);
160
+ expect(statusChangeSpy).toHaveBeenCalledWith({ isConnected: true, isConnecting: false });
263
161
  }));
264
- it('should have an instance of a CallControlFactory after calling the createCallControlFactory function', () => __awaiter(void 0, void 0, void 0, function* () {
265
- const testLabel = 'test label 123';
266
- jabraService.jabraSdk = jabraSdk;
267
- yield jabraService.connect(testLabel);
268
- yield flushPromises();
269
- expect(jabraService.callControlFactory instanceof jabra_js_1.CallControlFactory).toBe(true);
162
+ it('should connect with webhidRequest', () => __awaiter(void 0, void 0, void 0, function* () {
163
+ const statusChangeSpy = jest.spyOn(jabraService, 'changeConnectionStatus');
164
+ jest.spyOn(jabraService, 'getPreviouslyConnectedDevice').mockResolvedValue(null);
165
+ const webhidSpy = jest.spyOn(jabraService, 'getDeviceFromWebhid').mockResolvedValue(mockDevice2);
166
+ const callControl = createMockCallControl(new rxjs_1.Subject().asObservable());
167
+ jest
168
+ .spyOn(jabraService, 'createCallControlFactory')
169
+ .mockReturnValue({
170
+ createCallControl: () => __awaiter(void 0, void 0, void 0, function* () {
171
+ return callControl;
172
+ }),
173
+ });
174
+ yield jabraService.connect(mockDevice2.name);
175
+ expect(webhidSpy).toHaveBeenCalled();
176
+ expect(statusChangeSpy).toHaveBeenCalledWith({ isConnected: true, isConnecting: false });
177
+ }));
178
+ it('should fail to connect and set statuses accordingly', () => __awaiter(void 0, void 0, void 0, function* () {
179
+ const statusChangeSpy = jest.spyOn(jabraService, 'changeConnectionStatus');
180
+ jest.spyOn(jabraService, 'getPreviouslyConnectedDevice').mockResolvedValue(null);
181
+ const callControlSpy = jest.fn();
182
+ const callControl = createMockCallControl(new rxjs_1.Subject().asObservable());
183
+ jest
184
+ .spyOn(jabraService, 'createCallControlFactory')
185
+ .mockReturnValue({
186
+ createCallControl: callControl
187
+ });
188
+ const webhidSpy = jest.spyOn(jabraService, 'getDeviceFromWebhid').mockRejectedValue({});
189
+ yield jabraService.connect(mockDevice2.name);
190
+ expect(webhidSpy).toHaveBeenCalled();
191
+ expect(callControlSpy).not.toHaveBeenCalled();
192
+ expect(statusChangeSpy).lastCalledWith({ isConnected: false, isConnecting: false });
270
193
  }));
271
194
  });
272
195
  describe('processEvents', () => {
@@ -281,6 +204,18 @@ describe('JabraService', () => {
281
204
  expect(callControl.ring).toHaveBeenCalledWith(false);
282
205
  expect(deviceAnsweredCallSpy).toHaveBeenCalled();
283
206
  }));
207
+ it('offhook should not call deviceAnsweredCall if outboundCall', () => {
208
+ jabraService.pendingConversationIsOutbound = true;
209
+ jabraService.callLock = true;
210
+ const deviceAnsweredCallSpy = jest.spyOn(jabraService, 'deviceAnsweredCall');
211
+ const deviceSignalsSubject = new rxjs_1.Subject();
212
+ const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
213
+ jabraService._processEvents(callControl);
214
+ deviceSignalsSubject.next({ type: 32, value: true });
215
+ expect(callControl.offHook).toHaveBeenCalledWith(true);
216
+ expect(callControl.ring).toHaveBeenCalledWith(false);
217
+ expect(deviceAnsweredCallSpy).not.toHaveBeenCalled();
218
+ });
284
219
  it('properly handles end call events passed in from headset with a successful callLock release', () => __awaiter(void 0, void 0, void 0, function* () {
285
220
  jabraService.callLock = true;
286
221
  const deviceEndedCallSpy = jest.spyOn(jabraService, 'deviceEndedCall');
@@ -349,14 +284,25 @@ describe('JabraService', () => {
349
284
  const deviceSignalsSubject = new rxjs_1.Subject();
350
285
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
351
286
  jabraService._processEvents(callControl);
287
+ jabraService.activeConversationId = 'myConvo5521';
352
288
  deviceSignalsSubject.next({ type: 33, value: true });
353
289
  expect(jabraService.isHeld).toBe(true);
354
290
  expect(callControl.hold).toHaveBeenCalledWith(true);
355
- expect(deviceHoldStatusChangedSpy).toHaveBeenCalledWith(true, { code: 33, name: 'OnHold' });
291
+ expect(deviceHoldStatusChangedSpy).toHaveBeenCalledWith({
292
+ holdRequested: true,
293
+ code: 33,
294
+ name: 'OnHold',
295
+ conversationId: jabraService.activeConversationId
296
+ });
356
297
  deviceSignalsSubject.next({ type: 35, value: true });
357
298
  expect(jabraService.isHeld).toBe(false);
358
299
  expect(callControl.hold).toHaveBeenCalledWith(false);
359
- expect(deviceHoldStatusChangedSpy).toHaveBeenCalledWith(false, { code: 35, name: 'ResumeCall' });
300
+ expect(deviceHoldStatusChangedSpy).toHaveBeenCalledWith({
301
+ holdRequested: false,
302
+ code: 35,
303
+ name: 'ResumeCall',
304
+ conversationId: jabraService.activeConversationId
305
+ });
360
306
  }));
361
307
  it('properly handles mute call events passed in from headset', () => __awaiter(void 0, void 0, void 0, function* () {
362
308
  jabraService.callLock = true;
@@ -364,31 +310,44 @@ describe('JabraService', () => {
364
310
  const deviceSignalsSubject = new rxjs_1.Subject();
365
311
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
366
312
  jabraService._processEvents(callControl);
313
+ jabraService.activeConversationId = 'myConvo555521';
367
314
  deviceSignalsSubject.next({ type: 47, value: true });
368
315
  expect(jabraService.isMuted).toBe(true);
369
316
  expect(callControl.mute).toHaveBeenCalledWith(true);
370
- expect(deviceMuteChangedSpy).toHaveBeenCalledWith(true, { code: 47, name: 'CallMuted' });
317
+ expect(deviceMuteChangedSpy).toHaveBeenCalledWith({
318
+ isMuted: true,
319
+ code: 47,
320
+ name: 'CallMuted',
321
+ conversationId: jabraService.activeConversationId
322
+ });
371
323
  deviceSignalsSubject.next({ type: 47, value: true });
372
324
  expect(jabraService.isMuted).toBe(false);
373
325
  expect(callControl.mute).toHaveBeenCalledWith(false);
374
- expect(deviceMuteChangedSpy).toHaveBeenCalledWith(false, { code: 47, name: 'CallUnmuted' });
326
+ expect(deviceMuteChangedSpy).toHaveBeenCalledWith({
327
+ isMuted: false,
328
+ code: 47,
329
+ name: 'CallUnmuted',
330
+ conversationId: jabraService.activeConversationId
331
+ });
375
332
  }));
376
333
  it('properly handles reject call events passed in from headset with a successful callLock release', () => __awaiter(void 0, void 0, void 0, function* () {
377
334
  jabraService.callLock = true;
378
- jabraService.incomingConversationId = 'convoId1234';
335
+ const conversationId = 'convoId1234';
336
+ jabraService.pendingConversationId = conversationId;
379
337
  const deviceRejectedCallSpy = jest.spyOn(jabraService, 'deviceRejectedCall');
380
338
  const deviceSignalsSubject = new rxjs_1.Subject();
381
339
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
382
340
  jabraService._processEvents(callControl);
383
341
  deviceSignalsSubject.next({ type: 65533, value: true });
384
342
  expect(callControl.ring).toHaveBeenCalledWith(false);
385
- expect(deviceRejectedCallSpy).toHaveBeenCalledWith('convoId1234');
343
+ expect(deviceRejectedCallSpy).toHaveBeenCalledWith({ conversationId, name: 'REJECT_CALL' });
386
344
  expect(yield callControl.releaseCallLock).toHaveBeenCalled();
387
345
  expect(jabraService.callLock).toBe(false);
388
346
  }));
389
347
  it('properly handles reject call events passed in from headset with a failed callLock release', () => __awaiter(void 0, void 0, void 0, function* () {
390
348
  jabraService.callLock = true;
391
- jabraService.incomingConversationId = 'convoId1234';
349
+ const conversationId = 'convoId124234';
350
+ jabraService.pendingConversationId = conversationId;
392
351
  const deviceRejectedCallSpy = jest.spyOn(jabraService, 'deviceRejectedCall');
393
352
  const deviceSignalsSubject = new rxjs_1.Subject();
394
353
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
@@ -405,13 +364,14 @@ describe('JabraService', () => {
405
364
  const infoLoggerSpy = jest.spyOn(jabraService.logger, 'info');
406
365
  deviceSignalsSubject.next({ type: 65533, value: true });
407
366
  expect(callControl.ring).toHaveBeenCalledWith(false);
408
- expect(deviceRejectedCallSpy).toHaveBeenCalledWith('convoId1234');
367
+ expect(deviceRejectedCallSpy).toHaveBeenCalledWith({ conversationId, name: 'REJECT_CALL' });
409
368
  expect(yield callControl.releaseCallLock).toHaveBeenCalled();
410
369
  expect(infoLoggerSpy).toHaveBeenCalledWith('Trying to release the call lock, but it is not held!');
411
370
  }));
412
371
  it('properly logs an error that is not related to call lock during reject call flow', () => __awaiter(void 0, void 0, void 0, function* () {
413
372
  jabraService.callLock = true;
414
- jabraService.incomingConversationId = 'convoId1234';
373
+ const conversationId = 'convoId1524';
374
+ jabraService.pendingConversationId = conversationId;
415
375
  const deviceRejectedCallSpy = jest.spyOn(jabraService, 'deviceRejectedCall');
416
376
  const deviceSignalsSubject = new rxjs_1.Subject();
417
377
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
@@ -428,7 +388,7 @@ describe('JabraService', () => {
428
388
  const errorLoggerSpy = jest.spyOn(jabraService.logger, 'error');
429
389
  deviceSignalsSubject.next({ type: 65533, value: true });
430
390
  expect(callControl.ring).toHaveBeenCalledWith(false);
431
- expect(deviceRejectedCallSpy).toHaveBeenCalledWith('convoId1234');
391
+ expect(deviceRejectedCallSpy).toHaveBeenCalledWith({ conversationId, name: 'REJECT_CALL' });
432
392
  expect(yield callControl.releaseCallLock).toHaveBeenCalled();
433
393
  expect(errorLoggerSpy).toHaveBeenCalledWith(jabra_js_1.ErrorType.UNEXPECTED_ERROR, 'Something went terribly wrong');
434
394
  }));
@@ -491,15 +451,35 @@ describe('JabraService', () => {
491
451
  });
492
452
  });
493
453
  describe('disconnect', () => {
494
- it('resets two connected flags after disconnecting', () => {
454
+ it('resets two connected flags after disconnecting', () => __awaiter(void 0, void 0, void 0, function* () {
495
455
  jabraService.isConnected = true;
496
456
  jabraService.isConnecting = true;
497
- const headsetEventSubscriptionSpy = jest.spyOn(jabraService['headsetEventSubscription'], 'unsubscribe');
498
- jabraService.disconnect();
499
- expect(headsetEventSubscriptionSpy).toHaveBeenCalled();
457
+ const unsubscribeSpy = jest.fn();
458
+ jabraService['headsetEventSubscription'] = {
459
+ unsubscribe: unsubscribeSpy
460
+ };
461
+ yield jabraService.disconnect();
462
+ expect(unsubscribeSpy).toHaveBeenCalled();
500
463
  expect(jabraService.isConnecting).toBe(false);
501
464
  expect(jabraService.isConnected).toBe(false);
502
- });
465
+ }));
466
+ it('should only change connection status if connecting or connected', () => __awaiter(void 0, void 0, void 0, function* () {
467
+ const connectionSpy = jabraService['changeConnectionStatus'] = jest.fn();
468
+ jabraService.isConnected = false;
469
+ jabraService.isConnecting = false;
470
+ jabraService['headsetEventSubscription'] = {
471
+ unsubscribe: jest.fn()
472
+ };
473
+ yield jabraService.disconnect();
474
+ expect(connectionSpy).not.toHaveBeenCalled();
475
+ jabraService.isConnected = true;
476
+ yield jabraService.disconnect();
477
+ expect(connectionSpy).toHaveBeenCalled();
478
+ jabraService.isConnected = false;
479
+ jabraService.isConnecting = false;
480
+ yield jabraService.disconnect();
481
+ expect(connectionSpy).toHaveBeenCalled();
482
+ }));
503
483
  });
504
484
  describe('answerCall', () => {
505
485
  it('sends answer call event to headset', () => {
@@ -527,20 +507,33 @@ describe('JabraService', () => {
527
507
  jabraService.callControl = callControl;
528
508
  const callInfo = {
529
509
  conversationId: '123',
530
- contactName: 'Lee Moriarty'
510
+ contactName: 'Lee Moriarty',
531
511
  };
532
512
  callControl.takeCallLock.mockResolvedValue(true);
533
513
  yield jabraService.incomingCall(callInfo);
534
514
  expect(jabraService.callLock).toBe(true);
535
515
  expect(callControl.ring).toHaveBeenCalledWith(true);
536
516
  }));
517
+ it('should do nothing if no calllock', () => __awaiter(void 0, void 0, void 0, function* () {
518
+ const deviceSignalsSubject = new rxjs_1.Subject();
519
+ const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
520
+ jabraService.callControl = callControl;
521
+ callControl.takeCallLock.mockResolvedValue(false);
522
+ const callInfo = {
523
+ conversationId: '123',
524
+ contactName: 'Lee Moriarty',
525
+ };
526
+ yield jabraService.incomingCall(callInfo);
527
+ expect(jabraService.callLock).toBe(false);
528
+ expect(callControl.ring).not.toHaveBeenCalled();
529
+ }));
537
530
  it('sends ring event based on flags after already having callLock', () => __awaiter(void 0, void 0, void 0, function* () {
538
531
  const deviceSignalsSubject = new rxjs_1.Subject();
539
532
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
540
533
  jabraService.callControl = callControl;
541
534
  const callInfo = {
542
535
  conversationId: '456',
543
- contactName: 'Adam Cole'
536
+ contactName: 'Adam Cole',
544
537
  };
545
538
  callControl.takeCallLock.mockImplementation(() => {
546
539
  throw exceptionWithType('Trying to take the call lock, but it is already held!', jabra_js_1.ErrorType.SDK_USAGE_ERROR);
@@ -556,7 +549,7 @@ describe('JabraService', () => {
556
549
  jabraService.callControl = callControl;
557
550
  const callInfo = {
558
551
  conversationId: '789',
559
- contactName: 'Gene Ween'
552
+ contactName: 'Gene Ween',
560
553
  };
561
554
  callControl.takeCallLock.mockImplementation(() => {
562
555
  throw exceptionWithType('An actual error', jabra_js_1.ErrorType.UNEXPECTED_ERROR);
@@ -573,10 +566,20 @@ describe('JabraService', () => {
573
566
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
574
567
  jabraService.callControl = callControl;
575
568
  callControl.takeCallLock.mockResolvedValue(true);
576
- yield jabraService.outgoingCall();
569
+ yield jabraService.outgoingCall({ conversationId: 'myconvoid1' });
577
570
  expect(jabraService.callLock).toBe(true);
578
571
  expect(callControl.offHook).toHaveBeenCalledWith(true);
579
572
  }));
573
+ it('does nothing if callLock is false', () => __awaiter(void 0, void 0, void 0, function* () {
574
+ const deviceSignalsSubject = new rxjs_1.Subject();
575
+ const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
576
+ callControl.takeCallLock.mockResolvedValue(false);
577
+ jabraService.callControl = callControl;
578
+ yield jabraService.outgoingCall({ conversationId: 'myconvoid2' });
579
+ expect(jabraService.callLock).toBe(false);
580
+ expect(jabraService.activeConversationId).toBeFalsy();
581
+ expect(callControl.offHook).not.toHaveBeenCalled();
582
+ }));
580
583
  it('sends ring event while already in possession of callLock', () => __awaiter(void 0, void 0, void 0, function* () {
581
584
  const deviceSignalsSubject = new rxjs_1.Subject();
582
585
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
@@ -585,7 +588,7 @@ describe('JabraService', () => {
585
588
  throw exceptionWithType('Trying to take the call lock, but it is already held!', jabra_js_1.ErrorType.SDK_USAGE_ERROR);
586
589
  });
587
590
  const infoLoggerSpy = jest.spyOn(jabraService.logger, 'info');
588
- yield jabraService.outgoingCall();
591
+ yield jabraService.outgoingCall({ conversationId: 'myconvoid2' });
589
592
  expect(infoLoggerSpy).toHaveBeenCalledWith('Trying to take the call lock, but it is already held!');
590
593
  expect(callControl.offHook).toHaveBeenCalledWith(true);
591
594
  }));
@@ -597,37 +600,35 @@ describe('JabraService', () => {
597
600
  throw exceptionWithType('An actual error', jabra_js_1.ErrorType.UNEXPECTED_ERROR);
598
601
  });
599
602
  const errorLoggerSpy = jest.spyOn(jabraService.logger, 'error');
600
- yield jabraService.outgoingCall();
603
+ yield jabraService.outgoingCall({ conversationId: 'myconvoid3' });
601
604
  expect(errorLoggerSpy).toHaveBeenCalledWith(jabra_js_1.ErrorType.UNEXPECTED_ERROR, 'An actual error');
602
605
  expect(callControl.offHook).not.toHaveBeenCalled();
603
606
  }));
604
607
  });
605
608
  describe('rejectCall', () => {
606
- it('properly sends ring events and releases call lock', () => {
609
+ it('properly sends ring events and releases call lock', () => __awaiter(void 0, void 0, void 0, function* () {
607
610
  const deviceSignalsSubject = new rxjs_1.Subject();
608
611
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
609
612
  jabraService.callControl = callControl;
610
613
  const resetStateSpy = jest.spyOn(jabraService, 'resetState');
611
614
  jabraService.callLock = true;
612
- const jabraRejectCall = jabraService.rejectCall();
615
+ yield jabraService.rejectCall();
613
616
  expect(callControl.ring).toHaveBeenCalledWith(false);
614
617
  expect(callControl.releaseCallLock).toHaveBeenCalled();
615
618
  expect(jabraService.callLock).toBe(false);
616
619
  expect(resetStateSpy).toHaveBeenCalled();
617
- expect(jabraRejectCall).resolves.toReturn();
618
- });
619
- it('prints out message if not in possession of callLock', () => {
620
+ }));
621
+ it('prints out message if not in possession of callLock', () => __awaiter(void 0, void 0, void 0, function* () {
620
622
  const deviceSignalsSubject = new rxjs_1.Subject();
621
623
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
622
624
  jabraService.callControl = callControl;
623
625
  const infoLoggerSpy = jest.spyOn(jabraService.logger, 'info');
624
626
  const resetStateSpy = jest.spyOn(jabraService, 'resetState');
625
- const jabraRejectCall = jabraService.rejectCall();
627
+ yield jabraService.rejectCall();
626
628
  expect(infoLoggerSpy).toHaveBeenCalledWith('Currently not in possession of the Call Lock; Cannot react to Device Actions');
627
629
  expect(jabraService.callLock).toBe(false);
628
630
  expect(resetStateSpy).toHaveBeenCalled();
629
- expect(jabraRejectCall).resolves.toReturn();
630
- });
631
+ }));
631
632
  it('properly handles flow when in possession of callLock', () => {
632
633
  const deviceSignalsSubject = new rxjs_1.Subject();
633
634
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
@@ -657,39 +658,38 @@ describe('JabraService', () => {
657
658
  });
658
659
  });
659
660
  describe('endCall', () => {
660
- it('properly sends offHook events and releases call lock', () => {
661
+ it('properly sends offHook events and releases call lock', () => __awaiter(void 0, void 0, void 0, function* () {
661
662
  const deviceSignalsSubject = new rxjs_1.Subject();
663
+ jabraService.activeConversationId = '123';
662
664
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
663
665
  jabraService.callControl = callControl;
664
666
  const resetStateSpy = jest.spyOn(jabraService, 'resetState');
665
667
  jabraService.callLock = true;
666
- const jabraEndCalls = jabraService.endCall('123', false);
668
+ yield jabraService.endCall('123', false);
667
669
  expect(callControl.offHook).toHaveBeenCalledWith(false);
668
670
  expect(callControl.releaseCallLock).toHaveBeenCalled();
669
671
  expect(jabraService.callLock).toBe(false);
670
672
  expect(resetStateSpy).toHaveBeenCalled();
671
- expect(jabraEndCalls).resolves.toReturn();
672
- });
673
- it('properly resolves if another call is already in place', () => {
673
+ expect(jabraService.activeConversationId).toBeNull();
674
+ }));
675
+ it('properly resolves if another call is already in place', () => __awaiter(void 0, void 0, void 0, function* () {
674
676
  const deviceSignalsSubject = new rxjs_1.Subject();
675
677
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
676
678
  jabraService.callControl = callControl;
677
- const jabraEndCalls = jabraService.endCall('123', true);
678
- expect(jabraEndCalls).resolves.toReturn();
679
+ yield jabraService.endCall('123', true);
679
680
  expect(callControl.offHook).not.toHaveBeenCalled();
680
- });
681
- it('prints out message if not in possession of callLock', () => {
681
+ }));
682
+ it('prints out message if not in possession of callLock', () => __awaiter(void 0, void 0, void 0, function* () {
682
683
  const deviceSignalsSubject = new rxjs_1.Subject();
683
684
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
684
685
  jabraService.callControl = callControl;
685
686
  const infoLoggerSpy = jest.spyOn(jabraService.logger, 'info');
686
687
  const resetStateSpy = jest.spyOn(jabraService, 'resetState');
687
- const jabraEndCalls = jabraService.endCall('123', false);
688
+ yield jabraService.endCall('123', false);
688
689
  expect(infoLoggerSpy).toHaveBeenCalledWith('Currently not in possession of the Call Lock; Cannot react to Device Actions');
689
690
  expect(jabraService.callLock).toBe(false);
690
691
  expect(resetStateSpy).toHaveBeenCalled();
691
- expect(jabraEndCalls).resolves.toReturn();
692
- });
692
+ }));
693
693
  it('properly handles flow when in possession of callLock', () => {
694
694
  const deviceSignalsSubject = new rxjs_1.Subject();
695
695
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
@@ -719,31 +719,29 @@ describe('JabraService', () => {
719
719
  });
720
720
  });
721
721
  describe('endAllCall', () => {
722
- it('properly sends offHook events and releases call lock', () => {
722
+ it('properly sends offHook events and releases call lock', () => __awaiter(void 0, void 0, void 0, function* () {
723
723
  const deviceSignalsSubject = new rxjs_1.Subject();
724
724
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
725
725
  jabraService.callControl = callControl;
726
726
  const resetStateSpy = jest.spyOn(jabraService, 'resetState');
727
727
  jabraService.callLock = true;
728
- const jabraEndCalls = jabraService.endAllCalls();
728
+ yield jabraService.endAllCalls();
729
729
  expect(callControl.offHook).toHaveBeenCalledWith(false);
730
730
  expect(callControl.releaseCallLock).toHaveBeenCalled();
731
731
  expect(jabraService.callLock).toBe(false);
732
732
  expect(resetStateSpy).toHaveBeenCalled();
733
- expect(jabraEndCalls).resolves.toReturn();
734
- });
735
- it('prints out message if not in possession of callLock', () => {
733
+ }));
734
+ it('prints out message if not in possession of callLock', () => __awaiter(void 0, void 0, void 0, function* () {
736
735
  const deviceSignalsSubject = new rxjs_1.Subject();
737
736
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
738
737
  jabraService.callControl = callControl;
739
738
  const infoLoggerSpy = jest.spyOn(jabraService.logger, 'info');
740
739
  const resetStateSpy = jest.spyOn(jabraService, 'resetState');
741
- const jabraEndCalls = jabraService.endAllCalls();
740
+ yield jabraService.endAllCalls();
742
741
  expect(infoLoggerSpy).toHaveBeenCalledWith('Currently not in possession of the Call Lock; Cannot react to Device Actions');
743
742
  expect(jabraService.callLock).toBe(false);
744
743
  expect(resetStateSpy).toHaveBeenCalled();
745
- expect(jabraEndCalls).resolves.toReturn();
746
- });
744
+ }));
747
745
  it('properly handles flow when in possession of callLock', () => {
748
746
  const deviceSignalsSubject = new rxjs_1.Subject();
749
747
  const callControl = createMockCallControl(deviceSignalsSubject.asObservable());
@@ -773,41 +771,45 @@ describe('JabraService', () => {
773
771
  });
774
772
  });
775
773
  describe('deviceInfo', () => {
776
- it('should return null if activeDeviceId is null', () => {
777
- jabraService.devices.set(testDevice1.deviceName, testDevice1);
778
- jabraService.activeDeviceId = null;
779
- const result = jabraService.deviceInfo;
780
- expect(result).toBeNull();
781
- });
782
- it('should return null if there are no devices registered', () => {
783
- jabraService.activeDeviceId = 'foobar';
784
- const result = jabraService.deviceInfo;
785
- expect(result).toBeNull();
786
- });
787
- it('should return a device when it is registered and matches the activeDeviceId', () => {
788
- jabraService.activeDeviceId = testDevice1.deviceName;
789
- jabraService.devices.set(testDevice1.deviceName, testDevice1);
790
- jabraService.devices.set(testDevice2.deviceName, testDevice2);
791
- const result = jabraService.deviceInfo;
792
- expect(result).toBe(testDevice1);
774
+ it('should return _deviceInfo', () => {
775
+ const device = {
776
+ ProductName: 'myJabra',
777
+ deviceId: '123',
778
+ attached: true,
779
+ };
780
+ jabraService._deviceInfo = device;
781
+ expect(jabraService.deviceInfo).toBe(device);
793
782
  });
794
783
  });
795
784
  describe('deviceName', () => {
796
785
  it('should return the deviceName of the active device', () => {
797
- populateDevices(jabraService);
798
- jabraService.activeDeviceId = testDevice1.deviceName;
799
- expect(jabraService.deviceName).toEqual(testDevice1.deviceName);
786
+ const device = {
787
+ ProductName: 'myJabra',
788
+ deviceName: 'myJabraName',
789
+ deviceId: '123',
790
+ attached: true,
791
+ };
792
+ jabraService._deviceInfo = device;
793
+ expect(jabraService.deviceName).toBe(device.deviceName);
794
+ });
795
+ it('should return falsey value if no deviceInfo', () => {
796
+ jabraService._deviceInfo = null;
797
+ expect(jabraService.deviceName).toBeUndefined();
800
798
  });
801
799
  });
802
800
  describe('isDeviceAttached', () => {
803
- it('should return true if the the device is in the devices list is the activeDeviceId', () => {
804
- populateDevices(jabraService);
805
- jabraService.activeDeviceId = testDevice1.deviceName;
801
+ it('should return true if there is deviceInfo', () => {
802
+ const device = {
803
+ ProductName: 'myJabra',
804
+ deviceName: 'myJabraName',
805
+ deviceId: '123',
806
+ attached: true,
807
+ };
808
+ jabraService._deviceInfo = device;
806
809
  expect(jabraService.isDeviceAttached).toEqual(true);
807
810
  });
808
- it('should return false if the the device is NOT in the devices list is the activeDeviceId', () => {
809
- populateDevices(jabraService);
810
- jabraService.activeDeviceId = 'Imaginary Device';
811
+ it('should return false if no deviceInfo', () => {
812
+ jabraService._deviceInfo = null;
811
813
  expect(jabraService.isDeviceAttached).toEqual(false);
812
814
  });
813
815
  });
@@ -826,19 +828,130 @@ describe('JabraService', () => {
826
828
  });
827
829
  it('should return false if name within device is undefined', () => {
828
830
  const testDevice = {
829
- type: "Test",
830
- id: '123'
831
+ type: 'Test',
832
+ id: '123',
831
833
  };
832
834
  expect(jabraService.isDeviceInList(testDevice, 'Test Label 123')).toBe(false);
833
835
  });
834
836
  it('should return true if all expected values are present and the label matches', () => {
835
837
  const testDevice = {
836
- type: "Test",
838
+ type: 'Test',
837
839
  id: '123',
838
- name: 'Test Label 123'
840
+ name: 'Test Label 123',
839
841
  };
840
842
  expect(jabraService.isDeviceInList(testDevice, 'test label 123')).toBe(true);
841
843
  });
842
844
  });
845
+ describe('resetHeadsetState', () => {
846
+ it('should handle reset being called without a callControl', () => __awaiter(void 0, void 0, void 0, function* () {
847
+ yield jabraService.resetHeadsetState();
848
+ // if the above didn't blow up, we are happy
849
+ expect(true).toBeTruthy();
850
+ }));
851
+ it('should reset state if there is a callControl', () => __awaiter(void 0, void 0, void 0, function* () {
852
+ const callControl = createMockCallControl(null);
853
+ jabraService.callControl = callControl;
854
+ yield jabraService.resetHeadsetState();
855
+ expect(callControl.hold).toHaveBeenCalledWith(false);
856
+ expect(callControl.mute).toHaveBeenCalledWith(false);
857
+ expect(callControl.offHook).toHaveBeenCalledWith(false);
858
+ }));
859
+ });
860
+ describe('getDeviceFromWebhid', () => {
861
+ afterEach(() => {
862
+ jest.useRealTimers();
863
+ });
864
+ it('should return matching value from deviceList', () => __awaiter(void 0, void 0, void 0, function* () {
865
+ const sub = new rxjs_1.BehaviorSubject([mockDevice1]);
866
+ jabraService.jabraSdk = (yield initializeSdk(sub));
867
+ const requestSpy = jabraService.requestWebHidPermissions = jest.fn();
868
+ const completionSpy = jest.fn();
869
+ const devicePromise = jabraService.getDeviceFromWebhid(mockDevice2.name)
870
+ .then((device) => {
871
+ completionSpy();
872
+ return device;
873
+ });
874
+ yield flushPromises();
875
+ expect(requestSpy).toHaveBeenCalled();
876
+ expect(completionSpy).not.toBeCalled();
877
+ sub.next([mockDevice1, mockDevice2]);
878
+ const device = yield devicePromise;
879
+ expect(device).toBe(mockDevice2);
880
+ }));
881
+ it('should timeout after 30 seconds', () => __awaiter(void 0, void 0, void 0, function* () {
882
+ jest.useFakeTimers();
883
+ const sub = new rxjs_1.BehaviorSubject([mockDevice1]);
884
+ jabraService.jabraSdk = (yield initializeSdk(sub));
885
+ const requestSpy = jabraService.requestWebHidPermissions = jest.fn();
886
+ const devicePromise = jabraService.getDeviceFromWebhid(mockDevice2.name);
887
+ yield flushPromises();
888
+ expect(requestSpy).toHaveBeenCalled();
889
+ jest.advanceTimersByTime(30100);
890
+ yield expect(devicePromise).rejects.toThrow('not granted WebHID permissions');
891
+ }));
892
+ it('should log random error', () => __awaiter(void 0, void 0, void 0, function* () {
893
+ const sub = new rxjs_1.BehaviorSubject([mockDevice1]);
894
+ jabraService.jabraSdk = (yield initializeSdk(sub));
895
+ const requestSpy = jabraService.requestWebHidPermissions = jest.fn();
896
+ const devicePromise = jabraService.getDeviceFromWebhid(mockDevice2.name);
897
+ yield flushPromises();
898
+ expect(requestSpy).toHaveBeenCalled();
899
+ sub.error(new Error('random error'));
900
+ yield expect(devicePromise).rejects.toThrow('random error');
901
+ }));
902
+ });
903
+ describe('getPreviouslyConnectedDevice', () => {
904
+ afterEach(() => {
905
+ jest.useRealTimers();
906
+ });
907
+ it('should return matching value from deviceList', () => __awaiter(void 0, void 0, void 0, function* () {
908
+ const sub = new rxjs_1.BehaviorSubject([]);
909
+ jabraService.jabraSdk = (yield initializeSdk(sub));
910
+ const completionSpy = jest.fn();
911
+ const devicePromise = jabraService.getPreviouslyConnectedDevice(mockDevice2.name)
912
+ .then((device) => {
913
+ completionSpy();
914
+ return device;
915
+ });
916
+ yield flushPromises();
917
+ expect(completionSpy).not.toBeCalled();
918
+ sub.next([mockDevice1, mockDevice2]);
919
+ const device = yield devicePromise;
920
+ expect(device).toBe(mockDevice2);
921
+ }));
922
+ it('should return null', () => __awaiter(void 0, void 0, void 0, function* () {
923
+ const sub = new rxjs_1.BehaviorSubject([mockDevice1]);
924
+ jabraService.jabraSdk = (yield initializeSdk(sub));
925
+ const completionSpy = jest.fn();
926
+ const devicePromise = jabraService.getPreviouslyConnectedDevice(mockDevice2.name)
927
+ .then((device) => {
928
+ completionSpy();
929
+ return device;
930
+ });
931
+ yield flushPromises();
932
+ expect(completionSpy).not.toBeCalled();
933
+ sub.next([mockDevice1, mockDevice2]);
934
+ const device = yield devicePromise;
935
+ expect(device).toBeNull();
936
+ }));
937
+ it('should timeout after 3 seconds', () => __awaiter(void 0, void 0, void 0, function* () {
938
+ jest.useFakeTimers();
939
+ const sub = new rxjs_1.BehaviorSubject([]);
940
+ jabraService.jabraSdk = (yield initializeSdk(sub));
941
+ const devicePromise = jabraService.getPreviouslyConnectedDevice(mockDevice2.name);
942
+ yield flushPromises();
943
+ jest.advanceTimersByTime(3100);
944
+ const device = yield devicePromise;
945
+ expect(device).toBeFalsy();
946
+ }));
947
+ it('should log random error', () => __awaiter(void 0, void 0, void 0, function* () {
948
+ const sub = new rxjs_1.BehaviorSubject([]);
949
+ jabraService.jabraSdk = (yield initializeSdk(sub));
950
+ const devicePromise = jabraService.getPreviouslyConnectedDevice(mockDevice2.name);
951
+ yield flushPromises();
952
+ sub.error(new Error('random error'));
953
+ yield expect(devicePromise).rejects.toThrow('random error');
954
+ }));
955
+ });
843
956
  });
844
957
  //# sourceMappingURL=jabra.test.js.map