agora-appbuilder-core 4.0.0-ms.1 → 4.0.0-ms.2
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/package.json
CHANGED
|
@@ -11,7 +11,7 @@ import SDKMethodEventsManager from './utils/SdkMethodEvents';
|
|
|
11
11
|
import App from './App';
|
|
12
12
|
import SdkApiContextProvider from './components/SdkApiContext';
|
|
13
13
|
import {Unsubscribe} from 'nanoevents';
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
// type makeAsync<T extends (...p: any) => void> = (
|
|
16
16
|
// ...p: Parameters<T>
|
|
17
17
|
// ) => PromiseLike<ReturnType<T>>;
|
|
@@ -26,6 +26,8 @@ export interface SdkMethodEvents {
|
|
|
26
26
|
roomid: string | Partial<MeetingInfoContextInterface['data']>,
|
|
27
27
|
skipPrecall?: boolean,
|
|
28
28
|
): MeetingInfoContextInterface['data'];
|
|
29
|
+
'login':(token:string) => Promise<void>
|
|
30
|
+
'logout':() => Promise<void>
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
// interface AppBuilderSdkApiInterface {
|
|
@@ -41,23 +43,13 @@ export interface SdkMethodEvents {
|
|
|
41
43
|
// ) => Unsubscribe;
|
|
42
44
|
// }
|
|
43
45
|
|
|
44
|
-
const setAppBuilerToken = (token: string) => {
|
|
45
|
-
return new Promise((resolve, reject) => {
|
|
46
|
-
if ($config.ENABLE_TOKEN_AUTH) {
|
|
47
|
-
try {
|
|
48
|
-
AsyncStorage.setItem('SDK_TOKEN', token);
|
|
49
|
-
return resolve(true);
|
|
50
|
-
} catch (error) {
|
|
51
|
-
return reject(error);
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
return reject('ERROR: TOKEN AUTH IS NOT ENABLED');
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
|
|
59
46
|
export const AppBuilderSdkApi = {
|
|
60
|
-
|
|
47
|
+
login: async (token: string) => {
|
|
48
|
+
return await SDKMethodEventsManager.emit('login', token);
|
|
49
|
+
},
|
|
50
|
+
logout: async () => {
|
|
51
|
+
return await SDKMethodEventsManager.emit('logout');
|
|
52
|
+
},
|
|
61
53
|
customize: async (customization: CustomizationApiInterface) => {
|
|
62
54
|
return await SDKMethodEventsManager.emit('customize', customization);
|
|
63
55
|
},
|
|
@@ -16,6 +16,8 @@ import {getRequestHeaders, GET_UNAUTH_FLOW_API_ENDPOINT} from './config';
|
|
|
16
16
|
import isSDK from '../utils/isSDK';
|
|
17
17
|
import {Linking} from 'react-native';
|
|
18
18
|
import {isAndroid, isIOS} from '../utils/common';
|
|
19
|
+
import SDKMethodEventsManager from '../utils/SdkMethodEvents';
|
|
20
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
19
21
|
|
|
20
22
|
const GET_USER = gql`
|
|
21
23
|
query getUser {
|
|
@@ -55,6 +57,26 @@ const AuthProvider = (props: AuthProviderProps) => {
|
|
|
55
57
|
|
|
56
58
|
const enableAuth = $config.ENABLE_IDP_AUTH || $config.ENABLE_TOKEN_AUTH;
|
|
57
59
|
|
|
60
|
+
useEffect(()=>{
|
|
61
|
+
SDKMethodEventsManager.on('login',async(res,rej,token)=>{
|
|
62
|
+
try {
|
|
63
|
+
await AsyncStorage.setItem('SDK_TOKEN', token);
|
|
64
|
+
await enableTokenAuth()
|
|
65
|
+
res()
|
|
66
|
+
} catch (error) {
|
|
67
|
+
rej('SDK Login failed'+JSON.stringify(error))
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
SDKMethodEventsManager.on('logout',async(res,rej)=>{
|
|
71
|
+
try {
|
|
72
|
+
await tokenLogout()
|
|
73
|
+
res()
|
|
74
|
+
} catch (error) {
|
|
75
|
+
rej('SDK Logout failed'+JSON.stringify(error))
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
},[])
|
|
79
|
+
|
|
58
80
|
useEffect(() => {
|
|
59
81
|
if (!authenticated && authError) {
|
|
60
82
|
Toast.show({
|
|
@@ -121,8 +121,9 @@ const useTokenAuth = () => {
|
|
|
121
121
|
});
|
|
122
122
|
};
|
|
123
123
|
|
|
124
|
-
const tokenLogout = () => {
|
|
125
|
-
|
|
124
|
+
const tokenLogout = async () => {
|
|
125
|
+
const serverToken = await AsyncStorage.getItem('SDK_TOKEN');
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
126
127
|
try {
|
|
127
128
|
fetch(`${$config.BACKEND_ENDPOINT}/v1/logout`, {
|
|
128
129
|
headers: {
|