Agora-Flutter-SDK icon indicating copy to clipboard operation
Agora-Flutter-SDK copied to clipboard

Add firebase cloud function sample

Open sils opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe.

Sample code for other firebase users may save them a lot of time.

Describe the solution you'd like

Add this to the docs:

const { RtcTokenBuilder, RtcRole } = require('agora-access-token')
const functions = require("firebase-functions")


export const generateToken = functions.https.onCall((data: any, context: any) => {
    const request_data = data;

    const config = functions.config().agora;
    const appID = config.app_ID;
    const appCertificate = config.app_certificate;
    const expirationTimeInSeconds = 60 * 60 * config.token_expires_hours;

    const channelName = request_data.channel;
    const uid = 0;
    const role = RtcRole.PUBLISHER;

    const currentTimestamp = Math.floor(Date.now() / 1000)
    const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds

    const token = RtcTokenBuilder.buildTokenWithUid(appID, appCertificate, channelName, uid, role, privilegeExpiredTs);
    return {
        'token': token,
        'channel': channelName,
    };
});

I wrote this code anyway and I saw similar code samples in other flutter projects - I feel it may be a useful and easy add to the docs.

Additional context

#359 is sort of a blocker or people will be very disappointed.

sils avatar Jul 01 '21 13:07 sils

I will create a wiki page to explain your issue.

LichKing-2234 avatar Sep 06 '21 04:09 LichKing-2234

@sils I've been trying with this code for quite some time, however deploying the functions to firebase seems to fail on the following code:

const { RtcTokenBuilder, RtcRole } = require('agora-access-token')

Did you manage to find a solution for that?

bgwissam avatar Oct 23 '21 12:10 bgwissam

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. If you find this problem please file a new issue with the same description, what happens, logs and the output. All system setups can be slightly different so it's always better to open new issues and reference the related ones. Thanks for your contribution.

github-actions[bot] avatar Nov 28 '23 10:11 github-actions[bot]

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please raise a new issue.

github-actions[bot] avatar Dec 05 '23 11:12 github-actions[bot]