@cloudflare/realtimekit-react-native 0.1.4-staging.1 → 0.1.4-staging.10

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.
Files changed (92) hide show
  1. package/lib/commonjs/AudioSampleHandler.js +61 -0
  2. package/lib/commonjs/AudioSampleHandler.js.map +1 -0
  3. package/lib/commonjs/BackgroundHandler.js +109 -0
  4. package/lib/commonjs/BackgroundHandler.js.map +1 -0
  5. package/lib/commonjs/DeviceInfo.js +37 -0
  6. package/lib/commonjs/DeviceInfo.js.map +1 -0
  7. package/lib/commonjs/LocalMediaError.js +18 -0
  8. package/lib/commonjs/LocalMediaError.js.map +1 -0
  9. package/lib/commonjs/LocalMediaHandler.js +791 -0
  10. package/lib/commonjs/LocalMediaHandler.js.map +1 -0
  11. package/lib/commonjs/LocalMediaInterfaces.js +2 -0
  12. package/lib/commonjs/LocalMediaInterfaces.js.map +1 -0
  13. package/lib/commonjs/LocalMediaUtils.js +298 -0
  14. package/lib/commonjs/LocalMediaUtils.js.map +1 -0
  15. package/lib/commonjs/NativeAudioManager.js +72 -0
  16. package/lib/commonjs/NativeAudioManager.js.map +1 -0
  17. package/lib/commonjs/PermissionHandler.js +157 -0
  18. package/lib/commonjs/PermissionHandler.js.map +1 -0
  19. package/lib/commonjs/ReactContext.js +116 -0
  20. package/lib/commonjs/ReactContext.js.map +1 -0
  21. package/lib/commonjs/ReactHooks.js +99 -0
  22. package/lib/commonjs/ReactHooks.js.map +1 -0
  23. package/lib/commonjs/index.js +95 -0
  24. package/lib/commonjs/index.js.map +1 -0
  25. package/lib/commonjs/utils/constants.js +7 -0
  26. package/lib/commonjs/utils/constants.js.map +1 -0
  27. package/lib/commonjs/utils/crypto.js +76 -0
  28. package/lib/commonjs/utils/crypto.js.map +1 -0
  29. package/lib/commonjs/utils/version.js +8 -0
  30. package/lib/commonjs/utils/version.js.map +1 -0
  31. package/lib/module/AudioSampleHandler.js +54 -0
  32. package/lib/module/AudioSampleHandler.js.map +1 -0
  33. package/lib/module/BackgroundHandler.js +103 -0
  34. package/lib/module/BackgroundHandler.js.map +1 -0
  35. package/lib/module/DeviceInfo.js +31 -0
  36. package/lib/module/DeviceInfo.js.map +1 -0
  37. package/lib/module/LocalMediaError.js +11 -0
  38. package/lib/module/LocalMediaError.js.map +1 -0
  39. package/lib/module/LocalMediaHandler.js +784 -0
  40. package/lib/module/LocalMediaHandler.js.map +1 -0
  41. package/lib/module/LocalMediaInterfaces.js +2 -0
  42. package/lib/module/LocalMediaInterfaces.js.map +1 -0
  43. package/lib/module/LocalMediaUtils.js +290 -0
  44. package/lib/module/LocalMediaUtils.js.map +1 -0
  45. package/lib/module/NativeAudioManager.js +65 -0
  46. package/lib/module/NativeAudioManager.js.map +1 -0
  47. package/lib/module/PermissionHandler.js +149 -0
  48. package/lib/module/PermissionHandler.js.map +1 -0
  49. package/lib/module/ReactContext.js +107 -0
  50. package/lib/module/ReactContext.js.map +1 -0
  51. package/lib/module/ReactHooks.js +75 -0
  52. package/lib/module/ReactHooks.js.map +1 -0
  53. package/lib/{src → module}/index.js +32 -32
  54. package/lib/module/index.js.map +1 -0
  55. package/lib/module/utils/constants.js +5 -0
  56. package/lib/module/utils/constants.js.map +1 -0
  57. package/lib/module/utils/crypto.js +74 -0
  58. package/lib/module/utils/crypto.js.map +1 -0
  59. package/lib/module/utils/version.js +2 -0
  60. package/lib/module/utils/version.js.map +1 -0
  61. package/lib/{src → typescript}/LocalMediaHandler.d.ts +0 -4
  62. package/lib/{src → typescript}/ReactHooks.d.ts +2 -2
  63. package/lib/typescript/utils/constants.d.ts +1 -0
  64. package/lib/typescript/utils/version.d.ts +1 -0
  65. package/package.json +5 -4
  66. package/plugin/build/withRTK.js +43 -17
  67. package/plugin/src/withRTK.ts +55 -25
  68. package/android/src/main/res/values/strings.xml +0 -3
  69. package/lib/package.json +0 -168
  70. package/lib/src/AudioSampleHandler.js +0 -57
  71. package/lib/src/BackgroundHandler.js +0 -100
  72. package/lib/src/DeviceInfo.js +0 -27
  73. package/lib/src/LocalMediaError.js +0 -6
  74. package/lib/src/LocalMediaHandler.js +0 -860
  75. package/lib/src/LocalMediaInterfaces.js +0 -1
  76. package/lib/src/LocalMediaUtils.js +0 -288
  77. package/lib/src/NativeAudioManager.js +0 -93
  78. package/lib/src/PermissionHandler.js +0 -179
  79. package/lib/src/ReactContext.js +0 -90
  80. package/lib/src/ReactHooks.js +0 -80
  81. package/lib/src/utils/crypto.js +0 -82
  82. /package/lib/{src → typescript}/AudioSampleHandler.d.ts +0 -0
  83. /package/lib/{src → typescript}/BackgroundHandler.d.ts +0 -0
  84. /package/lib/{src → typescript}/DeviceInfo.d.ts +0 -0
  85. /package/lib/{src → typescript}/LocalMediaError.d.ts +0 -0
  86. /package/lib/{src → typescript}/LocalMediaInterfaces.d.ts +0 -0
  87. /package/lib/{src → typescript}/LocalMediaUtils.d.ts +0 -0
  88. /package/lib/{src → typescript}/NativeAudioManager.d.ts +0 -0
  89. /package/lib/{src → typescript}/PermissionHandler.d.ts +0 -0
  90. /package/lib/{src → typescript}/ReactContext.d.ts +0 -0
  91. /package/lib/{src → typescript}/index.d.ts +0 -0
  92. /package/lib/{src → typescript}/utils/crypto.d.ts +0 -0
@@ -1,80 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { useState, useEffect, useRef, useReducer, useContext } from 'react';
11
- import RealtimeKitClient from '@cloudflare/realtimekit';
12
- import { RealtimeKitContext } from './ReactContext';
13
- /**
14
- * Hook which manages a RealtimeKitClient instance
15
- */
16
- export const useRealtimeKitClient = () => {
17
- const [client, setClient] = useState();
18
- const initClient = (options) => __awaiter(void 0, void 0, void 0, function* () {
19
- const cli = yield RealtimeKitClient.init(options);
20
- setClient(cli);
21
- return cli;
22
- });
23
- return [client, initClient];
24
- };
25
- /**
26
- * Utility function which determines whether to trigger update or not
27
- */
28
- const shouldUpdate = (slice, newSlice) => {
29
- if (slice !== newSlice) {
30
- return true;
31
- }
32
- if (Array.isArray(slice) && Array.isArray(newSlice)) {
33
- if (slice.length !== newSlice.length) {
34
- return true;
35
- }
36
- }
37
- return false;
38
- };
39
- /**
40
- * @deprecated Use `useRealtimeKitSelector` instead.
41
- * Hook which extracts data from the RealtimeKitClient object
42
- */
43
- export const useRTKSelector = (selector) => {
44
- return useRealtimeKitSelector(selector);
45
- };
46
- /**
47
- * Hook which extracts data from the RealtimeKitClient object
48
- */
49
- export const useRealtimeKitSelector = (selector) => {
50
- const { meeting, updates } = useContext(RealtimeKitContext);
51
- if (!meeting)
52
- throw new Error('useRealtimeKitSelector must be used within the RealtimeKitProvider');
53
- const state = useRef(selector(meeting));
54
- const [, forceUpdate] = useReducer((c) => c + 1, 0);
55
- useEffect(() => {
56
- const currentState = meeting && selector(meeting);
57
- const listener = () => {
58
- const newStateSlice = meeting && selector(meeting);
59
- if (shouldUpdate(state.current, newStateSlice)) {
60
- state.current = newStateSlice;
61
- forceUpdate();
62
- }
63
- };
64
- if (currentState &&
65
- typeof currentState === 'object' &&
66
- 'addListener' in currentState) {
67
- currentState.addListener('*', forceUpdate);
68
- return () => {
69
- currentState.removeListener('*', forceUpdate);
70
- };
71
- }
72
- updates === null || updates === void 0 ? void 0 : updates.addListener(listener);
73
- return () => {
74
- updates === null || updates === void 0 ? void 0 : updates.removeListener(listener);
75
- };
76
- // eslint-disable-next-line react-hooks/exhaustive-deps
77
- }, [meeting, updates]);
78
- return state.current;
79
- };
80
- export * from './ReactContext';
@@ -1,82 +0,0 @@
1
- const base64Decode = require('fast-base64-decode');
2
- const { NativeModules } = require('react-native');
3
- class TypeMismatchError extends Error {
4
- }
5
- class QuotaExceededError extends Error {
6
- }
7
- let warned = false;
8
- function insecureRandomValues(array) {
9
- if (!warned) {
10
- console.warn('Using an insecure random number generator, this should only happen when running in a debugger without support for crypto.getRandomValues');
11
- warned = true;
12
- }
13
- for (let i = 0, r; i < array.length; i++) {
14
- if ((i & 0x03) === 0)
15
- r = Math.random() * 0x100000000;
16
- array[i] = (r >>> ((i & 0x03) << 3)) & 0xff;
17
- }
18
- return array;
19
- }
20
- /**
21
- * @param {number} byteLength
22
- * @returns {string}
23
- */
24
- function getRandomBase64(byteLength) {
25
- if (NativeModules.Core) {
26
- return NativeModules.Core.getRandomBase64(byteLength);
27
- }
28
- else if (NativeModules.ExpoRandom) {
29
- // Expo SDK 41-44
30
- return NativeModules.ExpoRandom.getRandomBase64String(byteLength);
31
- }
32
- else if (global.ExpoModules) {
33
- // Expo SDK 45+
34
- return global.ExpoModules.ExpoRandom.getRandomBase64String(byteLength);
35
- }
36
- else {
37
- throw new Error('Native module not found');
38
- }
39
- }
40
- /**
41
- * @param {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Uint8ClampedArray} array
42
- */
43
- function getRandomValues(array) {
44
- if (!(array instanceof Int8Array ||
45
- array instanceof Uint8Array ||
46
- array instanceof Int16Array ||
47
- array instanceof Uint16Array ||
48
- array instanceof Int32Array ||
49
- array instanceof Uint32Array ||
50
- array instanceof Uint8ClampedArray)) {
51
- throw new TypeMismatchError('Expected an integer array');
52
- }
53
- if (array.byteLength > 65536) {
54
- throw new QuotaExceededError('Can only request a maximum of 65536 bytes');
55
- }
56
- // Expo SDK 48+
57
- if (global.expo &&
58
- global.expo.modules &&
59
- global.expo.modules.ExpoCrypto &&
60
- global.expo.modules.ExpoCrypto.getRandomValues) {
61
- // ExpoCrypto.getRandomValues doesn't return the array
62
- global.expo.modules.ExpoCrypto.getRandomValues(array);
63
- return array;
64
- }
65
- // Calling getRandomBase64 in debug mode leads to the error
66
- // "Calling synchronous methods on native modules is not supported in Chrome".
67
- // So in that specific case we fall back to just using Math.random.
68
- if (__DEV__) {
69
- if (typeof global.nativeCallSyncHook === 'undefined') {
70
- return insecureRandomValues(array);
71
- }
72
- }
73
- base64Decode(getRandomBase64(array.byteLength), new Uint8Array(array.buffer, array.byteOffset, array.byteLength));
74
- return array;
75
- }
76
- if (typeof global.crypto !== 'object') {
77
- // @ts-ignore
78
- global.crypto = {};
79
- }
80
- if (typeof global.crypto.getRandomValues !== 'function') {
81
- global.crypto.getRandomValues = getRandomValues;
82
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes