Skip to content

Push notification ringing feature not working on app either on kill/background mode or on foreground mode #1919

@iambigmarn

Description

@iambigmarn

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

No one assigned

    Labels

    supportSupport requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions