@whereby.com/core 0.7.0 → 0.9.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.
- package/dist/cjs/index.cjs +3188 -0
- package/dist/cjs/utils.cjs +113 -0
- package/dist/index.d.ts +1555 -543
- package/dist/index.mjs +2999 -0
- package/dist/utils.d.ts +0 -10
- package/dist/{utils.js → utils.mjs} +20 -3
- package/package.json +10 -10
- package/dist/debounce-B-cWYxqK.js +0 -20
- package/dist/index.js +0 -9579
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
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 debounce(fn, { delay = 500, edges } = {}) {
|
|
73
|
+
let timeout;
|
|
74
|
+
let nCalls = 0;
|
|
75
|
+
return (...args) => {
|
|
76
|
+
nCalls += 1;
|
|
77
|
+
if (edges && nCalls === 1) {
|
|
78
|
+
fn(...args);
|
|
79
|
+
}
|
|
80
|
+
clearTimeout(timeout);
|
|
81
|
+
timeout = setTimeout(() => {
|
|
82
|
+
if (!edges || nCalls > 1) {
|
|
83
|
+
fn(...args);
|
|
84
|
+
}
|
|
85
|
+
timeout = undefined;
|
|
86
|
+
nCalls = 0;
|
|
87
|
+
}, delay);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function parseRoomUrlAndSubdomain(roomAttribute, subdomainAttribute) {
|
|
92
|
+
if (!roomAttribute) {
|
|
93
|
+
throw new Error("Missing room attribute");
|
|
94
|
+
}
|
|
95
|
+
const m = /https:\/\/([^.]+)(\.whereby\.com|-ip-\d+-\d+-\d+-\d+.hereby.dev:4443)\/.+/.exec(roomAttribute);
|
|
96
|
+
const subdomain = (m && m[1]) || subdomainAttribute;
|
|
97
|
+
if (!subdomain) {
|
|
98
|
+
throw new Error("Missing subdomain attribute");
|
|
99
|
+
}
|
|
100
|
+
if (!m) {
|
|
101
|
+
throw new Error("Could not parse room URL");
|
|
102
|
+
}
|
|
103
|
+
const roomUrl = new URL(roomAttribute);
|
|
104
|
+
return {
|
|
105
|
+
subdomain,
|
|
106
|
+
roomUrl,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
exports.debounce = debounce;
|
|
111
|
+
exports.fakeAudioStream = fakeAudioStream;
|
|
112
|
+
exports.fakeWebcamFrame = fakeWebcamFrame;
|
|
113
|
+
exports.parseRoomUrlAndSubdomain = parseRoomUrlAndSubdomain;
|