firebase / firebase/firebase-admin-node
firebaseMessaging.sendEachForMulticast: app/network-error
- Ngôn ngữ chính
- TypeScript
- Star
- 1.7k
- Fork
- 419
- Merge trung bình
- 3 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 16
Mô tả
```
export async function pushNotification({
identifiers,
body,
metadata,
title,
link,
}: PushMessage) {
try {
logger.debug(`Push Notification: ${JSON.stringify(identifiers)}`);
const userPreIdentifiers = identifiers.users;
const teamPreIdentifiers = identifiers.teams;
const userIdentifiers: string[] = [];
if (userPreIdentifiers === "allUsers") {
const allUserIdentifiers = await getAllUsersIdentifiers();
userIdentifiers.push(...allUserIdentifiers);
} else {
const userTokens = await getUserIdentifiers({
userRefs: userPreIdentifiers || [],
});
userIdentifiers.push(...(userTokens || []));
}
const teamIdentifiers = await getTeamIdentifiers({
teamRefs: teamPreIdentifiers || [],
});
const tokens = [...(userIdentifiers || []), ...(teamIdentifiers || [])];
logger.debug("All tokens:", tokens);
if (tokens.length === 0) {
logger.debug("No tokens found for push notification");
return;
}
const message: MulticastMessage = {
tokens,
notification: {
title,
body,
},
data: metadata as { [key: string]: string },
...(link && {
webpush: {
fcmOptions: {
link,
},
},
}),
};
const response =
await firebaseConfig.firebaseMessaging.sendEachForMulticast(message);
logger.debug(
`Successfully sent push notification: ${JSON.stringify(response)}`
);
} catch (error) {
logger.error("Error sending push notification:", error);
}
}
```
```
{"responses":[{"success":false,"error":{"code":"app/network-error","message":"Error while making request: Stream closed with error code NGHTTP2_PROTOCOL_ERROR. Error code: ERR_HTTP2_STREAM_ERROR"}}],"successCount":0,"failureCount":1}
```
I am using the `"firebase-admin": "^13.0.2",` sdk. The `sendEachForMulticast` not working on my development mode (did not try yet in production). However, if I am using the `send` method it will successfully push the notification.
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu từ lệnh gọi firebaseMessaging.sendEachForMulticast được nêu trong issue và tái hiện app/network-error với firebase-admin 13.0.2 ở chế độ development. So sánh hành vi của nó với phương thức send đang hoạt động và kiểm tra response được trả về. Được xem là hoàn tất khi việc gửi multicast thành công mà không gặp lỗi giao thức HTTP/2, hoặc khi lỗi được ghi lại kèm nguyên nhân đã được xác nhận và workaround.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- node.js, typescript
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 50/100