@digitalsamba/embedded-sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/.editorconfig +10 -0
  2. package/.github/workflows/main.yml +32 -0
  3. package/.yarn/cache/@discoveryjs-json-ext-npm-0.5.7-fe04af1f31-2176d301cc.zip +0 -0
  4. package/.yarn/cache/@jridgewell-gen-mapping-npm-0.3.2-c64eeb4a4e-1832707a1c.zip +0 -0
  5. package/.yarn/cache/@jridgewell-resolve-uri-npm-3.1.0-6ff2351e61-b5ceaaf9a1.zip +0 -0
  6. package/.yarn/cache/@jridgewell-set-array-npm-1.1.2-45b82d7fb6-69a84d5980.zip +0 -0
  7. package/.yarn/cache/@jridgewell-source-map-npm-0.3.2-6fd1f37b22-1b83f0eb94.zip +0 -0
  8. package/.yarn/cache/@jridgewell-sourcemap-codec-npm-1.4.14-f5f0630788-61100637b6.zip +0 -0
  9. package/.yarn/cache/@jridgewell-trace-mapping-npm-0.3.17-57578fd48c-9d703b859c.zip +0 -0
  10. package/.yarn/cache/@types-eslint-npm-8.4.8-f5b6d330b4-5b4708a56a.zip +0 -0
  11. package/.yarn/cache/@types-eslint-scope-npm-3.7.4-c11d226d71-ea6a9363e9.zip +0 -0
  12. package/.yarn/cache/@types-estree-npm-0.0.51-bc20719267-e56a3bcf75.zip +0 -0
  13. package/.yarn/cache/@types-estree-npm-1.0.0-eddde5b631-910d97fb70.zip +0 -0
  14. package/.yarn/cache/@types-json-schema-npm-7.0.11-79462ae5ca-527bddfe62.zip +0 -0
  15. package/.yarn/cache/@types-node-npm-18.11.7-0cf2ce3a09-69d630825c.zip +0 -0
  16. package/.yarn/cache/@webassemblyjs-ast-npm-1.11.1-623d3d973e-1eee1534ad.zip +0 -0
  17. package/.yarn/cache/@webassemblyjs-floating-point-hex-parser-npm-1.11.1-f8af5c0037-b8efc6fa08.zip +0 -0
  18. package/.yarn/cache/@webassemblyjs-helper-api-error-npm-1.11.1-b839d59053-0792813f0e.zip +0 -0
  19. package/.yarn/cache/@webassemblyjs-helper-buffer-npm-1.11.1-6afb1ef4aa-a337ee44b4.zip +0 -0
  20. package/.yarn/cache/@webassemblyjs-helper-numbers-npm-1.11.1-a41f7439eb-44d2905dac.zip +0 -0
  21. package/.yarn/cache/@webassemblyjs-helper-wasm-bytecode-npm-1.11.1-84f0ee4c30-eac4001131.zip +0 -0
  22. package/.yarn/cache/@webassemblyjs-helper-wasm-section-npm-1.11.1-e4e8450b9d-617696cfe8.zip +0 -0
  23. package/.yarn/cache/@webassemblyjs-ieee754-npm-1.11.1-897eb85879-23a0ac02a5.zip +0 -0
  24. package/.yarn/cache/@webassemblyjs-leb128-npm-1.11.1-fd9f27673d-33ccc4ade2.zip +0 -0
  25. package/.yarn/cache/@webassemblyjs-utf8-npm-1.11.1-583036e767-972c5cfc76.zip +0 -0
  26. package/.yarn/cache/@webassemblyjs-wasm-edit-npm-1.11.1-34565c1e92-6d7d9efaec.zip +0 -0
  27. package/.yarn/cache/@webassemblyjs-wasm-gen-npm-1.11.1-a6d0b4d37d-1f6921e640.zip +0 -0
  28. package/.yarn/cache/@webassemblyjs-wasm-opt-npm-1.11.1-0bb73c20b9-21586883a2.zip +0 -0
  29. package/.yarn/cache/@webassemblyjs-wasm-parser-npm-1.11.1-cd49c51fdc-1521644065.zip +0 -0
  30. package/.yarn/cache/@webassemblyjs-wast-printer-npm-1.11.1-f1213430d6-f15ae4c244.zip +0 -0
  31. package/.yarn/cache/@webpack-cli-configtest-npm-1.2.0-728a6bf8bd-a2726cd9ec.zip +0 -0
  32. package/.yarn/cache/@webpack-cli-info-npm-1.5.0-9d9627ae19-7f56fe037c.zip +0 -0
  33. package/.yarn/cache/@webpack-cli-serve-npm-1.7.0-2869abfdb4-d475e8effa.zip +0 -0
  34. package/.yarn/cache/@xtuc-ieee754-npm-1.2.0-ec0ce4e025-ac56d4ca6e.zip +0 -0
  35. package/.yarn/cache/@xtuc-long-npm-4.2.2-37236e6d72-8ed0d477ce.zip +0 -0
  36. package/.yarn/cache/acorn-import-assertions-npm-1.8.0-e9a9d57e27-5c4cf7c850.zip +0 -0
  37. package/.yarn/cache/acorn-npm-8.8.1-20e4aea981-4079b67283.zip +0 -0
  38. package/.yarn/cache/ajv-keywords-npm-3.5.2-0e391b70e2-7dc5e59316.zip +0 -0
  39. package/.yarn/cache/ajv-npm-6.12.6-4b5105e2b2-874972efe5.zip +0 -0
  40. package/.yarn/cache/ansi-styles-npm-4.3.0-245c7d42c7-513b44c3b2.zip +0 -0
  41. package/.yarn/cache/braces-npm-3.0.2-782240b28a-e2a8e769a8.zip +0 -0
  42. package/.yarn/cache/browserslist-npm-4.21.4-7d64a96afc-4af3793704.zip +0 -0
  43. package/.yarn/cache/buffer-from-npm-1.1.2-03d2f20d7e-0448524a56.zip +0 -0
  44. package/.yarn/cache/caniuse-lite-npm-1.0.30001426-f6186ea145-e8b9c14ee3.zip +0 -0
  45. package/.yarn/cache/chalk-npm-4.1.2-ba8b67ab80-fe75c9d5c7.zip +0 -0
  46. package/.yarn/cache/chrome-trace-event-npm-1.0.3-e0ae3dcd60-cb8b1fc7e8.zip +0 -0
  47. package/.yarn/cache/clone-deep-npm-4.0.1-70adab92c8-770f912fe4.zip +0 -0
  48. package/.yarn/cache/color-convert-npm-2.0.1-79730e935b-79e6bdb9fd.zip +0 -0
  49. package/.yarn/cache/color-name-npm-1.1.4-025792b0ea-b044585952.zip +0 -0
  50. package/.yarn/cache/colorette-npm-2.0.19-f73dfe6a4e-888cf5493f.zip +0 -0
  51. package/.yarn/cache/commander-npm-2.20.3-d8dcbaa39b-ab8c07884e.zip +0 -0
  52. package/.yarn/cache/commander-npm-7.2.0-19178180f8-53501cbeee.zip +0 -0
  53. package/.yarn/cache/cross-spawn-npm-7.0.3-e4ff3e65b3-671cc7c728.zip +0 -0
  54. package/.yarn/cache/electron-to-chromium-npm-1.4.284-2fb881a7ac-be496e9dca.zip +0 -0
  55. package/.yarn/cache/enhanced-resolve-npm-5.10.0-7941304306-0bb9830704.zip +0 -0
  56. package/.yarn/cache/envinfo-npm-7.8.1-f320033691-de736c98d6.zip +0 -0
  57. package/.yarn/cache/es-module-lexer-npm-0.9.3-ff6236dadb-84bbab23c3.zip +0 -0
  58. package/.yarn/cache/escalade-npm-3.1.1-e02da076aa-a3e2a99f07.zip +0 -0
  59. package/.yarn/cache/eslint-scope-npm-5.1.1-71fe59b18a-47e4b6a3f0.zip +0 -0
  60. package/.yarn/cache/esrecurse-npm-4.3.0-10b86a887a-ebc17b1a33.zip +0 -0
  61. package/.yarn/cache/estraverse-npm-4.3.0-920a32f3c6-a6299491f9.zip +0 -0
  62. package/.yarn/cache/estraverse-npm-5.3.0-03284f8f63-072780882d.zip +0 -0
  63. package/.yarn/cache/events-npm-3.3.0-c280bc7e48-f6f487ad21.zip +0 -0
  64. package/.yarn/cache/fast-deep-equal-npm-3.1.3-790edcfcf5-e21a9d8d84.zip +0 -0
  65. package/.yarn/cache/fast-json-stable-stringify-npm-2.1.0-02e8905fda-b191531e36.zip +0 -0
  66. package/.yarn/cache/fastest-levenshtein-npm-1.0.16-192d328856-a78d44285c.zip +0 -0
  67. package/.yarn/cache/fill-range-npm-7.0.1-b8b1817caa-cc283f4e65.zip +0 -0
  68. package/.yarn/cache/find-up-npm-4.1.0-c3ccf8d855-4c172680e8.zip +0 -0
  69. package/.yarn/cache/function-bind-npm-1.1.1-b56b322ae9-b32fbaebb3.zip +0 -0
  70. package/.yarn/cache/glob-to-regexp-npm-0.4.1-cd697e0fc7-e795f4e8f0.zip +0 -0
  71. package/.yarn/cache/graceful-fs-npm-4.2.10-79c70989ca-3f109d70ae.zip +0 -0
  72. package/.yarn/cache/has-flag-npm-4.0.0-32af9f0536-261a135703.zip +0 -0
  73. package/.yarn/cache/has-npm-1.0.3-b7f00631c1-b9ad53d53b.zip +0 -0
  74. package/.yarn/cache/import-local-npm-3.1.0-8960af5e51-bfcdb63b5e.zip +0 -0
  75. package/.yarn/cache/interpret-npm-2.2.0-3603a544e1-f51efef7cb.zip +0 -0
  76. package/.yarn/cache/is-core-module-npm-2.11.0-70061e141a-f96fd490c6.zip +0 -0
  77. package/.yarn/cache/is-number-npm-7.0.0-060086935c-456ac6f8e0.zip +0 -0
  78. package/.yarn/cache/is-plain-object-npm-2.0.4-da3265d804-2a401140cf.zip +0 -0
  79. package/.yarn/cache/isexe-npm-2.0.0-b58870bd2e-26bf6c5480.zip +0 -0
  80. package/.yarn/cache/isobject-npm-3.0.1-8145901fd2-db85c4c970.zip +0 -0
  81. package/.yarn/cache/jest-worker-npm-27.5.1-1c110b5894-98cd68b696.zip +0 -0
  82. package/.yarn/cache/json-parse-even-better-errors-npm-2.3.1-144d62256e-798ed4cf33.zip +0 -0
  83. package/.yarn/cache/json-schema-traverse-npm-0.4.1-4759091693-7486074d3b.zip +0 -0
  84. package/.yarn/cache/kind-of-npm-6.0.3-ab15f36220-3ab01e7b1d.zip +0 -0
  85. package/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip +0 -0
  86. package/.yarn/cache/locate-path-npm-5.0.0-46580c43e4-83e51725e6.zip +0 -0
  87. package/.yarn/cache/lru-cache-npm-6.0.0-b4c8668fe1-f97f499f89.zip +0 -0
  88. package/.yarn/cache/merge-stream-npm-2.0.0-2ac83efea5-6fa4dcc8d8.zip +0 -0
  89. package/.yarn/cache/micromatch-npm-4.0.5-cfab5d7669-02a17b671c.zip +0 -0
  90. package/.yarn/cache/mime-db-npm-1.52.0-b5371d6fd2-0d99a03585.zip +0 -0
  91. package/.yarn/cache/mime-types-npm-2.1.35-dd9ea9f3e2-89a5b7f1de.zip +0 -0
  92. package/.yarn/cache/neo-async-npm-2.6.2-75d6902586-deac9f8d00.zip +0 -0
  93. package/.yarn/cache/node-releases-npm-2.0.6-8accb3fefb-e86a926dc9.zip +0 -0
  94. package/.yarn/cache/p-limit-npm-2.3.0-94a0310039-84ff17f1a3.zip +0 -0
  95. package/.yarn/cache/p-locate-npm-4.1.0-eec6872537-513bd14a45.zip +0 -0
  96. package/.yarn/cache/p-try-npm-2.2.0-e0390dbaf8-f8a8e9a769.zip +0 -0
  97. package/.yarn/cache/path-exists-npm-4.0.0-e9e4f63eb0-505807199d.zip +0 -0
  98. package/.yarn/cache/path-key-npm-3.1.1-0e66ea8321-55cd7a9dd4.zip +0 -0
  99. package/.yarn/cache/path-parse-npm-1.0.7-09564527b7-49abf3d811.zip +0 -0
  100. package/.yarn/cache/picocolors-npm-1.0.0-d81e0b1927-a2e8092dd8.zip +0 -0
  101. package/.yarn/cache/picomatch-npm-2.3.1-c782cfd986-050c865ce8.zip +0 -0
  102. package/.yarn/cache/pkg-dir-npm-4.2.0-2b5d0a8d32-9863e3f351.zip +0 -0
  103. package/.yarn/cache/punycode-npm-2.1.1-26eb3e15cf-823bf443c6.zip +0 -0
  104. package/.yarn/cache/randombytes-npm-2.1.0-e3da76bccf-d779499376.zip +0 -0
  105. package/.yarn/cache/rechoir-npm-0.7.1-0c7e5c1201-2a04aab4e2.zip +0 -0
  106. package/.yarn/cache/resolve-cwd-npm-3.0.0-e6f4e296bf-546e081601.zip +0 -0
  107. package/.yarn/cache/resolve-from-npm-5.0.0-15c9db4d33-4ceeb9113e.zip +0 -0
  108. package/.yarn/cache/resolve-npm-1.22.1-3980488690-07af5fc1e8.zip +0 -0
  109. package/.yarn/cache/resolve-patch-46f9469d0d-5656f4d0be.zip +0 -0
  110. package/.yarn/cache/safe-buffer-npm-5.2.1-3481c8aa9b-b99c4b41fd.zip +0 -0
  111. package/.yarn/cache/schema-utils-npm-3.1.1-8704647575-fb73f3d759.zip +0 -0
  112. package/.yarn/cache/semver-npm-7.3.8-25a996cb4f-ba9c7cbbf2.zip +0 -0
  113. package/.yarn/cache/serialize-javascript-npm-6.0.0-0bb8a3c88d-56f90b562a.zip +0 -0
  114. package/.yarn/cache/shallow-clone-npm-3.0.1-dab5873d0d-39b3dd9630.zip +0 -0
  115. package/.yarn/cache/shebang-command-npm-2.0.0-eb2b01921d-6b52fe8727.zip +0 -0
  116. package/.yarn/cache/shebang-regex-npm-3.0.0-899a0cd65e-1a2bcae50d.zip +0 -0
  117. package/.yarn/cache/source-map-npm-0.6.1-1a3621db16-59ce8640cf.zip +0 -0
  118. package/.yarn/cache/source-map-support-npm-0.5.21-09ca99e250-43e98d700d.zip +0 -0
  119. package/.yarn/cache/supports-color-npm-7.2.0-606bfcf7da-3dda818de0.zip +0 -0
  120. package/.yarn/cache/supports-color-npm-8.1.1-289e937149-c052193a7e.zip +0 -0
  121. package/.yarn/cache/supports-preserve-symlinks-flag-npm-1.0.0-f17c4d0028-53b1e247e6.zip +0 -0
  122. package/.yarn/cache/tapable-npm-2.2.1-8cf5ff3039-3b7a1b4d86.zip +0 -0
  123. package/.yarn/cache/terser-npm-5.15.1-63dec1247d-9880a1e095.zip +0 -0
  124. package/.yarn/cache/terser-webpack-plugin-npm-5.3.6-27ed5132ff-8f3448d7fd.zip +0 -0
  125. package/.yarn/cache/to-regex-range-npm-5.0.1-f1e8263b00-f76fa01b3d.zip +0 -0
  126. package/.yarn/cache/ts-loader-npm-9.4.1-379dc021ff-b8947f6d39.zip +0 -0
  127. package/.yarn/cache/typescript-npm-4.8.4-9c0a335511-3e4f061658.zip +0 -0
  128. package/.yarn/cache/typescript-patch-74ec80b1de-563a0ef47a.zip +0 -0
  129. package/.yarn/cache/update-browserslist-db-npm-1.0.10-676baf0b9f-12db73b4f6.zip +0 -0
  130. package/.yarn/cache/uri-js-npm-4.4.1-66d11cbcaf-7167432de6.zip +0 -0
  131. package/.yarn/cache/watchpack-npm-2.4.0-7ec4b9cc65-23d4bc5863.zip +0 -0
  132. package/.yarn/cache/webpack-cli-npm-4.10.0-09cee8c457-2ff5355ac3.zip +0 -0
  133. package/.yarn/cache/webpack-merge-npm-5.8.0-e3c95fdc3c-88786ab910.zip +0 -0
  134. package/.yarn/cache/webpack-npm-5.74.0-f5b838a00d-320c41369a.zip +0 -0
  135. package/.yarn/cache/webpack-sources-npm-3.2.3-6bfb5d9563-989e401b9f.zip +0 -0
  136. package/.yarn/cache/which-npm-2.0.2-320ddf72f7-1a5c563d3c.zip +0 -0
  137. package/.yarn/cache/wildcard-npm-2.0.0-baedca033a-1f4fe4c03d.zip +0 -0
  138. package/.yarn/cache/yallist-npm-4.0.0-b493d9e907-343617202a.zip +0 -0
  139. package/LICENSE +22 -0
  140. package/README.md +122 -0
  141. package/config/tsconfig.cjs.json +7 -0
  142. package/config/tsconfig.esm.json +7 -0
  143. package/config/tsconfig.types.json +8 -0
  144. package/config/tsconfig.umd.json +7 -0
  145. package/config/webpack.config.js +30 -0
  146. package/package.json +23 -0
  147. package/src/index.ts +307 -0
  148. package/src/umd.ts +4 -0
  149. package/src/utils/errors.ts +30 -0
  150. package/tools/cleanup.js +29 -0
  151. package/tsconfig.json +21 -0
package/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ root = true
2
+
3
+ [*]
4
+ end_of_line = lf
5
+ insert_final_newline = true
6
+
7
+ [*.{js,json,yml}]
8
+ charset = utf-8
9
+ indent_style = space
10
+ indent_size = 2
@@ -0,0 +1,32 @@
1
+ name: Publish Package to npmjs
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - release
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: Clone repository
13
+ uses: actions/checkout@v3
14
+
15
+ - name: Setup .npmrc file to publish to npm
16
+ uses: actions/setup-node@v3
17
+ with:
18
+ node-version: '16'
19
+ registry-url: 'https://registry.npmjs.org'
20
+
21
+ - name: Setup git identity
22
+ run: |
23
+ git config --global user.email "github@digitalsamba.com"
24
+ git config --global user.name "Digital Samba"
25
+
26
+ - name: execute yarn
27
+ run: yarn
28
+
29
+ - name: yarn publish
30
+ run: yarn publish
31
+ env:
32
+ NODE_AUTH_TOKEN: ${{ secrets.EMBEDDED_SDK_NPM_TOKEN }}
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+
2
+ MIT License
3
+
4
+ Copyright (c) 2022 Digital Samba
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,122 @@
1
+ ## Description
2
+
3
+ Digital Samba Embedded SDK - control easily with JS your iframe integration.
4
+
5
+ ### Usage with NPM
6
+
7
+ Add it to dependency list using your preferred package manager:
8
+
9
+ ```npm install @digitalsamba/embedded-sdk```
10
+
11
+ or
12
+
13
+ ```yarn install @digitalsamba/embedded-sdk```
14
+
15
+ After installation, use it in your application code using provided import:
16
+
17
+ ```js
18
+ const DigitalSambaEmbedded = require('@digitalsamba/embedded-sdk')
19
+
20
+ // or, using imports
21
+ import DigitalSambaEmbedded from '@digitalsamba/embedded-sdk'
22
+ ```
23
+
24
+ This package is written in TypeScript, so type defintitions are also available:
25
+
26
+ ```ts
27
+ import { SendMessageType, ReceiveMessageType, /* ...etc */} from '@digitalsamba/embedded-sdk'
28
+ ```
29
+
30
+ ### Initialization
31
+
32
+ Library provides alternative initialization styles. Using the class constructor you can configure it and load the frame
33
+ in one call:
34
+
35
+ ```js
36
+ const api = new DigitalSambaEmbedded(InitOptions, InstanceProperties /* optional */);
37
+ ```
38
+
39
+ or you can pre-configure the instance and then load it on-demand:
40
+
41
+ ```js
42
+ // notice `createControl` vs constructor call
43
+ const api = DigitalSambaEmbedded.createControl(InitOptions);
44
+
45
+ // ...
46
+ // when necessary, load the frame:
47
+ api.load(InstanceProperties /* optional */)
48
+ ```
49
+
50
+ ### InitOptions
51
+
52
+ `InitOptions` has the following fields:
53
+
54
+ * `root` - HTMLElement. If specified, target frame will be created within it.
55
+ * `frame` - HTMLIFrameElement to be wrapped.
56
+ * `url` - full URL to be applied as frame src. Must include protocol and `token` query param for private rooms;
57
+ * `team` - team name string
58
+ * `room` - room identifier string
59
+ * `token` - optional string, for private rooms
60
+
61
+ To successfuly initialize an instance of the wrapper one of following combinations needs to be used:
62
+
63
+ * `root + team + room` - will create a controlled frame inside `root` element
64
+ * `frame + team + room` - will attach to existing frame
65
+ * `frame` - will attach to existing frame (assuming you've manually specified correct frame src)
66
+ * `root + url` - will create a frame inside `root` element
67
+
68
+ Remember to always specify `allow="camera; microphone; display-capture; autoplay;"` and `allowFullscreen="true"` attributes on iframe if you want to wrap around an existing iframe.
69
+
70
+ ### InstanceProperties
71
+
72
+ * `frameAttributes` - list of attributes to be applied to target iframe
73
+ * `reportErrors` - boolean, false by default. Whether to report misconfiguration or runtime errors to console
74
+
75
+ ### Usage
76
+
77
+ To listen for events, attach listener for any of supported events:
78
+
79
+ ```js
80
+ api.on('*', (data) => {
81
+ console.log(data)
82
+ });
83
+
84
+
85
+ api.on('userJoined', (data) => {
86
+ // ...
87
+ });
88
+ ```
89
+ Also see `dist/index.html` for more examples.
90
+
91
+ To send commands, api instance provides handy utilities:
92
+
93
+ ```js
94
+ api.toggleVideo();
95
+ // ...
96
+ api.disableAudio();
97
+ ```
98
+
99
+ ---
100
+
101
+ ### Available events:
102
+
103
+ * `connected`
104
+ * `userJoined`
105
+ * `userLeft`
106
+ * `videoEnabled`
107
+ * `videoDisabled`
108
+ * `audioEnabled`
109
+ * `audioDisabled`
110
+ * `screenshareStarted`
111
+ * `screenshareStopped`
112
+
113
+ ### Available commands:
114
+
115
+ * `enableVideo()`
116
+ * `disableVideo()`
117
+ * `toggleVideo(newState?: boolean)`
118
+ * `enableAudio()`
119
+ * `disableAudio()`
120
+ * `toggleAudio(newState?: boolean)`
121
+ * `startScreenshare()`
122
+ * `stopScreenshare()`
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../tsconfig",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "outDir": "../dist/cjs"
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../tsconfig",
3
+ "compilerOptions": {
4
+ "module": "ESNext",
5
+ "outDir": "../dist/esm"
6
+ }
7
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../tsconfig",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "emitDeclarationOnly": true,
6
+ "outDir": "../dist/types"
7
+ }
8
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../tsconfig",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "declaration": false
6
+ }
7
+ }
@@ -0,0 +1,30 @@
1
+ const path = require("path");
2
+
3
+ module.exports = {
4
+ mode: "production",
5
+ entry: "./src/umd.ts",
6
+ output: {
7
+ path: path.resolve(__dirname, "../dist/umd"),
8
+ filename: "index.js",
9
+ library: "DigitalSambaEmbedded",
10
+ libraryTarget: "umd",
11
+ globalObject: "this",
12
+ },
13
+ module: {
14
+ rules: [
15
+ {
16
+ test: /\.ts(x*)?$/,
17
+ exclude: /node_modules/,
18
+ use: {
19
+ loader: "ts-loader",
20
+ options: {
21
+ configFile: "config/tsconfig.umd.json",
22
+ },
23
+ },
24
+ },
25
+ ],
26
+ },
27
+ resolve: {
28
+ extensions: [".ts", ".js", ".tsx", ".jsx"],
29
+ },
30
+ };
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@digitalsamba/embedded-sdk",
3
+ "packageManager": "yarn@3.1.0",
4
+ "version": "0.0.1",
5
+ "license" : "BSD-2-Clause",
6
+ "scripts": {
7
+ "build": "npm run build:cjs && npm run build:esm && npm run build:umd && npm run build:types",
8
+ "build:cjs": "node tools/cleanup cjs && tsc -p config/tsconfig.cjs.json",
9
+ "build:esm": "node tools/cleanup esm && tsc -p config/tsconfig.esm.json",
10
+ "build:umd": "node tools/cleanup umd && webpack --config config/webpack.config.js",
11
+ "build:types": "node tools/cleanup types && tsc -p config/tsconfig.types.json"
12
+ },
13
+ "main": "dist/cjs/index.js",
14
+ "module": "dist/esm/index.js",
15
+ "umd:main": "dist/umd/index.js",
16
+ "types": "dist/types/index.d.js",
17
+ "devDependencies": {
18
+ "ts-loader": "^9.4.1",
19
+ "typescript": "^4.8.3",
20
+ "webpack": "^5.74.0",
21
+ "webpack-cli": "^4.10.0"
22
+ }
23
+ }
package/src/index.ts ADDED
@@ -0,0 +1,307 @@
1
+ import {
2
+ ALLOW_ATTRIBUTE_MISSING,
3
+ INVALID_CONFIG,
4
+ INVALID_URL,
5
+ RichError,
6
+ UNKNOWN_TARGET,
7
+ } from "./utils/errors";
8
+
9
+ export interface InitOptions {
10
+ root: HTMLElement;
11
+ frame: HTMLIFrameElement;
12
+
13
+ url: string;
14
+ team: string;
15
+ room: string;
16
+ token?: string;
17
+ }
18
+
19
+ export type FrameAttributes = {
20
+ align: string;
21
+ allow: string;
22
+ allowFullscreen: boolean;
23
+ frameBorder: string;
24
+ height: string;
25
+ longDesc: string;
26
+ marginHeight: string;
27
+ marginWidth: string;
28
+ name: string;
29
+ referrerPolicy: ReferrerPolicy;
30
+ scrolling: string;
31
+ src: string;
32
+ srcdoc: string;
33
+ width: string;
34
+ } & HTMLElement;
35
+
36
+ export interface InstanceProperties {
37
+ frameAttributes?: Partial<FrameAttributes>;
38
+ reportErrors?: boolean;
39
+ }
40
+
41
+ const CONNECT_TIMEOUT = 5000;
42
+
43
+ export type SendMessageType =
44
+ | "connect"
45
+ | "enableVideo"
46
+ | "enableAudio"
47
+ | "disableVideo"
48
+ | "disableAudio"
49
+ | "toggleVideo"
50
+ | "toggleAudio"
51
+ | "startScreenshare"
52
+ | "stopScreenshare";
53
+
54
+ export type ReceiveMessageType =
55
+ | "connected"
56
+ | "userJoined"
57
+ | "userLeft"
58
+ | "videoEnabled"
59
+ | "videoDisabled"
60
+ | "audioEnabled"
61
+ | "audioDisabled"
62
+ | "screenshareStarted"
63
+ | "screenshareStopped";
64
+
65
+ export interface SendMessage<P> {
66
+ type: SendMessageType;
67
+ payload?: P;
68
+ }
69
+
70
+ export interface ReceiveMessage {
71
+ type: ReceiveMessageType;
72
+ payload: unknown;
73
+ }
74
+
75
+ function isFunction(func: any): func is (payload: any) => void {
76
+ return func instanceof Function;
77
+ }
78
+
79
+ export class DigitalSambaEmbedded {
80
+ initOptions: Partial<InitOptions>;
81
+
82
+ savedIframeSrc: string = "";
83
+
84
+ allowedOrigin: string = "*";
85
+
86
+ connected: boolean = false;
87
+
88
+ frame: HTMLIFrameElement = document.createElement("iframe");
89
+
90
+ eventHandlers: Partial<
91
+ Record<ReceiveMessageType | "*", (payload: any) => void>
92
+ > = {};
93
+
94
+ reportErrors: boolean = false;
95
+
96
+ constructor(
97
+ options: Partial<InitOptions> = {},
98
+ instanceProperties: Partial<InstanceProperties> = {},
99
+ loadImmediately = true
100
+ ) {
101
+ this.initOptions = options;
102
+
103
+ this.frame.allow = "camera; microphone; display-capture; autoplay;";
104
+ this.frame.setAttribute("allowFullscreen", "true");
105
+
106
+ this.mountFrame(loadImmediately);
107
+
108
+ if (loadImmediately) {
109
+ this.load(instanceProperties);
110
+ } else {
111
+ this.frame.style.display = "none";
112
+ }
113
+
114
+ window.addEventListener("message", this.onMessage);
115
+ }
116
+
117
+ static createControl = (initOptions: InitOptions) => {
118
+ return new this(initOptions, {}, false);
119
+ };
120
+
121
+ private mountFrame = (loadImmediately: boolean) => {
122
+ const { url, frame, root } = this.initOptions;
123
+
124
+ if (root) {
125
+ root.appendChild(this.frame);
126
+ } else if (frame) {
127
+ this.frame = frame;
128
+
129
+ if (!frame.allow) {
130
+ this.logError(ALLOW_ATTRIBUTE_MISSING);
131
+ }
132
+ } else {
133
+ document.body.appendChild(this.frame);
134
+ }
135
+
136
+ if (url) {
137
+ try {
138
+ const frameSrc = new URL(url).toString();
139
+
140
+ this.frame.src = frameSrc;
141
+ this.savedIframeSrc = frameSrc;
142
+ } catch {
143
+ this.logError(INVALID_URL);
144
+ }
145
+ }
146
+
147
+ if (!loadImmediately) {
148
+ this.savedIframeSrc = this.frame.src;
149
+ this.frame.src = "";
150
+ }
151
+ };
152
+
153
+ load = (instanceProperties: InstanceProperties = {}) => {
154
+ this.reportErrors = instanceProperties.reportErrors || false;
155
+
156
+ this.setFrameSrc();
157
+
158
+ this.applyFrameProperties(instanceProperties);
159
+
160
+ this.frame.style.display = "block";
161
+ };
162
+
163
+ on = (type: ReceiveMessageType, handler: (payload: any) => void) => {
164
+ this.eventHandlers[type] = handler;
165
+ };
166
+
167
+ private onMessage = (event: MessageEvent<ReceiveMessage>) => {
168
+ // if (event.origin !== this.allowedOrigin) {
169
+ // // ignore messages from other sources;
170
+ // return;
171
+ // }
172
+
173
+ if (typeof this.eventHandlers["*"] === "function") {
174
+ this.eventHandlers["*"](event.data);
175
+ }
176
+
177
+ if (event.data.type) {
178
+ const callback = this.eventHandlers[event.data.type];
179
+
180
+ if (isFunction(callback)) {
181
+ callback(event.data);
182
+ }
183
+ }
184
+ };
185
+
186
+ private setFrameSrc = () => {
187
+ let url = this.savedIframeSrc;
188
+ const { team, room, token } = this.initOptions;
189
+
190
+ if (team && room) {
191
+ url = `https://${team}.digitalsamba.com/${room}`;
192
+ if (token) {
193
+ const params = new URLSearchParams({ token });
194
+
195
+ url = `${url}?${params}`;
196
+ }
197
+
198
+ this.frame.src = url;
199
+ } else {
200
+ this.logError(INVALID_CONFIG);
201
+ return;
202
+ }
203
+
204
+ const allowedURL = new URL(this.frame.src);
205
+
206
+ this.allowedOrigin = allowedURL.origin;
207
+
208
+ this.frame.onload = () => this.checkTarget();
209
+ };
210
+
211
+ private checkTarget() {
212
+ this.sendMessage({ type: "connect" });
213
+
214
+ const confirmationTimeout = window.setTimeout(() => {
215
+ this.logError(UNKNOWN_TARGET);
216
+ }, CONNECT_TIMEOUT);
217
+
218
+ this.on("connected", () => {
219
+ this.connected = true;
220
+ clearTimeout(confirmationTimeout);
221
+ });
222
+ }
223
+
224
+ private sendMessage<G>(message: SendMessage<G>) {
225
+ if (this.frame.contentWindow) {
226
+ this.frame.contentWindow.postMessage(message, {
227
+ targetOrigin: this.allowedOrigin,
228
+ });
229
+ }
230
+ }
231
+
232
+ private logError = (error: RichError) => {
233
+ if (this.reportErrors) {
234
+ throw error;
235
+ }
236
+ };
237
+
238
+ private applyFrameProperties = (
239
+ instanceProperties: Partial<InstanceProperties>
240
+ ) => {
241
+ if (instanceProperties.frameAttributes) {
242
+ // TODO: only allow specific attrs here; This is a heck to support
243
+ Object.entries(instanceProperties.frameAttributes).forEach(
244
+ ([attr, value]) => {
245
+ if (value !== null && typeof value !== "undefined") {
246
+ this.frame.setAttribute(attr, value.toString());
247
+ } else {
248
+ this.frame.removeAttribute(attr);
249
+ }
250
+ }
251
+ );
252
+ }
253
+
254
+ if (instanceProperties.reportErrors) {
255
+ this.reportErrors = true;
256
+ }
257
+ };
258
+
259
+ // commands
260
+ enableVideo = () => {
261
+ this.sendMessage({ type: "enableVideo" });
262
+ };
263
+
264
+ disableVideo = () => {
265
+ this.sendMessage({ type: "disableVideo" });
266
+ };
267
+
268
+ toggleVideo = (enable?: boolean) => {
269
+ if (typeof enable === "undefined") {
270
+ this.sendMessage({ type: "toggleVideo" });
271
+ } else {
272
+ if (enable) {
273
+ this.enableVideo();
274
+ } else {
275
+ this.disableVideo();
276
+ }
277
+ }
278
+ };
279
+
280
+ enableAudio = () => {
281
+ this.sendMessage({ type: "enableAudio" });
282
+ };
283
+
284
+ disableAudio = () => {
285
+ this.sendMessage({ type: "disableAudio" });
286
+ };
287
+
288
+ toggleAudio = (enable?: boolean) => {
289
+ if (typeof enable === "undefined") {
290
+ this.sendMessage({ type: "toggleAudio" });
291
+ } else {
292
+ if (enable) {
293
+ this.enableAudio();
294
+ } else {
295
+ this.disableAudio();
296
+ }
297
+ }
298
+ };
299
+
300
+ startScreenshare = () => {
301
+ this.sendMessage({ type: "startScreenshare" });
302
+ };
303
+
304
+ stopScreenshare = () => {
305
+ this.sendMessage({ type: "stopScreenshare" });
306
+ };
307
+ }
package/src/umd.ts ADDED
@@ -0,0 +1,4 @@
1
+ import {DigitalSambaEmbedded} from './index';
2
+
3
+ // compatibility with script tag
4
+ module.exports = DigitalSambaEmbedded
@@ -0,0 +1,30 @@
1
+ export class RichError extends Error {
2
+ constructor(error: { name: string; message: string }) {
3
+ super(error.message);
4
+
5
+ this.name = error.name;
6
+ }
7
+ }
8
+
9
+ export const UNKNOWN_TARGET = new RichError({
10
+ name: "UNKNOWN_TARGET",
11
+ message:
12
+ "Could not verify the identity of target frame. Commands may not work",
13
+ });
14
+
15
+ export const INVALID_CONFIG = new RichError({
16
+ name: "INVALID_INIT_CONFIG",
17
+ message: "Initializations options are invalid. Missing team name or room ID",
18
+ });
19
+
20
+ export const ALLOW_ATTRIBUTE_MISSING = new RichError({
21
+ name: "ALLOW_ATTRIBUTE_MISSING",
22
+ message:
23
+ "You've provided a frame that is mising 'allow' attribute. Some functionality may not work.",
24
+ });
25
+
26
+
27
+ export const INVALID_URL = new RichError({
28
+ name: "INVALID_URL",
29
+ message: "Invalid frame url specified"
30
+ })
@@ -0,0 +1,29 @@
1
+ /* eslint-disable */
2
+ const fs = require("fs");
3
+ const Path = require("path");
4
+ /* eslint-enable */
5
+
6
+ const deleteFolderRecursive = (path) => {
7
+ if (fs.existsSync(path)) {
8
+ fs.readdirSync(path).forEach((file) => {
9
+ const curPath = Path.join(path, file);
10
+ if (fs.lstatSync(curPath).isDirectory()) {
11
+ deleteFolderRecursive(curPath);
12
+ } else {
13
+ fs.unlinkSync(curPath);
14
+ }
15
+ });
16
+ fs.rmdirSync(path);
17
+ }
18
+ };
19
+
20
+ const folder = process.argv.slice(2)[0];
21
+
22
+ if (folder) {
23
+ deleteFolderRecursive(Path.join(__dirname, "../dist", folder));
24
+ } else {
25
+ deleteFolderRecursive(Path.join(__dirname, "../dist/cjs"));
26
+ deleteFolderRecursive(Path.join(__dirname, "../dist/esm"));
27
+ deleteFolderRecursive(Path.join(__dirname, "../dist/umd"));
28
+ deleteFolderRecursive(Path.join(__dirname, "../dist/types"));
29
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es5",
4
+ "declaration": true,
5
+ "allowJs": true,
6
+ "incremental": true,
7
+ "downlevelIteration": true,
8
+ "strict": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "module": "commonjs",
11
+ "resolveJsonModule": true,
12
+ "isolatedModules": false,
13
+ "jsx": "react-jsx",
14
+ "noImplicitAny": true,
15
+ "outDir": "./dist",
16
+ "esModuleInterop": true,
17
+ "moduleResolution": "node",
18
+ },
19
+ "include": ["./src/**/*"],
20
+ "exclude": ["node_modules"]
21
+ }