masashi-sutou / flutter_ios_voip_kit

One-to-one video call using CallKit and PushKit with flutter iOS app.
MIT License
67 stars 45 forks source link

What is the correct way to send VoIP Push using Node (Firebase Cloud Function) #25

Open SirJAKfromSpace opened 3 years ago

SirJAKfromSpace commented 3 years ago

i'm using the @parse/node-apn npm package in my firebase cloud function to request for a push.

i seem to be getting 'notifs sent: 0 failed: 1' when printing results.sent and results.failed. i'm pretty sure that the VoIP Token being used is the one produced by the voip_kit instance (i checked logs). please can someone confirm whether I'm calling the APNs properly? any idea where the problem could be?

const options = {
    token: {                                    //  hidden for privacy
        key: __dirname + "/../AuthKey_SECRET_KEYID.p8",
        keyId: "SECRET_KEYID",
        teamId: "SECRET_TEAMID",
    },
    production: true,
};
const apnProvider = new apn.Provider(options);

export const apncallpush = functions.https.onRequest(async (req, res) => {
    const callerid = req.body.callerid;
    const callername = req.body.callername;
    const callertoken = req.body.calleetoken;

    const note = new apn.Notification();
    const deviceToken = `${callertoken}`
    note.payload = {
        "aps": {
            "alert": {
                "uuid": `f579cc8c-7127-4ca3-a9f5-dd4a591a2567`,
                "incoming_caller_id": `${callerid}`,
                "incoming_caller_name": `${callername}`,
            },
        },
    };
    note.contentAvailable = true;
    note.expiry = Math.floor(Date.now() / 1000) + 60;
    note.priority = 10;
    note.pushType = "voip";
    note.topic = "BUNDLE_ID.voip";    //  hidden for privacy

    apnProvider.send(note, deviceToken).then((result) => {
        const r = `DONE! notifs sent: ${result.sent.length} failed: ${result.failed.length}`;
        console.log(r);
    }).catch(() => {
        console.log('NOPE notif not sent');
    });

and i only have 1 iOS device not 2, so sadly i cant try out the example app. i also tried the CURL command mentioned in the doc. it connects to api.sandbox.apple and my .pem certificate verifies OK. finally it outputs:

* Connection state changed (MAX_CONCURRENT_STREAMS == 1000)!
* We are completely uploaded and fine
< HTTP/2 200 
< apns-id: A2ED1505-EE9D-CD19-955B-84669C7322A2
< 
* Connection #0 to host api.sandbox.push.apple.com left intact
* Closing connection 0
masashi-sutou commented 3 years ago

@SirJAKfromSpace

Development server: api.sandbox.push.apple.com:443 Production server: api.push.apple.com:443 https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns/

mars3142 commented 3 years ago

I do have the same problem. The curl returns 200 and my app doesn't response to it.

Edit: After compiling in release mode, the push did open the calling ui.