Project re-initialization with latest react native (npx create-react-native-library)
This commit is contained in:
@@ -2,7 +2,9 @@ import type { MutableRefObject } from 'react';
|
||||
import type { EmitterSubscription } from 'react-native';
|
||||
import nativeEmitter from '../native-messaging/emitter';
|
||||
|
||||
export function setupListener(_webViewRef: MutableRefObject<any>):EmitterSubscription {
|
||||
export function setupListener(
|
||||
_webViewRef: MutableRefObject<any>
|
||||
): EmitterSubscription {
|
||||
// Resolve promise when SDP offer is available
|
||||
return nativeEmitter.addListener('onBroadcastFinished', () => {
|
||||
console.log(`Broadcast finished`);
|
||||
|
||||
@@ -2,13 +2,15 @@ import type { MutableRefObject } from 'react';
|
||||
import type { EmitterSubscription } from 'react-native';
|
||||
import nativeEmitter from '../native-messaging/emitter';
|
||||
|
||||
export function setupListener(_webViewRef: MutableRefObject<any>):EmitterSubscription {
|
||||
export function setupListener(
|
||||
_webViewRef: MutableRefObject<any>
|
||||
): EmitterSubscription {
|
||||
// Resolve promise when SDP offer is available
|
||||
return nativeEmitter.addListener(
|
||||
'onScreenShareLocalIceCandidate',
|
||||
(jsonEncodedIceCandidate) => {
|
||||
let iceCandidate = JSON.parse(jsonEncodedIceCandidate);
|
||||
if (typeof iceCandidate == 'string') {
|
||||
if (typeof iceCandidate === 'string') {
|
||||
iceCandidate = JSON.parse(iceCandidate);
|
||||
}
|
||||
const event = { candidate: iceCandidate };
|
||||
|
||||
@@ -2,14 +2,19 @@ import type { MutableRefObject } from 'react';
|
||||
import type { EmitterSubscription } from 'react-native';
|
||||
import nativeEmitter from '../native-messaging/emitter';
|
||||
|
||||
export function setupListener(_webViewRef: MutableRefObject<any>):EmitterSubscription {
|
||||
export function setupListener(
|
||||
_webViewRef: MutableRefObject<any>
|
||||
): EmitterSubscription {
|
||||
// Resolve promise when SDP offer is available
|
||||
return nativeEmitter.addListener('onScreenShareSignalingStateChange', (newState) => {
|
||||
console.log(`Temos um novo state: ${newState}`);
|
||||
_webViewRef.current.injectJavaScript(
|
||||
`window.bbbMobileScreenShareSignalingStateChangeCallback && window.bbbMobileScreenShareSignalingStateChangeCallback(${JSON.stringify(
|
||||
newState
|
||||
)});`
|
||||
);
|
||||
});
|
||||
return nativeEmitter.addListener(
|
||||
'onScreenShareSignalingStateChange',
|
||||
(newState) => {
|
||||
console.log(`Temos um novo state: ${newState}`);
|
||||
_webViewRef.current.injectJavaScript(
|
||||
`window.bbbMobileScreenShareSignalingStateChangeCallback && window.bbbMobileScreenShareSignalingStateChangeCallback(${JSON.stringify(
|
||||
newState
|
||||
)});`
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import * as onScreenShareLocalIceCandidate from './events/onScreenShareLocalIceC
|
||||
import * as onScreenShareSignalingStateChange from './events/onScreenShareSignalingStateChange';
|
||||
import * as onBroadcastFinished from './events/onBroadcastFinished';
|
||||
|
||||
type BigbluebuttonMobileSdkProps = {
|
||||
type BigBlueButtonTabletSdkProps = {
|
||||
url: string;
|
||||
style: ViewStyle;
|
||||
onError?: any;
|
||||
@@ -15,8 +15,8 @@ type BigbluebuttonMobileSdkProps = {
|
||||
};
|
||||
|
||||
const data = {
|
||||
instances: 0
|
||||
}
|
||||
instances: 0,
|
||||
};
|
||||
|
||||
const renderPlatformSpecificComponents = () =>
|
||||
Platform.select({
|
||||
@@ -24,12 +24,12 @@ const renderPlatformSpecificComponents = () =>
|
||||
android: null,
|
||||
});
|
||||
|
||||
export const BigBlueButtonMobile = ({
|
||||
export const BigBlueButtonTablet = ({
|
||||
url,
|
||||
style,
|
||||
onError,
|
||||
onSuccess,
|
||||
}: BigbluebuttonMobileSdkProps) => {
|
||||
}: BigBlueButtonTabletSdkProps) => {
|
||||
const webViewRef = useRef(null);
|
||||
const thisInstanceId = ++data.instances;
|
||||
|
||||
@@ -37,22 +37,22 @@ export const BigBlueButtonMobile = ({
|
||||
|
||||
useEffect(() => {
|
||||
const logPrefix = `[${thisInstanceId}] - ${url.substring(8, 16)}`;
|
||||
|
||||
|
||||
console.log(`${logPrefix} - addingListeners`);
|
||||
const listeners:EmitterSubscription[] = [];
|
||||
const listeners: EmitterSubscription[] = [];
|
||||
listeners.push(onScreenShareLocalIceCandidate.setupListener(webViewRef));
|
||||
listeners.push(onScreenShareSignalingStateChange.setupListener(webViewRef));
|
||||
listeners.push(onBroadcastFinished.setupListener(webViewRef));
|
||||
|
||||
return () => {
|
||||
console.log(`${logPrefix} - Removing listeners`);
|
||||
|
||||
listeners.forEach( (listener, index) => {
|
||||
|
||||
listeners.forEach((listener, index) => {
|
||||
console.log(`${logPrefix} - Removing listener ${index}`);
|
||||
listener.remove();
|
||||
} );
|
||||
}
|
||||
}, [webViewRef]);
|
||||
});
|
||||
};
|
||||
}, [webViewRef, thisInstanceId, url]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -63,7 +63,9 @@ export const BigBlueButtonMobile = ({
|
||||
source={{ uri: url }}
|
||||
style={{ ...style }}
|
||||
contentMode={'mobile'}
|
||||
onMessage={(msg) => handleWebviewMessage(thisInstanceId, webViewRef, msg)}
|
||||
onMessage={(msg) =>
|
||||
handleWebviewMessage(thisInstanceId, webViewRef, msg)
|
||||
}
|
||||
applicationNameForUserAgent="BBBMobile"
|
||||
allowsInlineMediaPlayback={true}
|
||||
mediaCapturePermissionGrantType={'grant'}
|
||||
|
||||
@@ -14,7 +14,10 @@ nativeEmitter.addListener('onAddScreenShareRemoteIceCandidateCompleted', () => {
|
||||
});
|
||||
|
||||
// Entry point of this method
|
||||
function addScreenShareRemoteIceCandidate(instanceId: Number, remoteCandidateJson: string) {
|
||||
function addScreenShareRemoteIceCandidate(
|
||||
instanceId: Number,
|
||||
remoteCandidateJson: string
|
||||
) {
|
||||
return new Promise((res, rej) => {
|
||||
// store the resolver for later call (when event is received)
|
||||
resolve = res;
|
||||
|
||||
@@ -20,7 +20,9 @@ function setFullAudioRemoteSDP(instanceId: Number, remoteSdp: string) {
|
||||
resolve = res;
|
||||
|
||||
try {
|
||||
console.log(`[${instanceId}] - >nativeSetFullAudioRemoteSDP ${remoteSdp}`);
|
||||
console.log(
|
||||
`[${instanceId}] - >nativeSetFullAudioRemoteSDP ${remoteSdp}`
|
||||
);
|
||||
// call native swift method that triggers the broadcast popup
|
||||
nativeSetFullAudioRemoteSDP(remoteSdp);
|
||||
} catch (e) {
|
||||
|
||||
@@ -20,7 +20,9 @@ function setScreenShareRemoteSDP(instanceId: Number, remoteSdp: string) {
|
||||
resolve = res;
|
||||
|
||||
try {
|
||||
console.log(`[${instanceId}] - >nativeSetScreenShareRemoteSDP ${remoteSdp}`);
|
||||
console.log(
|
||||
`[${instanceId}] - >nativeSetScreenShareRemoteSDP ${remoteSdp}`
|
||||
);
|
||||
// call native swift method that triggers the broadcast popup
|
||||
nativeSetScreenShareRemoteSDP(remoteSdp);
|
||||
} catch (e) {
|
||||
|
||||
@@ -40,8 +40,8 @@ export function handleWebviewMessage(
|
||||
) {
|
||||
const stringData = event?.nativeEvent?.data;
|
||||
|
||||
console.log("handleWebviewMessage - ", instanceId);
|
||||
|
||||
console.log('handleWebviewMessage - ', instanceId);
|
||||
|
||||
const data = JSON.parse(stringData);
|
||||
if (data?.method && data?.sequence) {
|
||||
let promise;
|
||||
@@ -68,7 +68,7 @@ export function handleWebviewMessage(
|
||||
);
|
||||
break;
|
||||
case 'stopScreenShare':
|
||||
promise = stopScreenShare(instanceId)
|
||||
promise = stopScreenShare(instanceId);
|
||||
break;
|
||||
default:
|
||||
throw `[${instanceId}] - Unknown method ${data?.method}`;
|
||||
|
||||
Reference in New Issue
Block a user