-
Notifications
You must be signed in to change notification settings - Fork 41
Closed
Labels
supportSupport requestsSupport requests
Description
import {
StreamVideoClient,
StreamVideoRN,
} from "@stream-io/video-react-native-sdk";
import { AndroidImportance } from "@notifee/react-native";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { chatApiKey } from "../chatConfig";
import DeviceInfo from "react-native-device-info";
import { makeApi, baseUrl } from "../api";
export function setPushConfig() {
const createStreamVideoClient = async () => {
try {
let token = await AsyncStorage.getItem("chatToken");
let id = await DeviceInfo.getUniqueId();
let name = id;
if (!token) {
const authApi = makeApi({ baseURL: baseUrl });
const response = await authApi.post(`/device/add`, {
deviceSerial: id,
});
if (response?.success) {
token = response.data.chatToken;
const chatUser = {
chatUserId: response.data.deviceSerial,
chatUserName: response.data.deviceSerial,
chatUserToken: response.data.chatToken,
};
await AsyncStorage.setItem("chatToken", response.data.chatToken);
await AsyncStorage.setItem("chatUser", JSON.stringify(chatUser));
}
}
if (!token) {
throw new Error("No token available for Stream Video client.");
}
return StreamVideoClient.getOrCreateInstance({
apiKey: chatApiKey,
user: {
id,
name,
},
tokenProvider: async () => token!,
});
console.log("Push config successful");
} catch (err: any) {
console.log("Push config failed, retrying...", err.message);
setTimeout(createStreamVideoClient, 5000);
}
};
StreamVideoRN.setPushConfig({
ios: {
pushProviderName: __DEV__
? "apn-video-staging"
: "apn-video-production",
},
android: {
smallIcon: "ic_notification",
pushProviderName:"app-android",
incomingCallChannel: {
id: "stream_incoming_call",
name: "Incoming call notifications",
importance: AndroidImportance.HIGH,
},
incomingCallNotificationTextGetters: {
getTitle: (userName: string) => `Incoming call from ${userName}`,
getBody: () => "Tap to answer the call",
getAcceptButtonTitle: () => "Accept",
getDeclineButtonTitle: () => "Decline",
},
},
createStreamVideoClient,
});
}
Metadata
Metadata
Assignees
Labels
supportSupport requestsSupport requests