Search code examples
azure-storagerecordstreamreaderliveagora.io

Agora cloud recording not saving video in azure


static startRecording = async (resourceId, channelName, idsToUse) => {
        let startDateTime = Date.now();
        console.log("Total ID USER MAP Time = " + (Date.now() - startDateTime) / 1000);
        try {
            const request = {
                uid: '999',
                cname: `${channelName}`,
                clientRequest: {
                    token: EventService.getRecordingToken(channelName),//tocken of 999
                    recordingConfig: {
                        maxIdleTime: 120,
                        streamTypes: 2,
                        channelType: 0,
                        videoStreamType: 0,
                        subscribeVideoUids: [idsToUse.uId + ""],
                        subscribeAudioUids: [idsToUse.uId + ""],
                        subscribeUidGroup: 0
                    },
                    recordingFileConfig: {
                        avFileType: ["hls"]
                    },
                    storageConfig: {
                        accessKey: "ACCESS KEY",
                        region: 0,//The region parameter has no effect, whether or not it is set.(Ref:https://docs.agora.io/en/cloud-recording/cloud_recording_api_rest?platform=RESTful)
                        bucket: `azure-recordings/${channelName}`,
                        secretKey: "SECRET KEY",
                        vendor: 5
                    }
                }
            };
            console.log("agoraApiCallConfig", agoraApiCallConfig);
            console.log("req", request);
            const requestUrl = `${AgoraBaseUrl}/v1/apps/${AgoraAppID}/cloud_recording/resourceid/${resourceId}/mode/individual/start`;
            const start = Date.now();
            console.log("req--", requestUrl);
            const response = await axios.post(requestUrl, request, agoraApiCallConfig);

            const stop = Date.now();
            const elapsed = stop - start;

            //console.log("Total Start Recording Time = " + elapsed / 1000);
            console.log("response.data", response.data);
            if (response.status == 200 || response.status == 201) {
                return response.data;
            }
            log(response.data, "error");
            throw Error("Recording starting failed with status code: " + response.status);
        } catch (e) {
            appInsightLogHelper.trackException(e, 4);
            throw e;
        }
    };

this is my code for recording and storing data in azure can anyone guide me why the data is not moving in azure? I am going live on my app and then I try to record that live with a bot user and then store that in blob service in azure storage container.


Solution

  • I too was struggling with Agora.io and Azure integration just yesterday, and had same-ish troubles. After asking their support, I came to understand that storageConfig for Azure Storage Account must be set as follows:

    {
       vendor: 5,
       region = 0,
       accessKey = <storage account name>,
       secretKey = <access key>,
       bucket = <container name>,
       fileNamePrefix = ["directory", "subdirectory"]
    }
    

    Therefore if you want to save to storage account named "junaidstorageaccount", in container "azure-recordings" and directory {channelName}, the config you should use would be as follows:

    {
       vendor: 5,
       region: 0,
       accessKey: 'junaidstorageaccount',
       secretKey: <access key>,
       bucket: 'azure-recordings',
       fileNamePrefix: [channelName]
    }
    

    Notes:

    • region is unused, you can omit it or set to anything, I prefer to set to zero
    • Replace with access key to the Storage Account
    • fileNamePrefix: an array representing the path of directories in which to store the files. So if you want to store files in my/beautiful/directory, you'll have to pass ['my', 'beautiful', 'directory']

    As per Agora documentation (https://docs.agora.io/en/cloud-recording/integration_best_practices?platform=RESTful#a-namestart_successaensure-the-recording-service-starts-successfully), you should call query after calling start to check the recording status (it should be 4 or 5), and keep checking for all the recording duration, at intervals less than maxIdleTime.

    Wishing you best of luck!