@whereby.com/core 0.8.0 → 0.9.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.
@@ -35,6 +35,8 @@ const createReactor = (selectors, callback) => {
35
35
  });
36
36
  };
37
37
 
38
+ const coreVersion = "0.9.1";
39
+
38
40
  const initialState$c = {
39
41
  isNodeSdk: false,
40
42
  wantsToJoin: false,
@@ -42,7 +44,7 @@ const initialState$c = {
42
44
  roomKey: null,
43
45
  roomUrl: null,
44
46
  displayName: null,
45
- sdkVersion: null,
47
+ userAgent: `core:${coreVersion}`,
46
48
  externalId: null,
47
49
  };
48
50
  const appSlice = toolkit.createSlice({
@@ -68,7 +70,7 @@ const selectAppRoomName = (state) => state.app.roomName;
68
70
  const selectAppRoomUrl = (state) => state.app.roomUrl;
69
71
  const selectAppRoomKey = (state) => state.app.roomKey;
70
72
  const selectAppDisplayName = (state) => state.app.displayName;
71
- const selectAppSdkVersion = (state) => state.app.sdkVersion;
73
+ const selectAppUserAgent = (state) => state.app.userAgent;
72
74
  const selectAppExternalId = (state) => state.app.externalId;
73
75
  const selectAppIsNodeSdk = (state) => state.app.isNodeSdk;
74
76
 
@@ -406,6 +408,75 @@ const selectCloudRecordingStartedAt = (state) => state.cloudRecording.startedAt;
406
408
  const selectCloudRecordingError = (state) => state.cloudRecording.error;
407
409
  const selectIsCloudRecording = (state) => state.cloudRecording.isRecording;
408
410
 
411
+ function fakeAudioStream() {
412
+ const audioCtx = new AudioContext();
413
+ const oscillator = audioCtx.createOscillator();
414
+ const destination = audioCtx.createMediaStreamDestination();
415
+ oscillator.connect(destination);
416
+ oscillator.frequency.value = 400;
417
+ oscillator.type = "sine";
418
+ setInterval(() => {
419
+ if (oscillator.frequency.value <= 900) {
420
+ oscillator.frequency.value += 10;
421
+ }
422
+ else {
423
+ oscillator.frequency.value = 200;
424
+ }
425
+ }, 20);
426
+ oscillator.start();
427
+ return destination.stream;
428
+ }
429
+
430
+ let rotationAngle = 0;
431
+ function drawWebcamFrame(canvas) {
432
+ const context = canvas.getContext("2d");
433
+ if (!context) {
434
+ console.error("Canvas context not available");
435
+ return;
436
+ }
437
+ const wheelRadius = 100;
438
+ const wheelCenterX = canvas.width / 2;
439
+ const wheelCenterY = canvas.height / 2;
440
+ context.fillStyle = "darkgreen";
441
+ context.fillRect(0, 0, canvas.width, canvas.height);
442
+ context.save();
443
+ context.translate(wheelCenterX, wheelCenterY);
444
+ context.rotate(rotationAngle);
445
+ const numSlices = 12;
446
+ const sliceAngle = (2 * Math.PI) / numSlices;
447
+ const colors = ["red", "orange", "yellow", "green", "blue", "purple"];
448
+ for (let i = 0; i < numSlices; i++) {
449
+ context.beginPath();
450
+ context.moveTo(0, 0);
451
+ context.arc(0, 0, wheelRadius, i * sliceAngle, (i + 1) * sliceAngle);
452
+ context.fillStyle = colors[i % colors.length];
453
+ context.fill();
454
+ context.closePath();
455
+ }
456
+ context.restore();
457
+ context.fillStyle = "white";
458
+ context.font = "42px Arial";
459
+ const topText = "Whereby Media Stream";
460
+ const topTextWidth = context.measureText(topText).width;
461
+ context.fillText(topText, canvas.width / 2 - topTextWidth / 2, 50);
462
+ context.font = "32px Arial";
463
+ const now = new Date();
464
+ const timeText = `time: ${now.getHours().toString().padStart(2, "0")}:${now
465
+ .getMinutes()
466
+ .toString()
467
+ .padStart(2, "0")}:${now.getSeconds().toString().padStart(2, "0")}.${now
468
+ .getMilliseconds()
469
+ .toString()
470
+ .padStart(3, "0")}`;
471
+ context.fillText(timeText, 10, canvas.height - 20);
472
+ context.fillText(`rotation angle: ${rotationAngle.toFixed(2)}`, canvas.width - canvas.width / 2, canvas.height - 20);
473
+ rotationAngle += 0.01;
474
+ }
475
+ function fakeWebcamFrame(canvas) {
476
+ drawWebcamFrame(canvas);
477
+ requestAnimationFrame(() => fakeWebcamFrame(canvas));
478
+ }
479
+
409
480
  function debounce(fn, { delay = 500, edges } = {}) {
410
481
  let timeout;
411
482
  let nCalls = 0;
@@ -425,6 +496,25 @@ function debounce(fn, { delay = 500, edges } = {}) {
425
496
  };
426
497
  }
427
498
 
499
+ function parseRoomUrlAndSubdomain(roomAttribute, subdomainAttribute) {
500
+ if (!roomAttribute) {
501
+ throw new Error("Missing room attribute");
502
+ }
503
+ const m = /https:\/\/([^.]+)(\.whereby\.com|-ip-\d+-\d+-\d+-\d+.hereby.dev:4443)\/.+/.exec(roomAttribute);
504
+ const subdomain = (m && m[1]) || subdomainAttribute;
505
+ if (!subdomain) {
506
+ throw new Error("Missing subdomain attribute");
507
+ }
508
+ if (!m) {
509
+ throw new Error("Could not parse room URL");
510
+ }
511
+ const roomUrl = new URL(roomAttribute);
512
+ return {
513
+ subdomain,
514
+ roomUrl,
515
+ };
516
+ }
517
+
428
518
  const initialLocalMediaState = {
429
519
  busyDeviceIds: [],
430
520
  cameraEnabled: false,
@@ -1329,7 +1419,7 @@ const doKnockRoom = createAppThunk(() => (dispatch, getState) => {
1329
1419
  const roomName = selectAppRoomName(state);
1330
1420
  const roomKey = selectAppRoomKey(state);
1331
1421
  const displayName = selectAppDisplayName(state);
1332
- const sdkVersion = selectAppSdkVersion(state);
1422
+ const userAgent = selectAppUserAgent(state);
1333
1423
  const externalId = selectAppExternalId(state);
1334
1424
  const organizationId = selectOrganizationId(state);
1335
1425
  socket === null || socket === void 0 ? void 0 : socket.emit("knock_room", {
@@ -1347,7 +1437,7 @@ const doKnockRoom = createAppThunk(() => (dispatch, getState) => {
1347
1437
  roomKey,
1348
1438
  roomName,
1349
1439
  selfId: "",
1350
- userAgent: `browser-sdk:${sdkVersion || "unknown"}`,
1440
+ userAgent,
1351
1441
  externalId,
1352
1442
  });
1353
1443
  dispatch(connectionStatusChanged("knocking"));
@@ -1358,7 +1448,7 @@ const doConnectRoom = createAppThunk(() => (dispatch, getState) => {
1358
1448
  const roomName = selectAppRoomName(state);
1359
1449
  const roomKey = selectAppRoomKey(state);
1360
1450
  const displayName = selectAppDisplayName(state);
1361
- const sdkVersion = selectAppSdkVersion(state);
1451
+ const userAgent = selectAppUserAgent(state);
1362
1452
  const externalId = selectAppExternalId(state);
1363
1453
  const organizationId = selectOrganizationId(state);
1364
1454
  const isCameraEnabled = selectIsCameraEnabled(getState());
@@ -1371,7 +1461,8 @@ const doConnectRoom = createAppThunk(() => (dispatch, getState) => {
1371
1461
  }, deviceCapabilities: { canScreenshare: true }, displayName, isCoLocated: false, isDevicePermissionDenied: false, kickFromOtherRooms: false, organizationId,
1372
1462
  roomKey,
1373
1463
  roomName,
1374
- selfId }, (!!clientClaim && { clientClaim })), { userAgent: `browser-sdk:${sdkVersion || "unknown"}`, externalId }));
1464
+ selfId }, (!!clientClaim && { clientClaim })), { userAgent,
1465
+ externalId }));
1375
1466
  dispatch(connectionStatusChanged("connecting"));
1376
1467
  });
1377
1468
  const selectRoomConnectionRaw = (state) => state.roomConnection;
@@ -2970,8 +3061,6 @@ class LocalParticipant extends RoomParticipant {
2970
3061
  }
2971
3062
  }
2972
3063
 
2973
- const sdkVersion = "0.8.0";
2974
-
2975
3064
  const API_BASE_URL = "https://api.whereby.dev" ;
2976
3065
  function createServices() {
2977
3066
  const credentialsService = CredentialsService.create({ baseUrl: API_BASE_URL });
@@ -3016,6 +3105,7 @@ exports.createReactor = createReactor;
3016
3105
  exports.createServices = createServices;
3017
3106
  exports.createStore = createStore;
3018
3107
  exports.createWebRtcEmitter = createWebRtcEmitter;
3108
+ exports.debounce = debounce;
3019
3109
  exports.deviceBusy = deviceBusy;
3020
3110
  exports.deviceCredentialsSlice = deviceCredentialsSlice;
3021
3111
  exports.deviceIdentified = deviceIdentified;
@@ -3055,6 +3145,8 @@ exports.doStopScreenshare = doStopScreenshare;
3055
3145
  exports.doSwitchLocalStream = doSwitchLocalStream;
3056
3146
  exports.doToggleCamera = doToggleCamera;
3057
3147
  exports.doUpdateDeviceList = doUpdateDeviceList;
3148
+ exports.fakeAudioStream = fakeAudioStream;
3149
+ exports.fakeWebcamFrame = fakeWebcamFrame;
3058
3150
  exports.initialCloudRecordingState = initialCloudRecordingState;
3059
3151
  exports.initialLocalMediaState = initialLocalMediaState;
3060
3152
  exports.isAcceptingStreams = isAcceptingStreams;
@@ -3066,6 +3158,7 @@ exports.localScreenshareSlice = localScreenshareSlice;
3066
3158
  exports.localStreamMetadataUpdated = localStreamMetadataUpdated;
3067
3159
  exports.observeStore = observeStore;
3068
3160
  exports.organizationSlice = organizationSlice;
3161
+ exports.parseRoomUrlAndSubdomain = parseRoomUrlAndSubdomain;
3069
3162
  exports.participantStreamAdded = participantStreamAdded;
3070
3163
  exports.participantStreamIdAdded = participantStreamIdAdded;
3071
3164
  exports.recordingRequestStarted = recordingRequestStarted;
@@ -3081,7 +3174,6 @@ exports.rtcDispatcherCreated = rtcDispatcherCreated;
3081
3174
  exports.rtcManagerCreated = rtcManagerCreated;
3082
3175
  exports.rtcManagerDestroyed = rtcManagerDestroyed;
3083
3176
  exports.rtcManagerInitialized = rtcManagerInitialized;
3084
- exports.sdkVersion = sdkVersion;
3085
3177
  exports.selectAppDisplayName = selectAppDisplayName;
3086
3178
  exports.selectAppExternalId = selectAppExternalId;
3087
3179
  exports.selectAppIsNodeSdk = selectAppIsNodeSdk;
@@ -3089,7 +3181,7 @@ exports.selectAppRaw = selectAppRaw;
3089
3181
  exports.selectAppRoomKey = selectAppRoomKey;
3090
3182
  exports.selectAppRoomName = selectAppRoomName;
3091
3183
  exports.selectAppRoomUrl = selectAppRoomUrl;
3092
- exports.selectAppSdkVersion = selectAppSdkVersion;
3184
+ exports.selectAppUserAgent = selectAppUserAgent;
3093
3185
  exports.selectAppWantsToJoin = selectAppWantsToJoin;
3094
3186
  exports.selectBusyDeviceIds = selectBusyDeviceIds;
3095
3187
  exports.selectCameraDeviceError = selectCameraDeviceError;