@cloudflare/realtimekit-react-native 0.1.3-staging.1 → 0.1.3-staging.3
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/android/src/main/AndroidManifest.xml +7 -0
- package/android/src/main/res/values/strings.xml +3 -0
- package/ios/RTKRNBackgroundTimer.m +8 -7
- package/lib/AudioSampleHandler.d.ts +14 -0
- package/lib/AudioSampleHandler.js +57 -0
- package/lib/BackgroundHandler.d.ts +1 -0
- package/lib/BackgroundHandler.js +3 -0
- package/lib/ReactHooks.d.ts +5 -0
- package/lib/ReactHooks.js +8 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +13 -1
- package/package.json +3 -3
|
@@ -21,4 +21,11 @@
|
|
|
21
21
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
|
22
22
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
|
23
23
|
<uses-permission android:name="android.permission.MICROPHONE" />
|
|
24
|
+
<application>
|
|
25
|
+
<provider
|
|
26
|
+
android:name="com.facebook.react.modules.blob.BlobProvider"
|
|
27
|
+
android:authorities="@string/blob_provider_authority"
|
|
28
|
+
android:exported="false"
|
|
29
|
+
/>
|
|
30
|
+
</application>
|
|
24
31
|
</manifest>
|
|
@@ -77,14 +77,15 @@ RCT_EXPORT_METHOD(setTimeout:(int)timeoutId
|
|
|
77
77
|
resolve([NSNumber numberWithBool:YES]);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
resolver:(RCTPromiseResolveBlock)resolve
|
|
83
|
-
rejecter:(RCTPromiseRejectBlock)reject)
|
|
80
|
+
RCT_EXPORT_METHOD(backgroundTimerSetTimeout:(int)timeoutId
|
|
81
|
+
timeout:(double)timeout)
|
|
84
82
|
{
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, timeout * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
|
|
84
|
+
if ([self bridge] != nil) {
|
|
85
|
+
[self sendEventWithName:@"backgroundTimer.timeout" body:[NSNumber numberWithInt:timeoutId]];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
88
89
|
|
|
89
90
|
@end
|
|
90
91
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
export default class AudioSampleHandler extends EventEmitter {
|
|
3
|
+
private webRTCModuleEmitter;
|
|
4
|
+
private _audioSamplesListener?;
|
|
5
|
+
private _isListening;
|
|
6
|
+
private _currentSamples;
|
|
7
|
+
constructor();
|
|
8
|
+
static init(): Promise<AudioSampleHandler>;
|
|
9
|
+
private _audioSampleHandler;
|
|
10
|
+
private initialiseSampler;
|
|
11
|
+
getFloatTimeDomainData(samples: Float32Array): void;
|
|
12
|
+
stopListening(): void;
|
|
13
|
+
destructor(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 { NativeEventEmitter, NativeModules, Platform, } from 'react-native';
|
|
11
|
+
import { EventEmitter } from 'events';
|
|
12
|
+
const { WebRTCModule } = NativeModules;
|
|
13
|
+
export default class AudioSampleHandler extends EventEmitter {
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this._isListening = false;
|
|
17
|
+
this.webRTCModuleEmitter = new NativeEventEmitter(WebRTCModule);
|
|
18
|
+
this._audioSampleHandler = this._audioSampleHandler.bind(this);
|
|
19
|
+
this._currentSamples = new Float32Array(1024);
|
|
20
|
+
this.initialiseSampler();
|
|
21
|
+
}
|
|
22
|
+
static init() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return new AudioSampleHandler();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
_audioSampleHandler(audioData) {
|
|
28
|
+
this._currentSamples.fill(0);
|
|
29
|
+
if (Platform.OS === 'android') {
|
|
30
|
+
this._currentSamples.set(audioData);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this._currentSamples.set(audioData.samples);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
initialiseSampler() {
|
|
37
|
+
this._audioSamplesListener = this.webRTCModuleEmitter.addListener('audioSamples', this._audioSampleHandler);
|
|
38
|
+
this._isListening = true;
|
|
39
|
+
}
|
|
40
|
+
getFloatTimeDomainData(samples) {
|
|
41
|
+
if (!this._isListening) {
|
|
42
|
+
this.initialiseSampler();
|
|
43
|
+
}
|
|
44
|
+
samples.set(this._currentSamples);
|
|
45
|
+
}
|
|
46
|
+
stopListening() {
|
|
47
|
+
if (this._audioSamplesListener) {
|
|
48
|
+
this._audioSamplesListener.remove();
|
|
49
|
+
this._audioSamplesListener = undefined;
|
|
50
|
+
this._isListening = false;
|
|
51
|
+
this._currentSamples.fill(0);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
destructor() {
|
|
55
|
+
this.stopListening();
|
|
56
|
+
}
|
|
57
|
+
}
|
package/lib/BackgroundHandler.js
CHANGED
package/lib/ReactHooks.d.ts
CHANGED
|
@@ -5,7 +5,12 @@ import RealtimeKitClient from '@cloudflare/realtimekit';
|
|
|
5
5
|
export declare const useRealtimeKitClient: () => [RealtimeKitClient | undefined, (options: any) => {}];
|
|
6
6
|
type StateSelector<T extends object, U> = (state: T) => U;
|
|
7
7
|
/**
|
|
8
|
+
* @deprecated Use `useRealtimeKitSelector` instead.
|
|
8
9
|
* Hook which extracts data from the RealtimeKitClient object
|
|
9
10
|
*/
|
|
10
11
|
export declare const useRTKSelector: <StateSlice>(selector: StateSelector<RealtimeKitClient, StateSlice>) => StateSlice;
|
|
12
|
+
/**
|
|
13
|
+
* Hook which extracts data from the RealtimeKitClient object
|
|
14
|
+
*/
|
|
15
|
+
export declare const useRealtimeKitSelector: <StateSlice>(selector: StateSelector<RealtimeKitClient, StateSlice>) => StateSlice;
|
|
11
16
|
export * from './ReactContext';
|
package/lib/ReactHooks.js
CHANGED
|
@@ -37,12 +37,19 @@ const shouldUpdate = (slice, newSlice) => {
|
|
|
37
37
|
return false;
|
|
38
38
|
};
|
|
39
39
|
/**
|
|
40
|
+
* @deprecated Use `useRealtimeKitSelector` instead.
|
|
40
41
|
* Hook which extracts data from the RealtimeKitClient object
|
|
41
42
|
*/
|
|
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) => {
|
|
43
50
|
const { meeting, updates } = useContext(RealtimeKitContext);
|
|
44
51
|
if (!meeting)
|
|
45
|
-
throw new Error('
|
|
52
|
+
throw new Error('useRealtimeKitSelector must be used within the RealtimeKitProvider');
|
|
46
53
|
const state = useRef(selector(meeting));
|
|
47
54
|
const [, forceUpdate] = useReducer((c) => c + 1, 0);
|
|
48
55
|
useEffect(() => {
|
package/lib/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import './utils/crypto';
|
|
|
3
3
|
import 'text-encoding-polyfill';
|
|
4
4
|
import 'node-libs-react-native/globals';
|
|
5
5
|
import 'react-native-url-polyfill/auto';
|
|
6
|
-
export { RealtimeKitProvider, useRealtimeKitClient, useRTKSelector, useRealtimeKitMeeting, } from './ReactHooks';
|
|
6
|
+
export { RealtimeKitProvider, useRealtimeKitClient, useRTKSelector, useRealtimeKitSelector, useRealtimeKitMeeting, } from './ReactHooks';
|
|
7
7
|
declare global {
|
|
8
8
|
var navigator: any;
|
|
9
9
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { NativeModules, Platform } from 'react-native';
|
|
2
2
|
import RealtimeKitMeeting from '@cloudflare/realtimekit';
|
|
3
3
|
import LocalMediaHandler from './LocalMediaHandler';
|
|
4
|
+
import AudioSampleHandler from './AudioSampleHandler';
|
|
5
|
+
import BackgroundTimer from './BackgroundHandler';
|
|
4
6
|
import { registerGlobals } from '@cloudflare/react-native-webrtc';
|
|
5
7
|
import './utils/crypto';
|
|
6
8
|
import 'text-encoding-polyfill';
|
|
7
9
|
import 'node-libs-react-native/globals';
|
|
8
10
|
import 'react-native-url-polyfill/auto';
|
|
9
|
-
export { RealtimeKitProvider, useRealtimeKitClient, useRTKSelector, useRealtimeKitMeeting, } from './ReactHooks';
|
|
11
|
+
export { RealtimeKitProvider, useRealtimeKitClient, useRTKSelector, useRealtimeKitSelector, useRealtimeKitMeeting, } from './ReactHooks';
|
|
10
12
|
registerGlobals();
|
|
11
13
|
const LINKING_ERROR = `The package '@cloudflare/realtimekit-react-native' doesn't seem to be linked. Make sure: \n\n` +
|
|
12
14
|
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
@@ -37,4 +39,14 @@ Object.defineProperty(navigator, 'RNLocalMediaHandlerImpl', {
|
|
|
37
39
|
return LocalMediaHandler;
|
|
38
40
|
},
|
|
39
41
|
});
|
|
42
|
+
Object.defineProperty(navigator, 'RNAudioSampleHandlerImpl', {
|
|
43
|
+
get: function () {
|
|
44
|
+
return AudioSampleHandler;
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(navigator, 'RNBackgroundTimerImpl', {
|
|
48
|
+
get: function () {
|
|
49
|
+
return BackgroundTimer;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
40
52
|
export default RealtimeKitMeeting;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/realtimekit-react-native",
|
|
3
|
-
"version": "0.1.3-staging.
|
|
3
|
+
"version": "0.1.3-staging.3",
|
|
4
4
|
"description": "Cloudflare RealtimeKit SDK for react native",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Cloudflare",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"private": false,
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@cloudflare/realtimekit": "1.
|
|
28
|
+
"@cloudflare/realtimekit": "1.1.5-staging.1",
|
|
29
29
|
"events": "^3.3.0",
|
|
30
30
|
"fast-base64-decode": "1.0.0",
|
|
31
31
|
"node-libs-react-native": "^1.2.1",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"android"
|
|
39
39
|
],
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@cloudflare/react-native-webrtc": "~
|
|
41
|
+
"@cloudflare/react-native-webrtc": "~125.0.1",
|
|
42
42
|
"@expo/config-plugins": "*",
|
|
43
43
|
"react": "*",
|
|
44
44
|
"react-native": "*"
|