@whereby.com/core 0.0.0-canary-20240402133911

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,19 @@
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
+ declare function debounce(fn: DebouncedFunction, { delay, edges }?: Options): DebouncedFunction;
13
+
14
+ declare function parseRoomUrlAndSubdomain(roomAttribute?: string, subdomainAttribute?: string): {
15
+ subdomain: string;
16
+ roomUrl: URL;
17
+ };
18
+
19
+ export { debounce, fakeAudioStream, fakeWebcamFrame, parseRoomUrlAndSubdomain };
package/dist/utils.js ADDED
@@ -0,0 +1,91 @@
1
+ export { d as debounce } from './debounce-B-cWYxqK.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,71 @@
1
+ {
2
+ "name": "@whereby.com/core",
3
+ "description": "Core library for whereby.com sdk",
4
+ "author": "Whereby AS",
5
+ "version": "0.0.0-canary-20240402133911",
6
+ "license": "MIT",
7
+ "scripts": {
8
+ "build": "rimraf dist && rollup -c rollup.config.cjs",
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
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "import": "./dist/index.js",
25
+ "types": "./dist/index.d.ts"
26
+ },
27
+ "./utils": {
28
+ "import": "./dist/utils.js",
29
+ "types": "./dist/utils.d.ts"
30
+ }
31
+ },
32
+ "types": "dist/index.d.ts",
33
+ "typesVersions": {
34
+ "*": {
35
+ "*": [
36
+ "dist/index.d.ts"
37
+ ],
38
+ "utils": [
39
+ "dist/utils.d.ts"
40
+ ]
41
+ }
42
+ },
43
+ "devDependencies": {
44
+ "@rollup/plugin-commonjs": "^25.0.7",
45
+ "@rollup/plugin-node-resolve": "^15.2.3",
46
+ "@rollup/plugin-replace": "^5.0.5",
47
+ "@types/btoa": "^1.2.3",
48
+ "@types/node": "^20.11.19",
49
+ "@types/uuid": "^9.0.7",
50
+ "deep-object-diff": "^1.1.9",
51
+ "dotenv": "^16.3.1",
52
+ "dotenv-run-script": "^0.4.1",
53
+ "rimraf": "^5.0.5",
54
+ "rollup": "^4.12.0",
55
+ "rollup-plugin-dts": "^6.1.0",
56
+ "rollup-plugin-polyfill-node": "^0.13.0",
57
+ "rollup-plugin-terser": "^7.0.2",
58
+ "rollup-plugin-typescript2": "^0.36.0",
59
+ "tslib": "^2.4.1",
60
+ "uuid": "^9.0.1",
61
+ "yalc": "^1.0.0-pre.53"
62
+ },
63
+ "dependencies": {
64
+ "@reduxjs/toolkit": "^2.0.1",
65
+ "@swc/helpers": "^0.3.13",
66
+ "@whereby.com/media": "*",
67
+ "axios": "^1.2.3",
68
+ "btoa": "^1.2.1",
69
+ "events": "^3.3.0"
70
+ }
71
+ }