-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
52 lines (45 loc) · 1.4 KB
/
App.js
File metadata and controls
52 lines (45 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import AmityClient, { ConnectionStatus, ApiEndpoint,ChannelRepository,ChannelFilter } from "@amityco/js-sdk";
import { View, Button,Text } from "react-native";
let client;
function AuthProvider() {
const apiKey = ""; // Add your api key here
function login() {
client = new AmityClient({
apiKey: apiKey,
apiEndpoint: ApiEndpoint.SG,
}); // modify your server region here e.g ApiEndpoint.EU
client.registerSession({
userId: "",
displayName: "",
}); // Add your own userId and displayName
client.on("connectionStatusChanged", ({ newValue }) => {
if (newValue === ConnectionStatus.Connected) {
console.log("connected to asc");
} else {
console.log(" not connected to asc");
}
});
console.log("client: ", client);
}
function logout(){
client.unregisterSession();
}
function queryChannel() {
const liveCollection = ChannelRepository.queryChannels({
filter: ChannelFilter.Member,
sortBy:'lastActivity'
});
liveCollection.on("dataUpdated", (models) => {
console.log("Channel models: ", models);
});
}
return (
<View>
<Button title='login'onPress={login}/>
<Text>Trigger login first, before calling other functions</Text>
<Button title='logout'onPress={logout}/>
<Button title='query channel'onPress={queryChannel}/>
</View>
);
}
export default AuthProvider;