@digitalsamba/embedded-sdk 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.d.ts +66 -0
- package/dist/cjs/index.js +214 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/cjs/umd.d.ts +1 -0
- package/dist/cjs/umd.js +5 -0
- package/dist/cjs/utils/errors.d.ts +10 -0
- package/dist/cjs/utils/errors.js +44 -0
- package/dist/esm/index.d.ts +66 -0
- package/dist/esm/index.js +211 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/esm/umd.d.ts +1 -0
- package/dist/esm/umd.js +3 -0
- package/dist/esm/utils/errors.d.ts +10 -0
- package/dist/esm/utils/errors.js +41 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.html +83 -0
- package/dist/index.js +194 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +66 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -0
- package/dist/types/umd.d.ts +1 -0
- package/dist/types/utils/errors.d.ts +10 -0
- package/dist/umd/index.js +1 -0
- package/dist/utils/errors.d.ts +1 -0
- package/dist/utils/errors.js +4 -0
- package/package.json +1 -1
@@ -0,0 +1,211 @@
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
3
|
+
if (!m) return o;
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
5
|
+
try {
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
7
|
+
}
|
8
|
+
catch (error) { e = { error: error }; }
|
9
|
+
finally {
|
10
|
+
try {
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
12
|
+
}
|
13
|
+
finally { if (e) throw e.error; }
|
14
|
+
}
|
15
|
+
return ar;
|
16
|
+
};
|
17
|
+
import { ALLOW_ATTRIBUTE_MISSING, INVALID_CONFIG, INVALID_URL, UNKNOWN_TARGET, } from "./utils/errors";
|
18
|
+
var CONNECT_TIMEOUT = 5000;
|
19
|
+
function isFunction(func) {
|
20
|
+
return func instanceof Function;
|
21
|
+
}
|
22
|
+
var DigitalSambaEmbedded = /** @class */ (function () {
|
23
|
+
function DigitalSambaEmbedded(options, instanceProperties, loadImmediately) {
|
24
|
+
if (options === void 0) { options = {}; }
|
25
|
+
if (instanceProperties === void 0) { instanceProperties = {}; }
|
26
|
+
if (loadImmediately === void 0) { loadImmediately = true; }
|
27
|
+
var _this = this;
|
28
|
+
this.savedIframeSrc = "";
|
29
|
+
this.allowedOrigin = "*";
|
30
|
+
this.connected = false;
|
31
|
+
this.frame = document.createElement("iframe");
|
32
|
+
this.eventHandlers = {};
|
33
|
+
this.reportErrors = false;
|
34
|
+
this.mountFrame = function (loadImmediately) {
|
35
|
+
var _b = _this.initOptions, url = _b.url, frame = _b.frame, root = _b.root;
|
36
|
+
if (root) {
|
37
|
+
root.appendChild(_this.frame);
|
38
|
+
}
|
39
|
+
else if (frame) {
|
40
|
+
_this.frame = frame;
|
41
|
+
if (!frame.allow) {
|
42
|
+
_this.logError(ALLOW_ATTRIBUTE_MISSING);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
document.body.appendChild(_this.frame);
|
47
|
+
}
|
48
|
+
if (url) {
|
49
|
+
try {
|
50
|
+
var frameSrc = new URL(url).toString();
|
51
|
+
_this.frame.src = frameSrc;
|
52
|
+
_this.savedIframeSrc = frameSrc;
|
53
|
+
}
|
54
|
+
catch (_c) {
|
55
|
+
_this.logError(INVALID_URL);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
if (!loadImmediately) {
|
59
|
+
_this.savedIframeSrc = _this.frame.src;
|
60
|
+
_this.frame.src = "";
|
61
|
+
}
|
62
|
+
};
|
63
|
+
this.load = function (instanceProperties) {
|
64
|
+
if (instanceProperties === void 0) { instanceProperties = {}; }
|
65
|
+
_this.reportErrors = instanceProperties.reportErrors || false;
|
66
|
+
_this.setFrameSrc();
|
67
|
+
_this.applyFrameProperties(instanceProperties);
|
68
|
+
_this.frame.style.display = "block";
|
69
|
+
};
|
70
|
+
this.on = function (type, handler) {
|
71
|
+
_this.eventHandlers[type] = handler;
|
72
|
+
};
|
73
|
+
this.onMessage = function (event) {
|
74
|
+
// if (event.origin !== this.allowedOrigin) {
|
75
|
+
// // ignore messages from other sources;
|
76
|
+
// return;
|
77
|
+
// }
|
78
|
+
if (typeof _this.eventHandlers["*"] === "function") {
|
79
|
+
_this.eventHandlers["*"](event.data);
|
80
|
+
}
|
81
|
+
if (event.data.type) {
|
82
|
+
var callback = _this.eventHandlers[event.data.type];
|
83
|
+
if (isFunction(callback)) {
|
84
|
+
callback(event.data);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
};
|
88
|
+
this.setFrameSrc = function () {
|
89
|
+
var url = _this.savedIframeSrc;
|
90
|
+
var _b = _this.initOptions, team = _b.team, room = _b.room, token = _b.token;
|
91
|
+
if (team && room) {
|
92
|
+
url = "https://".concat(team, ".digitalsamba.com/").concat(room);
|
93
|
+
if (token) {
|
94
|
+
var params = new URLSearchParams({ token: token });
|
95
|
+
url = "".concat(url, "?").concat(params);
|
96
|
+
}
|
97
|
+
_this.frame.src = url;
|
98
|
+
}
|
99
|
+
else {
|
100
|
+
_this.logError(INVALID_CONFIG);
|
101
|
+
return;
|
102
|
+
}
|
103
|
+
var allowedURL = new URL(_this.frame.src);
|
104
|
+
_this.allowedOrigin = allowedURL.origin;
|
105
|
+
_this.frame.onload = function () { return _this.checkTarget(); };
|
106
|
+
};
|
107
|
+
this.logError = function (error) {
|
108
|
+
if (_this.reportErrors) {
|
109
|
+
throw error;
|
110
|
+
}
|
111
|
+
};
|
112
|
+
this.applyFrameProperties = function (instanceProperties) {
|
113
|
+
if (instanceProperties.frameAttributes) {
|
114
|
+
// TODO: only allow specific attrs here; This is a heck to support
|
115
|
+
Object.entries(instanceProperties.frameAttributes).forEach(function (_b) {
|
116
|
+
var _c = __read(_b, 2), attr = _c[0], value = _c[1];
|
117
|
+
if (value !== null && typeof value !== "undefined") {
|
118
|
+
_this.frame.setAttribute(attr, value.toString());
|
119
|
+
}
|
120
|
+
else {
|
121
|
+
_this.frame.removeAttribute(attr);
|
122
|
+
}
|
123
|
+
});
|
124
|
+
}
|
125
|
+
if (instanceProperties.reportErrors) {
|
126
|
+
_this.reportErrors = true;
|
127
|
+
}
|
128
|
+
};
|
129
|
+
// commands
|
130
|
+
this.enableVideo = function () {
|
131
|
+
_this.sendMessage({ type: "enableVideo" });
|
132
|
+
};
|
133
|
+
this.disableVideo = function () {
|
134
|
+
_this.sendMessage({ type: "disableVideo" });
|
135
|
+
};
|
136
|
+
this.toggleVideo = function (enable) {
|
137
|
+
if (typeof enable === "undefined") {
|
138
|
+
_this.sendMessage({ type: "toggleVideo" });
|
139
|
+
}
|
140
|
+
else {
|
141
|
+
if (enable) {
|
142
|
+
_this.enableVideo();
|
143
|
+
}
|
144
|
+
else {
|
145
|
+
_this.disableVideo();
|
146
|
+
}
|
147
|
+
}
|
148
|
+
};
|
149
|
+
this.enableAudio = function () {
|
150
|
+
_this.sendMessage({ type: "enableAudio" });
|
151
|
+
};
|
152
|
+
this.disableAudio = function () {
|
153
|
+
_this.sendMessage({ type: "disableAudio" });
|
154
|
+
};
|
155
|
+
this.toggleAudio = function (enable) {
|
156
|
+
if (typeof enable === "undefined") {
|
157
|
+
_this.sendMessage({ type: "toggleAudio" });
|
158
|
+
}
|
159
|
+
else {
|
160
|
+
if (enable) {
|
161
|
+
_this.enableAudio();
|
162
|
+
}
|
163
|
+
else {
|
164
|
+
_this.disableAudio();
|
165
|
+
}
|
166
|
+
}
|
167
|
+
};
|
168
|
+
this.startScreenshare = function () {
|
169
|
+
_this.sendMessage({ type: "startScreenshare" });
|
170
|
+
};
|
171
|
+
this.stopScreenshare = function () {
|
172
|
+
_this.sendMessage({ type: "stopScreenshare" });
|
173
|
+
};
|
174
|
+
this.initOptions = options;
|
175
|
+
this.frame.allow = "camera; microphone; display-capture; autoplay;";
|
176
|
+
this.frame.setAttribute("allowFullscreen", "true");
|
177
|
+
this.mountFrame(loadImmediately);
|
178
|
+
if (loadImmediately) {
|
179
|
+
this.load(instanceProperties);
|
180
|
+
}
|
181
|
+
else {
|
182
|
+
this.frame.style.display = "none";
|
183
|
+
}
|
184
|
+
window.addEventListener("message", this.onMessage);
|
185
|
+
}
|
186
|
+
DigitalSambaEmbedded.prototype.checkTarget = function () {
|
187
|
+
var _this = this;
|
188
|
+
this.sendMessage({ type: "connect" });
|
189
|
+
var confirmationTimeout = window.setTimeout(function () {
|
190
|
+
_this.logError(UNKNOWN_TARGET);
|
191
|
+
}, CONNECT_TIMEOUT);
|
192
|
+
this.on("connected", function () {
|
193
|
+
_this.connected = true;
|
194
|
+
clearTimeout(confirmationTimeout);
|
195
|
+
});
|
196
|
+
};
|
197
|
+
DigitalSambaEmbedded.prototype.sendMessage = function (message) {
|
198
|
+
if (this.frame.contentWindow) {
|
199
|
+
this.frame.contentWindow.postMessage(message, {
|
200
|
+
targetOrigin: this.allowedOrigin,
|
201
|
+
});
|
202
|
+
}
|
203
|
+
};
|
204
|
+
var _a;
|
205
|
+
_a = DigitalSambaEmbedded;
|
206
|
+
DigitalSambaEmbedded.createControl = function (initOptions) {
|
207
|
+
return new _a(initOptions, {}, false);
|
208
|
+
};
|
209
|
+
return DigitalSambaEmbedded;
|
210
|
+
}());
|
211
|
+
export { DigitalSambaEmbedded };
|
@@ -0,0 +1 @@
|
|
1
|
+
{"program":{"fileNames":["../../node_modules/typescript/lib/lib.d.ts","../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.es2020.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../../node_modules/typescript/lib/lib.scripthost.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../../node_modules/@types/react/global.d.ts","../../../node_modules/csstype/index.d.ts","../../../node_modules/@types/prop-types/index.d.ts","../../../node_modules/@types/scheduler/tracing.d.ts","../../../node_modules/@types/react/index.d.ts","../../../node_modules/@types/react/jsx-runtime.d.ts","../../src/utils/errors.ts","../../src/index.ts","../../src/umd.ts","../../node_modules/@types/eslint/helpers.d.ts","../../node_modules/@types/estree/index.d.ts","../../node_modules/@types/json-schema/index.d.ts","../../node_modules/@types/eslint/index.d.ts","../../node_modules/@types/eslint-scope/index.d.ts","../../node_modules/@types/node/ts4.8/assert.d.ts","../../node_modules/@types/node/ts4.8/assert/strict.d.ts","../../node_modules/@types/node/ts4.8/globals.d.ts","../../node_modules/@types/node/ts4.8/async_hooks.d.ts","../../node_modules/@types/node/ts4.8/buffer.d.ts","../../node_modules/@types/node/ts4.8/child_process.d.ts","../../node_modules/@types/node/ts4.8/cluster.d.ts","../../node_modules/@types/node/ts4.8/console.d.ts","../../node_modules/@types/node/ts4.8/constants.d.ts","../../node_modules/@types/node/ts4.8/crypto.d.ts","../../node_modules/@types/node/ts4.8/dgram.d.ts","../../node_modules/@types/node/ts4.8/diagnostics_channel.d.ts","../../node_modules/@types/node/ts4.8/dns.d.ts","../../node_modules/@types/node/ts4.8/dns/promises.d.ts","../../node_modules/@types/node/ts4.8/domain.d.ts","../../node_modules/@types/node/ts4.8/dom-events.d.ts","../../node_modules/@types/node/ts4.8/events.d.ts","../../node_modules/@types/node/ts4.8/fs.d.ts","../../node_modules/@types/node/ts4.8/fs/promises.d.ts","../../node_modules/@types/node/ts4.8/http.d.ts","../../node_modules/@types/node/ts4.8/http2.d.ts","../../node_modules/@types/node/ts4.8/https.d.ts","../../node_modules/@types/node/ts4.8/inspector.d.ts","../../node_modules/@types/node/ts4.8/module.d.ts","../../node_modules/@types/node/ts4.8/net.d.ts","../../node_modules/@types/node/ts4.8/os.d.ts","../../node_modules/@types/node/ts4.8/path.d.ts","../../node_modules/@types/node/ts4.8/perf_hooks.d.ts","../../node_modules/@types/node/ts4.8/process.d.ts","../../node_modules/@types/node/ts4.8/punycode.d.ts","../../node_modules/@types/node/ts4.8/querystring.d.ts","../../node_modules/@types/node/ts4.8/readline.d.ts","../../node_modules/@types/node/ts4.8/readline/promises.d.ts","../../node_modules/@types/node/ts4.8/repl.d.ts","../../node_modules/@types/node/ts4.8/stream.d.ts","../../node_modules/@types/node/ts4.8/stream/promises.d.ts","../../node_modules/@types/node/ts4.8/stream/consumers.d.ts","../../node_modules/@types/node/ts4.8/stream/web.d.ts","../../node_modules/@types/node/ts4.8/string_decoder.d.ts","../../node_modules/@types/node/ts4.8/test.d.ts","../../node_modules/@types/node/ts4.8/timers.d.ts","../../node_modules/@types/node/ts4.8/timers/promises.d.ts","../../node_modules/@types/node/ts4.8/tls.d.ts","../../node_modules/@types/node/ts4.8/trace_events.d.ts","../../node_modules/@types/node/ts4.8/tty.d.ts","../../node_modules/@types/node/ts4.8/url.d.ts","../../node_modules/@types/node/ts4.8/util.d.ts","../../node_modules/@types/node/ts4.8/v8.d.ts","../../node_modules/@types/node/ts4.8/vm.d.ts","../../node_modules/@types/node/ts4.8/wasi.d.ts","../../node_modules/@types/node/ts4.8/worker_threads.d.ts","../../node_modules/@types/node/ts4.8/zlib.d.ts","../../node_modules/@types/node/ts4.8/globals.global.d.ts","../../node_modules/@types/node/ts4.8/index.d.ts","../../../node_modules/@types/hoist-non-react-statics/index.d.ts","../../../node_modules/redux/index.d.ts","../../../node_modules/@types/react-redux/index.d.ts","../../../node_modules/@types/scheduler/index.d.ts"],"fileInfos":["2dc8c927c9c162a773c6bb3cdc4f3286c23f10eedc67414028f9cb5951610f60",{"version":"f20c05dbfe50a208301d2a1da37b9931bce0466eb5a1f4fe240971b4ecc82b67","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","1fc5ab7a764205c68fa10d381b08417795fc73111d6dd16b5b1ed36badb743d9",{"version":"9b087de7268e4efc5f215347a62656663933d63c0b1d7b624913240367b999ea","affectsGlobalScope":true},{"version":"7fac8cb5fc820bc2a59ae11ef1c5b38d3832c6d0dfaec5acdb5569137d09a481","affectsGlobalScope":true},{"version":"097a57355ded99c68e6df1b738990448e0bf170e606707df5a7c0481ff2427cd","affectsGlobalScope":true},{"version":"adb996790133eb33b33aadb9c09f15c2c575e71fb57a62de8bf74dbf59ec7dfb","affectsGlobalScope":true},{"version":"8cc8c5a3bac513368b0157f3d8b31cfdcfe78b56d3724f30f80ed9715e404af8","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"55f400eec64d17e888e278f4def2f254b41b89515d3b88ad75d5e05f019daddd","affectsGlobalScope":true},{"version":"181f1784c6c10b751631b24ce60c7f78b20665db4550b335be179217bacc0d5f","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"81cac4cbc92c0c839c70f8ffb94eb61e2d32dc1c3cf6d95844ca099463cf37ea","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"09aa50414b80c023553090e2f53827f007a301bc34b0495bfb2c3c08ab9ad1eb","affectsGlobalScope":true},{"version":"d7f680a43f8cd12a6b6122c07c54ba40952b0c8aa140dcfcf32eb9e6cb028596","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"775d9c9fd150d5de79e0450f35bc8b8f94ae64e3eb5da12725ff2a649dccc777","affectsGlobalScope":true},{"version":"b248e32ca52e8f5571390a4142558ae4f203ae2f94d5bac38a3084d529ef4e58","affectsGlobalScope":true},{"version":"52d1bb7ab7a3306fd0375c8bff560feed26ed676a5b0457fa8027b563aecb9a4","affectsGlobalScope":true},{"version":"ecf78e637f710f340ec08d5d92b3f31b134a46a4fcf2e758690d8c46ce62cba6","affectsGlobalScope":true},"5b1d4ebd62d975c7d3826202f8fac290bac0bae6e04d9e84d1707d7047e108df","f7b46d22a307739c145e5fddf537818038fdfffd580d79ed717f4d4d37249380","f5a8b384f182b3851cec3596ccc96cb7464f8d3469f48c74bf2befb782a19de5",{"version":"b0e7534cd480e87b0976a4454e81d93ae31564f78a7068a7356408fe0c86f93e","affectsGlobalScope":true},"af7fd2870746deed40e130fc0a3966de74e8f52a97ec114d0fbb35876ab05ca9",{"version":"7b2f9eda59965cd1371e202b7e38b9b607594a1b3c6780751c2d2539f57b2be0","signature":"ba5b6ffe369d5c5b3d9daca09423b3c551e37ae2a6fe7cabb5ca3b80c7be065c"},{"version":"765ed20d0ffc8d0923d4b6b11805478bc675cc72adf467b506fd31fd42381f45","signature":"6ea3069543908661b7867695bb35b81b39efe235b747fd932408e7e16fe5fce1"},{"version":"682bd958f5237705f6613d4bb9446f31b551eb83f4e6e0b69c05e07cc4f6c105","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"64d4b35c5456adf258d2cf56c341e203a073253f229ef3208fc0d5020253b241","affectsGlobalScope":true},"946bd1737d9412395a8f24414c70f18660b84a75a12b0b448e6eb1a2161d06dd","f3e604694b624fa3f83f6684185452992088f5efb2cf136b62474aa106d6f1b6","12269db43308334832b46233ce4d19e6c8b6453cb4877b081341184ee9a1700d","e050a0afcdbb269720a900c85076d18e0c1ab73e580202a2bf6964978181222a","7e771891adaa85b690266bc37bd6eb43bc57eecc4b54693ead36467e7369952a","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"02873d070f9cb79f50833fbf4a9a27ac578a2edf8ddb8421eba1b37faba83bfb","affectsGlobalScope":true},"21a167fec8f933752fb8157f06d28fab6817af3ad9b0bdb1908a10762391eab9",{"version":"c0db280fa6b09d7b8d6720a19a47f485956a41ee0e6914f1b704033eb69c6058","affectsGlobalScope":true},"0c0cee62cb619aed81133b904f644515ba3064487002a7da83fd8aa07b1b4abd","5a94487653355b56018122d92392beb2e5f4a6c63ba5cef83bbe1c99775ef713",{"version":"d5135ad93b33adcce80b18f8065087934cdc1730d63db58562edcf017e1aad9b","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","dd1d8b922bd0874a7715e43015ebfe4ce1eb55fbe405a6d97b7c9756dc608813","bb9c4ffa5e6290c6980b63c815cdd1625876dadb2efaf77edbe82984be93e55e","75ecef44f126e2ae018b4abbd85b6e8a2e2ba1638ebec56cc64274643ce3567b","f30bb836526d930a74593f7b0f5c1c46d10856415a8f69e5e2fc3db80371e362","14b5aa23c5d0ae1907bc696ac7b6915d88f7d85799cc0dc2dcf98fbce2c5a67c","5c439dafdc09abe4d6c260a96b822fa0ba5be7203c71a63ab1f1423cd9e838ea",{"version":"6b526a5ec4a401ca7c26cfe6a48e641d8f30af76673bad3b06a1b4504594a960","affectsGlobalScope":true},{"version":"816ad2e607a96de5bcac7d437f843f5afd8957f1fa5eefa6bba8e4ed7ca8fd84","affectsGlobalScope":true},"cec36af22f514322f870e81d30675c78df82ae8bf4863f5fd4e4424c040c678d","d903fafe96674bc0b2ac38a5be4a8fc07b14c2548d1cdb165a80ea24c44c0c54","b01a80007e448d035a16c74b5c95a5405b2e81b12fabcf18b75aa9eb9ef28990","04eb6578a588d6a46f50299b55f30e3a04ef27d0c5a46c57d8fcc211cd530faa","dbe5aa5a5dd8bd1c6a8d11b1310c3f0cdabaacc78a37b394a8c7b14faeb5fb84","2c828a5405191d006115ab34e191b8474bc6c86ffdc401d1a9864b1b6e088a58",{"version":"e8b18c6385ff784228a6f369694fcf1a6b475355ba89090a88de13587a9391d5","affectsGlobalScope":true},"d4ac44f01d42f541631c5fc88d0ed8efac29a3a3ad9a745d9fd58f8b61ed132e","7c013aa892414a7fdcfd861ae524a668eaa3ede8c7c0acafaf611948122c8d93","b0973c3cbcdc59b37bf477731d468696ecaf442593ec51bab497a613a580fe30",{"version":"4989e92ba5b69b182d2caaea6295af52b7dc73a4f7a2e336a676722884e7139d","affectsGlobalScope":true},{"version":"b3624aed92dab6da8484280d3cb3e2f4130ec3f4ef3f8201c95144ae9e898bb6","affectsGlobalScope":true},"5153a2fd150e46ce57bb3f8db1318d33f6ad3261ed70ceeff92281c0608c74a3","210d54cd652ec0fec8c8916e4af59bb341065576ecda039842f9ffb2e908507c","36b03690b628eab08703d63f04eaa89c5df202e5f1edf3989f13ad389cd2c091","0effadd232a20498b11308058e334d3339cc5bf8c4c858393e38d9d4c0013dcf","25846d43937c672bab7e8195f3d881f93495df712ee901860effc109918938cc","3163f47436da41706c6e2b3c1511f3b7cce9f9f3905b2f3e01246c48b4ba7d14","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff","69ee23dd0d215b09907ad30d23f88b7790c93329d1faf31d7835552a10cf7cbf","44b8b584a338b190a59f4f6929d072431950c7bd92ec2694821c11bce180c8a5","23b89798789dffbd437c0c423f5d02d11f9736aea73d6abf16db4f812ff36eda","24ad30a03d6c9266b63540956868dd70fa2dc523d60d780d6586eb0c281946bc",{"version":"970a90f76d4d219ad60819d61f5994514087ba94c985647a3474a5a3d12714ed","affectsGlobalScope":true},"664d8f2d59164f2e08c543981453893bc7e003e4dfd29651ce09db13e9457980","4c8525f256873c7ba3135338c647eaf0ca7115a1a2805ae2d0056629461186ce","3c13ef48634e7b5012fcf7e8fce7496352c2d779a7201389ca96a2a81ee4314d","5d0a25ec910fa36595f85a67ac992d7a53dd4064a1ba6aea1c9f14ab73a023f2",{"version":"f0900cd5d00fe1263ff41201fb8073dbeb984397e4af3b8002a5c207a30bdc33","affectsGlobalScope":true},{"version":"f7db71191aa7aac5d6bc927ed6e7075c2763d22c7238227ec0c63c8cf5cb6a8b","affectsGlobalScope":true},"06d7c42d256f0ce6afe1b2b6cfbc97ab391f29dadb00dd0ae8e8f23f5bc916c3","ec4bd1b200670fb567920db572d6701ed42a9641d09c4ff6869768c8f81b404c","e59a892d87e72733e2a9ca21611b9beb52977be2696c7ba4b216cbbb9a48f5aa",{"version":"da26af7362f53d122283bc69fed862b9a9fe27e01bc6a69d1d682e0e5a4df3e6","affectsGlobalScope":true},"8a300fa9b698845a1f9c41ecbe2c5966634582a8e2020d51abcace9b55aa959e",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"652ee9c5103e89102d87bc20d167a02a0e3e5e53665674466c8cfea8a9e418c7","bfe1b52cf71aea9bf8815810cc5d9490fa9617313e3d3c2ee3809a28b80d0bb4",{"version":"d530250769a14518ebd6edda5b5f94abaaf3b9f612363c0da32082fa6acd0da8","affectsGlobalScope":true},"4370c91e46f6992a89e3979c50434cf932088e1b5ae6e3a5214d778634dea768","74b0245c42990ed8a849df955db3f4362c81b13f799ebc981b7bec2d5b414a57"],"options":{"declaration":true,"downlevelIteration":true,"esModuleInterop":true,"jsx":4,"module":99,"noImplicitAny":true,"outDir":"./","strict":true,"target":1},"fileIdsList":[[55,57,105],[105],[54,55,56,105],[59,105],[62,105],[63,68,96,105],[64,75,76,83,93,104,105],[64,65,75,83,105],[66,105],[67,68,76,84,105],[68,93,101,105],[69,71,75,83,105],[70,105],[71,72,105],[75,105],[73,75,105],[75,76,77,93,104,105],[75,76,77,90,93,96,105],[105,109],[78,83,93,104,105],[75,76,78,79,83,93,101,104,105],[78,80,93,101,104,105],[59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111],[75,81,105],[82,104,105],[71,75,83,93,105],[84,105],[85,105],[62,86,105],[87,103,105,109],[88,105],[89,105],[75,90,91,105],[90,92,105,107],[63,75,93,94,95,96,105],[63,93,95,105],[93,94,105],[96,105],[97,105],[75,99,100,105],[99,100,105],[68,83,93,101,105],[102,105],[83,103,105],[63,78,89,104,105],[68,105],[93,105,106],[105,107],[105,108],[63,68,75,77,86,93,104,105,107,109],[93,105,110],[50,51,105],[50,52,105],[50,105],[49,105],[49,105,113,114],[45,46,47,48,105]],"referencedMap":[[58,1],[54,2],[57,3],[55,2],[56,2],[59,4],[60,4],[62,5],[63,6],[64,7],[65,8],[66,9],[67,10],[68,11],[69,12],[70,13],[71,14],[72,14],[74,15],[73,16],[75,15],[76,17],[77,18],[61,19],[111,2],[78,20],[79,21],[80,22],[112,23],[81,24],[82,25],[83,26],[84,27],[85,28],[86,29],[87,30],[88,31],[89,32],[90,33],[91,33],[92,34],[93,35],[95,36],[94,37],[96,38],[97,39],[98,2],[99,40],[100,41],[101,42],[102,43],[103,44],[104,45],[105,46],[106,47],[107,48],[108,49],[109,50],[110,51],[1,2],[9,2],[13,2],[12,2],[3,2],[14,2],[15,2],[16,2],[17,2],[18,2],[19,2],[20,2],[21,2],[4,2],[5,2],[25,2],[22,2],[23,2],[24,2],[26,2],[27,2],[28,2],[6,2],[29,2],[30,2],[31,2],[32,2],[7,2],[33,2],[34,2],[35,2],[36,2],[8,2],[37,2],[42,2],[43,2],[38,2],[39,2],[40,2],[41,2],[2,2],[44,2],[11,2],[10,2],[52,52],[53,53],[51,54],[113,55],[47,2],[115,56],[45,2],[49,57],[50,55],[116,2],[48,2],[46,2],[114,2]],"exportedModulesMap":[[58,1],[54,2],[57,3],[55,2],[56,2],[59,4],[60,4],[62,5],[63,6],[64,7],[65,8],[66,9],[67,10],[68,11],[69,12],[70,13],[71,14],[72,14],[74,15],[73,16],[75,15],[76,17],[77,18],[61,19],[111,2],[78,20],[79,21],[80,22],[112,23],[81,24],[82,25],[83,26],[84,27],[85,28],[86,29],[87,30],[88,31],[89,32],[90,33],[91,33],[92,34],[93,35],[95,36],[94,37],[96,38],[97,39],[98,2],[99,40],[100,41],[101,42],[102,43],[103,44],[104,45],[105,46],[106,47],[107,48],[108,49],[109,50],[110,51],[1,2],[9,2],[13,2],[12,2],[3,2],[14,2],[15,2],[16,2],[17,2],[18,2],[19,2],[20,2],[21,2],[4,2],[5,2],[25,2],[22,2],[23,2],[24,2],[26,2],[27,2],[28,2],[6,2],[29,2],[30,2],[31,2],[32,2],[7,2],[33,2],[34,2],[35,2],[36,2],[8,2],[37,2],[42,2],[43,2],[38,2],[39,2],[40,2],[41,2],[2,2],[44,2],[11,2],[10,2],[113,55],[47,2],[115,56],[45,2],[49,57],[50,55],[116,2],[48,2],[46,2],[114,2]],"semanticDiagnosticsPerFile":[58,54,57,55,56,59,60,62,63,64,65,66,67,68,69,70,71,72,74,73,75,76,77,61,111,78,79,80,112,81,82,83,84,85,86,87,88,89,90,91,92,93,95,94,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,1,9,13,12,3,14,15,16,17,18,19,20,21,4,5,25,22,23,24,26,27,28,6,29,30,31,32,7,33,34,35,36,8,37,42,43,38,39,40,41,2,44,11,10,52,53,51,113,47,115,45,49,50,116,48,46,114]},"version":"4.8.4"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/esm/umd.js
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
export declare class RichError extends Error {
|
2
|
+
constructor(error: {
|
3
|
+
name: string;
|
4
|
+
message: string;
|
5
|
+
});
|
6
|
+
}
|
7
|
+
export declare const UNKNOWN_TARGET: RichError;
|
8
|
+
export declare const INVALID_CONFIG: RichError;
|
9
|
+
export declare const ALLOW_ATTRIBUTE_MISSING: RichError;
|
10
|
+
export declare const INVALID_URL: RichError;
|
@@ -0,0 +1,41 @@
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
2
|
+
var extendStatics = function (d, b) {
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
6
|
+
return extendStatics(d, b);
|
7
|
+
};
|
8
|
+
return function (d, b) {
|
9
|
+
if (typeof b !== "function" && b !== null)
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
11
|
+
extendStatics(d, b);
|
12
|
+
function __() { this.constructor = d; }
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14
|
+
};
|
15
|
+
})();
|
16
|
+
var RichError = /** @class */ (function (_super) {
|
17
|
+
__extends(RichError, _super);
|
18
|
+
function RichError(error) {
|
19
|
+
var _this = _super.call(this, error.message) || this;
|
20
|
+
_this.name = error.name;
|
21
|
+
return _this;
|
22
|
+
}
|
23
|
+
return RichError;
|
24
|
+
}(Error));
|
25
|
+
export { RichError };
|
26
|
+
export var UNKNOWN_TARGET = new RichError({
|
27
|
+
name: "UNKNOWN_TARGET",
|
28
|
+
message: "Could not verify the identity of target frame. Commands may not work",
|
29
|
+
});
|
30
|
+
export var INVALID_CONFIG = new RichError({
|
31
|
+
name: "INVALID_INIT_CONFIG",
|
32
|
+
message: "Initializations options are invalid. Missing team name or room ID",
|
33
|
+
});
|
34
|
+
export var ALLOW_ATTRIBUTE_MISSING = new RichError({
|
35
|
+
name: "ALLOW_ATTRIBUTE_MISSING",
|
36
|
+
message: "You've provided a frame that is mising 'allow' attribute. Some functionality may not work.",
|
37
|
+
});
|
38
|
+
export var INVALID_URL = new RichError({
|
39
|
+
name: "INVALID_URL",
|
40
|
+
message: "Invalid frame url specified"
|
41
|
+
});
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
declare const INVALID_CONFIG = "Initializations options are invalid. Missing team name or room ID";
|
2
|
+
interface InitOptions {
|
3
|
+
root: HTMLElement;
|
4
|
+
frame: HTMLIFrameElement;
|
5
|
+
url: string;
|
6
|
+
team: string;
|
7
|
+
room: string;
|
8
|
+
token?: string;
|
9
|
+
}
|
10
|
+
declare type FrameAttributes = {
|
11
|
+
align: string;
|
12
|
+
allow: string;
|
13
|
+
allowFullscreen: boolean;
|
14
|
+
frameBorder: string;
|
15
|
+
height: string;
|
16
|
+
longDesc: string;
|
17
|
+
marginHeight: string;
|
18
|
+
marginWidth: string;
|
19
|
+
name: string;
|
20
|
+
referrerPolicy: ReferrerPolicy;
|
21
|
+
scrolling: string;
|
22
|
+
src: string;
|
23
|
+
srcdoc: string;
|
24
|
+
width: string;
|
25
|
+
} & HTMLElement;
|
26
|
+
interface InstanceProperties {
|
27
|
+
frameAttributes?: Partial<FrameAttributes>;
|
28
|
+
reportErrors?: boolean;
|
29
|
+
}
|
30
|
+
declare const CONNECT_TIMEOUT = 5000;
|
31
|
+
declare type SendMessageType = "connect" | "enableVideo" | "enableAudio" | "disableVideo" | "disableAudio" | "toggleVideo" | "toggleAudio";
|
32
|
+
declare type ReceiveMessageType = "connected" | "userJoined" | "userLeft" | "videoEnabled" | "videoDisabled" | "audioEnabled" | "audioDisabled";
|
33
|
+
interface SendMessage<P> {
|
34
|
+
type: SendMessageType;
|
35
|
+
payload?: P;
|
36
|
+
}
|
37
|
+
interface ReceiveMessage {
|
38
|
+
type: ReceiveMessageType;
|
39
|
+
payload: unknown;
|
40
|
+
}
|
41
|
+
declare function isFunction(func: any): func is (payload: any) => void;
|
42
|
+
declare class DigitalSambaEmbedded {
|
43
|
+
initOptions: Partial<InitOptions>;
|
44
|
+
savedIframeSrc: string;
|
45
|
+
allowedOrigin: string;
|
46
|
+
connected: boolean;
|
47
|
+
frame: HTMLIFrameElement;
|
48
|
+
eventHandlers: Partial<Record<ReceiveMessageType | "*", (payload: any) => void>>;
|
49
|
+
reportErrors: boolean;
|
50
|
+
constructor(options?: Partial<InitOptions>, instanceProperties?: Partial<InstanceProperties>, loadImmediately?: boolean);
|
51
|
+
static createControl: (initOptions: InitOptions) => DigitalSambaEmbedded;
|
52
|
+
private mountFrame;
|
53
|
+
load: (instanceProperties?: InstanceProperties) => void;
|
54
|
+
on: (type: ReceiveMessageType, handler: (payload: any) => void) => void;
|
55
|
+
enableVideo: () => void;
|
56
|
+
disableVideo: () => void;
|
57
|
+
toggleVideo: (enable?: boolean) => void;
|
58
|
+
enableAudio: () => void;
|
59
|
+
disableAudio: () => void;
|
60
|
+
toggleAudio: (enable?: boolean) => void;
|
61
|
+
private onMessage;
|
62
|
+
private setFrameSrc;
|
63
|
+
private checkTarget;
|
64
|
+
private sendMessage;
|
65
|
+
private logError;
|
66
|
+
private applyFrameProperties;
|
67
|
+
}
|
package/dist/index.html
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
7
|
+
<title>Document</title>
|
8
|
+
<script src="https://unpkg.com/@digitalsamba/embedded-sdk@0.0.1"></script>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<div class="ifp" style="display: flex">
|
12
|
+
|
13
|
+
<!--<iframe allow="camera; microphone; display-capture; autoplay;" src="https://localhost:3000/Public" class="if"></iframe>-->
|
14
|
+
|
15
|
+
<div class="log">
|
16
|
+
|
17
|
+
</div>
|
18
|
+
|
19
|
+
</div>
|
20
|
+
<div class="div" style=" border: 1px solid yellow">
|
21
|
+
<button class="c0" style="margin-right: 15px; border: 2px solid blue">LOAD</button>
|
22
|
+
<button class="c1">toggleVideo</button>
|
23
|
+
<button class="c2">enableVideo</button>
|
24
|
+
<button class="c3">disableVideo</button>
|
25
|
+
<button class="c4">toggleAudio</button>
|
26
|
+
<button class="c5">enableAudio</button>
|
27
|
+
<button class="c6">disableAudio</button>
|
28
|
+
<button class="c7">startScreenshare</button>
|
29
|
+
<button class="c8">stopScreenshare</button>
|
30
|
+
</div>
|
31
|
+
<script async defer>
|
32
|
+
const parent = document.querySelector('.isfp');
|
33
|
+
const frame = document.querySelector('.if');
|
34
|
+
const btn0 = document.querySelector('.c0');
|
35
|
+
const btn1 = document.querySelector('.c1');
|
36
|
+
const btn2 = document.querySelector('.c2');
|
37
|
+
const btn3 = document.querySelector('.c3');
|
38
|
+
const btn4 = document.querySelector('.c4');
|
39
|
+
const btn5 = document.querySelector('.c5');
|
40
|
+
const btn6 = document.querySelector('.c6');
|
41
|
+
const btn7 = document.querySelector('.c7');
|
42
|
+
const btn8 = document.querySelector('.c8');
|
43
|
+
|
44
|
+
const api = new DigitalSambaEmbedded({ root: parent, team: 'alex.dev.monza', room: 'Public' });
|
45
|
+
//const api = new DigitalSambaEmbedded({ frame});
|
46
|
+
//const api = new DigitalSambaEmbedded({ url: 'https://localhost:3000/Public'}, {reportErrors: true});
|
47
|
+
|
48
|
+
//const api = DigitalSambaEmbedded.createControl({ url: 'https://localhost:3000/Public'});
|
49
|
+
|
50
|
+
const log = document.querySelector('.log');
|
51
|
+
|
52
|
+
api.frame.width = 700;
|
53
|
+
api.frame.height = 500;
|
54
|
+
|
55
|
+
btn0.onclick = () => {api.load({ frameAttributes: {style: "border: 5px solid red"}, reportErrors: true })}
|
56
|
+
btn1.onclick = () => {api.toggleVideo()}
|
57
|
+
btn2.onclick = () => {api.enableVideo()}
|
58
|
+
btn3.onclick = () => {api.disableVideo()}
|
59
|
+
btn4.onclick = () => {api.toggleAudio()}
|
60
|
+
btn5.onclick = () => {api.enableAudio()}
|
61
|
+
btn6.onclick = () => {api.disableAudio()}
|
62
|
+
btn7.onclick = () => {api.startScreenshare()}
|
63
|
+
btn8.onclick = () => {api.stopScreenshare()}
|
64
|
+
|
65
|
+
api.on('*', (data) => {
|
66
|
+
log.innerHTML += `<p>${Number(new Date)}: ev(${data.type}): ${JSON.stringify(data)}</p>`
|
67
|
+
});
|
68
|
+
|
69
|
+
|
70
|
+
api.on('userJoined', (data) => {
|
71
|
+
log.innerHTML += `<p>${Number(new Date)}: USER JOINED: ${JSON.stringify(data)}</p>`
|
72
|
+
});
|
73
|
+
|
74
|
+
api.on('userLeft', (data) => {
|
75
|
+
log.innerHTML += `<p>${Number(new Date)}: USER JOINED: ${JSON.stringify(data)}</p>`
|
76
|
+
});
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
</script>
|
81
|
+
|
82
|
+
</body>
|
83
|
+
</html>
|
package/dist/index.js
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
4
|
+
if (!m) return o;
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
6
|
+
try {
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
8
|
+
}
|
9
|
+
catch (error) { e = { error: error }; }
|
10
|
+
finally {
|
11
|
+
try {
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
13
|
+
}
|
14
|
+
finally { if (e) throw e.error; }
|
15
|
+
}
|
16
|
+
return ar;
|
17
|
+
};
|
18
|
+
var INVALID_CONFIG = "Initializations options are invalid. Missing team name or room ID";
|
19
|
+
var CONNECT_TIMEOUT = 5000;
|
20
|
+
function isFunction(func) {
|
21
|
+
return func instanceof Function;
|
22
|
+
}
|
23
|
+
var DigitalSambaEmbedded = /** @class */ (function () {
|
24
|
+
function DigitalSambaEmbedded(options, instanceProperties, loadImmediately) {
|
25
|
+
if (options === void 0) { options = {}; }
|
26
|
+
if (instanceProperties === void 0) { instanceProperties = {}; }
|
27
|
+
if (loadImmediately === void 0) { loadImmediately = true; }
|
28
|
+
var _this = this;
|
29
|
+
this.savedIframeSrc = "";
|
30
|
+
this.allowedOrigin = "";
|
31
|
+
this.connected = false;
|
32
|
+
this.frame = document.createElement("iframe");
|
33
|
+
this.eventHandlers = {};
|
34
|
+
this.reportErrors = false;
|
35
|
+
this.mountFrame = function (loadImmediately) {
|
36
|
+
var _b = _this.initOptions, frame = _b.frame, root = _b.root;
|
37
|
+
if (root) {
|
38
|
+
root.appendChild(_this.frame);
|
39
|
+
}
|
40
|
+
else if (frame) {
|
41
|
+
_this.frame = frame;
|
42
|
+
if (!loadImmediately) {
|
43
|
+
_this.savedIframeSrc = _this.frame.src;
|
44
|
+
_this.frame.src = "";
|
45
|
+
}
|
46
|
+
}
|
47
|
+
else {
|
48
|
+
document.body.appendChild(_this.frame);
|
49
|
+
}
|
50
|
+
};
|
51
|
+
this.load = function (instanceProperties) {
|
52
|
+
if (instanceProperties === void 0) { instanceProperties = {}; }
|
53
|
+
_this.reportErrors = instanceProperties.reportErrors || false;
|
54
|
+
_this.setFrameSrc();
|
55
|
+
_this.applyFrameProperties(instanceProperties);
|
56
|
+
_this.frame.style.display = "block";
|
57
|
+
};
|
58
|
+
this.on = function (type, handler) {
|
59
|
+
_this.eventHandlers[type] = handler;
|
60
|
+
};
|
61
|
+
// commands
|
62
|
+
this.enableVideo = function () {
|
63
|
+
_this.sendMessage({ type: "enableVideo" });
|
64
|
+
};
|
65
|
+
this.disableVideo = function () {
|
66
|
+
_this.sendMessage({ type: "disableVideo" });
|
67
|
+
};
|
68
|
+
this.toggleVideo = function (enable) {
|
69
|
+
if (typeof enable === "undefined") {
|
70
|
+
_this.sendMessage({ type: "toggleVideo" });
|
71
|
+
}
|
72
|
+
else {
|
73
|
+
if (enable) {
|
74
|
+
_this.enableVideo();
|
75
|
+
}
|
76
|
+
else {
|
77
|
+
_this.disableVideo();
|
78
|
+
}
|
79
|
+
}
|
80
|
+
};
|
81
|
+
this.enableAudio = function () {
|
82
|
+
_this.sendMessage({ type: "enableAudio" });
|
83
|
+
};
|
84
|
+
this.disableAudio = function () {
|
85
|
+
_this.sendMessage({ type: "disableAudio" });
|
86
|
+
};
|
87
|
+
this.toggleAudio = function (enable) {
|
88
|
+
if (typeof enable === "undefined") {
|
89
|
+
_this.sendMessage({ type: "toggleAudio" });
|
90
|
+
}
|
91
|
+
else {
|
92
|
+
if (enable) {
|
93
|
+
_this.enableAudio();
|
94
|
+
}
|
95
|
+
else {
|
96
|
+
_this.disableAudio();
|
97
|
+
}
|
98
|
+
}
|
99
|
+
};
|
100
|
+
this.onMessage = function (event) {
|
101
|
+
if (event.origin !== _this.allowedOrigin) {
|
102
|
+
// ignore messages from other sources;
|
103
|
+
return;
|
104
|
+
}
|
105
|
+
if (typeof _this.eventHandlers["*"] === "function") {
|
106
|
+
_this.eventHandlers["*"](event.data);
|
107
|
+
}
|
108
|
+
if (event.data.type) {
|
109
|
+
var callback = _this.eventHandlers[event.data.type];
|
110
|
+
if (isFunction(callback)) {
|
111
|
+
callback(event.data);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
};
|
115
|
+
this.setFrameSrc = function () {
|
116
|
+
if (_this.savedIframeSrc) {
|
117
|
+
_this.frame.src = _this.savedIframeSrc;
|
118
|
+
return;
|
119
|
+
}
|
120
|
+
var _b = _this.initOptions, team = _b.team, room = _b.room, token = _b.token;
|
121
|
+
if (team && room) {
|
122
|
+
var url = "https://".concat(team, ".digitalsamba.com/").concat(room);
|
123
|
+
if (token) {
|
124
|
+
var params = new URLSearchParams({ token: token });
|
125
|
+
url = "".concat(url, "?").concat(params);
|
126
|
+
}
|
127
|
+
_this.frame.src = url;
|
128
|
+
var allowedURL = new URL(url);
|
129
|
+
_this.allowedOrigin = allowedURL.origin;
|
130
|
+
}
|
131
|
+
else {
|
132
|
+
_this.logError(INVALID_CONFIG);
|
133
|
+
}
|
134
|
+
};
|
135
|
+
this.logError = function (message) {
|
136
|
+
if (_this.reportErrors) {
|
137
|
+
throw new Error(message);
|
138
|
+
}
|
139
|
+
};
|
140
|
+
this.applyFrameProperties = function (instanceProperties) {
|
141
|
+
_this.frame.setAttribute("allow", "camera; microphone; display-capture; autoplay;");
|
142
|
+
_this.frame.setAttribute("allowFullscreen", "true");
|
143
|
+
if (instanceProperties.frameAttributes) {
|
144
|
+
// TODO: only allow specific attrs here; This is a heck to support
|
145
|
+
Object.entries(instanceProperties.frameAttributes).forEach(function (_b) {
|
146
|
+
var _c = __read(_b, 2), attr = _c[0], value = _c[1];
|
147
|
+
if (value !== null && typeof value !== "undefined") {
|
148
|
+
_this.frame.setAttribute(attr, value.toString());
|
149
|
+
}
|
150
|
+
else {
|
151
|
+
_this.frame.removeAttribute(attr);
|
152
|
+
}
|
153
|
+
});
|
154
|
+
}
|
155
|
+
if (instanceProperties.reportErrors) {
|
156
|
+
_this.reportErrors = true;
|
157
|
+
}
|
158
|
+
};
|
159
|
+
this.initOptions = options;
|
160
|
+
this.mountFrame(loadImmediately);
|
161
|
+
if (loadImmediately) {
|
162
|
+
this.load(instanceProperties);
|
163
|
+
}
|
164
|
+
else {
|
165
|
+
this.frame.style.display = "none";
|
166
|
+
}
|
167
|
+
this.frame.onload = function () { return _this.checkTarget(); };
|
168
|
+
window.addEventListener("message", this.onMessage);
|
169
|
+
}
|
170
|
+
DigitalSambaEmbedded.prototype.checkTarget = function () {
|
171
|
+
var _this = this;
|
172
|
+
this.sendMessage({ type: "connect" });
|
173
|
+
var confirmationTimeout = window.setTimeout(function () {
|
174
|
+
_this.logError("Could not verify target frame identity. Commands may not work");
|
175
|
+
}, CONNECT_TIMEOUT);
|
176
|
+
this.on("connected", function () {
|
177
|
+
_this.connected = true;
|
178
|
+
clearTimeout(confirmationTimeout);
|
179
|
+
});
|
180
|
+
};
|
181
|
+
DigitalSambaEmbedded.prototype.sendMessage = function (message) {
|
182
|
+
if (this.frame.contentWindow) {
|
183
|
+
this.frame.contentWindow.postMessage(message, this.allowedOrigin);
|
184
|
+
}
|
185
|
+
};
|
186
|
+
var _a;
|
187
|
+
_a = DigitalSambaEmbedded;
|
188
|
+
DigitalSambaEmbedded.createControl = function (initOptions) {
|
189
|
+
return new _a(initOptions, {}, false);
|
190
|
+
};
|
191
|
+
return DigitalSambaEmbedded;
|
192
|
+
}());
|
193
|
+
// @ts-ignore
|
194
|
+
window.DigitalSambaEmbedded = DigitalSambaEmbedded;
|