@whereby.com/core 0.2.0-beta.0

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.
@@ -0,0 +1,29 @@
1
+ declare function fakeAudioStream(): MediaStream;
2
+
3
+ declare function fakeWebcamFrame(canvas: HTMLCanvasElement): void;
4
+
5
+ interface Options {
6
+ delay?: number;
7
+ edges?: boolean;
8
+ }
9
+ interface DebouncedFunction {
10
+ (...args: any[]): void;
11
+ }
12
+ /**
13
+ * Debounce function.
14
+ *
15
+ * @param {Function} fn - Function to debounce.
16
+ * @param {Object} [options] - Options.
17
+ * @param {number} [options.delay=500] - Delay in milliseconds.
18
+ * @param {boolean} [options.edges=false] - Whether to call the function on the
19
+ * leading and trailing edges of the wait timeout.
20
+ * @returns {Function} Debounced function.
21
+ */
22
+ declare function debounce(fn: DebouncedFunction, { delay, edges }?: Options): DebouncedFunction;
23
+
24
+ declare function parseRoomUrlAndSubdomain(roomAttribute?: string, subdomainAttribute?: string): {
25
+ subdomain: string;
26
+ roomUrl: URL;
27
+ };
28
+
29
+ export { debounce, fakeAudioStream, fakeWebcamFrame, parseRoomUrlAndSubdomain };
package/dist/utils.js ADDED
@@ -0,0 +1,91 @@
1
+ export { d as debounce } from './debounce-IlgXge5U.js';
2
+
3
+ function fakeAudioStream() {
4
+ const audioCtx = new AudioContext();
5
+ const oscillator = audioCtx.createOscillator();
6
+ const destination = audioCtx.createMediaStreamDestination();
7
+ oscillator.connect(destination);
8
+ oscillator.frequency.value = 400;
9
+ oscillator.type = "sine";
10
+ setInterval(() => {
11
+ if (oscillator.frequency.value <= 900) {
12
+ oscillator.frequency.value += 10;
13
+ }
14
+ else {
15
+ oscillator.frequency.value = 200;
16
+ }
17
+ }, 20);
18
+ oscillator.start();
19
+ return destination.stream;
20
+ }
21
+
22
+ let rotationAngle = 0;
23
+ function drawWebcamFrame(canvas) {
24
+ const context = canvas.getContext("2d");
25
+ if (!context) {
26
+ console.error("Canvas context not available");
27
+ return;
28
+ }
29
+ const wheelRadius = 100;
30
+ const wheelCenterX = canvas.width / 2;
31
+ const wheelCenterY = canvas.height / 2;
32
+ context.fillStyle = "darkgreen";
33
+ context.fillRect(0, 0, canvas.width, canvas.height);
34
+ context.save();
35
+ context.translate(wheelCenterX, wheelCenterY);
36
+ context.rotate(rotationAngle);
37
+ const numSlices = 12;
38
+ const sliceAngle = (2 * Math.PI) / numSlices;
39
+ const colors = ["red", "orange", "yellow", "green", "blue", "purple"];
40
+ for (let i = 0; i < numSlices; i++) {
41
+ context.beginPath();
42
+ context.moveTo(0, 0);
43
+ context.arc(0, 0, wheelRadius, i * sliceAngle, (i + 1) * sliceAngle);
44
+ context.fillStyle = colors[i % colors.length];
45
+ context.fill();
46
+ context.closePath();
47
+ }
48
+ context.restore();
49
+ context.fillStyle = "white";
50
+ context.font = "42px Arial";
51
+ const topText = "Whereby Media Stream";
52
+ const topTextWidth = context.measureText(topText).width;
53
+ context.fillText(topText, canvas.width / 2 - topTextWidth / 2, 50);
54
+ context.font = "32px Arial";
55
+ const now = new Date();
56
+ const timeText = `time: ${now.getHours().toString().padStart(2, "0")}:${now
57
+ .getMinutes()
58
+ .toString()
59
+ .padStart(2, "0")}:${now.getSeconds().toString().padStart(2, "0")}.${now
60
+ .getMilliseconds()
61
+ .toString()
62
+ .padStart(3, "0")}`;
63
+ context.fillText(timeText, 10, canvas.height - 20);
64
+ context.fillText(`rotation angle: ${rotationAngle.toFixed(2)}`, canvas.width - canvas.width / 2, canvas.height - 20);
65
+ rotationAngle += 0.01;
66
+ }
67
+ function fakeWebcamFrame(canvas) {
68
+ drawWebcamFrame(canvas);
69
+ requestAnimationFrame(() => fakeWebcamFrame(canvas));
70
+ }
71
+
72
+ function parseRoomUrlAndSubdomain(roomAttribute, subdomainAttribute) {
73
+ if (!roomAttribute) {
74
+ throw new Error("Missing room attribute");
75
+ }
76
+ const m = /https:\/\/([^.]+)(\.whereby\.com|-ip-\d+-\d+-\d+-\d+.hereby.dev:4443)\/.+/.exec(roomAttribute);
77
+ const subdomain = (m && m[1]) || subdomainAttribute;
78
+ if (!subdomain) {
79
+ throw new Error("Missing subdomain attribute");
80
+ }
81
+ if (!m) {
82
+ throw new Error("Could not parse room URL");
83
+ }
84
+ const roomUrl = new URL(roomAttribute);
85
+ return {
86
+ subdomain,
87
+ roomUrl,
88
+ };
89
+ }
90
+
91
+ export { fakeAudioStream, fakeWebcamFrame, parseRoomUrlAndSubdomain };
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@whereby.com/core",
3
+ "description": "Core library for whereby.com sdk",
4
+ "author": "Whereby AS",
5
+ "version": "0.2.0-beta.0",
6
+ "license": "MIT",
7
+ "scripts": {
8
+ "build": "rimraf dist && rollup -c rollup.config.js",
9
+ "test": "yarn test:lint && yarn test:unit",
10
+ "test:lint": "eslint src/",
11
+ "test:unit": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js",
12
+ "test:unit:watch": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js --watch"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "files": [
18
+ "dist/*.js",
19
+ "dist/*.d.ts"
20
+ ],
21
+ "exports": {
22
+ ".": {
23
+ "import": "./dist/index.js",
24
+ "types": "./dist/index.d.ts"
25
+ },
26
+ "./utils": {
27
+ "import": "./dist/utils.js",
28
+ "types": "./dist/utils.d.ts"
29
+ }
30
+ },
31
+ "types": "dist/index.d.ts",
32
+ "typesVersions": {
33
+ "*": {
34
+ "*": [
35
+ "dist/index.d.ts"
36
+ ],
37
+ "utils": [
38
+ "dist/utils.d.ts"
39
+ ]
40
+ }
41
+ },
42
+ "devDependencies": {
43
+ "@rollup/plugin-commonjs": "^25.0.7",
44
+ "@rollup/plugin-node-resolve": "^15.2.3",
45
+ "@rollup/plugin-replace": "^5.0.5",
46
+ "@types/btoa": "^1.2.3",
47
+ "@types/node": "^20.11.16",
48
+ "@types/uuid": "^9.0.7",
49
+ "deep-object-diff": "^1.1.9",
50
+ "dotenv": "^16.3.1",
51
+ "dotenv-run-script": "^0.4.1",
52
+ "rimraf": "^3.0.2",
53
+ "rollup": "^4.3.0",
54
+ "rollup-plugin-dts": "^6.1.0",
55
+ "rollup-plugin-polyfill-node": "^0.13.0",
56
+ "rollup-plugin-terser": "^7.0.2",
57
+ "rollup-plugin-typescript2": "^0.36.0",
58
+ "tslib": "^2.4.1",
59
+ "uuid": "^9.0.1",
60
+ "yalc": "^1.0.0-pre.53"
61
+ },
62
+ "dependencies": {
63
+ "@reduxjs/toolkit": "^2.0.1",
64
+ "@swc/helpers": "^0.3.13",
65
+ "@whereby/jslib-media": "whereby/jslib-media.git#1.4.1",
66
+ "axios": "^1.2.3",
67
+ "btoa": "^1.2.1",
68
+ "events": "^3.3.0"
69
+ }
70
+ }