我正在尝试使用音频视频通话功能制作一个应用程序。我已使用React本地callkeep通知接收者有关该呼叫的信息。呼叫流程如下:当呼叫者按下呼叫启动按钮时,接收者会收到一个FCM推送通知,其中包含加入房间的数据
我想在接收器应用程序处于关闭状态时唤醒接收器屏幕。为此,我使用了react native callkeep。我调用displayIncomingCall()函数来唤醒屏幕,它在IOS中运行良好,但当应用程序处于关闭状态时,在Android中不工作。
//function to call the incoming call screen
export const Display = async (uuid, handle, localizedCallerName) => {
RNCallKeep.displayIncomingCall(uuid, handle, localizedCallerName);
};
// inside index.js
messaging().setBackgroundMessageHandler(async (data) => {
if (data.data?.description == "audio" || data.data?.description == "video") {
Platform.OS == "android"
? Display(
"11edc52b-2918-4d71-9058-f7285e29d894",
"Shadowz Calling",
data?.data?.sent_by_name
)
: Display(
"11edc52b-2918-4d71-9058-f7285e29d894",
"Shadowz Calling",
data?.data?.sent_by_name,
"number",
"false"
);
}
});
您需要发送数据类型firebase通知来触发BackgroundMessageHandler
。您不能通过firebase控制台发送它,您必须向https://fcm.googleapis.com/fcm/send
api发送POST请求。下面添加了示例代码。
const sendPush = async () => {
let data = {
method: 'POST',
body: JSON.stringify({
to: '<device token>',
priority: 'high',
data: {
description:"audio"// your data here
},
}),
headers: {
'Content-Type': 'application/json',
Authorization:
'<server key>',//copy this from your project in firebase console
},
};
return fetch('https://fcm.googleapis.com/fcm/send', data)
.then(response => response.json())
.then(json => console.log('FCM Response---', json));
};
您也可以使用poster来测试这一点。
阅读有关FCM通知类型的更多信息-https://www.javatpoint.com/firebase-types-of-message