diff --git a/Agora-Restful-Recording-Nodejs/record/src/agora_node_ext/AgoraSdk.cpp b/Agora-Restful-Recording-Nodejs/record/src/agora_node_ext/AgoraSdk.cpp index ced97ec..a24c6a3 100755 --- a/Agora-Restful-Recording-Nodejs/record/src/agora_node_ext/AgoraSdk.cpp +++ b/Agora-Restful-Recording-Nodejs/record/src/agora_node_ext/AgoraSdk.cpp @@ -208,6 +208,9 @@ void AgoraSdk::onJoinChannelSuccessImpl(const char * channelId, agora::linuxsdk: void AgoraSdk::onLeaveChannelImpl(agora::linuxsdk::LEAVE_PATH_CODE code) { cout << "leave channel with code:" << code << endl; + agora::recording::node_async_call::async_call([this]() { + MAKE_JS_CALL_0(REC_EVENT_LEAVE_CHANNEL); + }); } void AgoraSdk::onUserJoinedImpl(unsigned uid, agora::linuxsdk::UserJoinInfos &infos) { diff --git a/Agora-Restful-Recording-Nodejs/record/src/agora_node_ext/AgoraSdk.h b/Agora-Restful-Recording-Nodejs/record/src/agora_node_ext/AgoraSdk.h index d5e1b17..91064de 100755 --- a/Agora-Restful-Recording-Nodejs/record/src/agora_node_ext/AgoraSdk.h +++ b/Agora-Restful-Recording-Nodejs/record/src/agora_node_ext/AgoraSdk.h @@ -40,6 +40,7 @@ struct MixModeSettings { class AgoraSdk : virtual public agora::recording::IRecordingEngineEventHandler { #define REC_EVENT_JOIN_CHANNEL "joinchannel" +#define REC_EVENT_LEAVE_CHANNEL "leavechannel" #define REC_EVENT_ERROR "error" #define REC_EVENT_USER_JOIN "userjoin" #define REC_EVENT_USER_LEAVE "userleave" diff --git a/Agora-Restful-Recording-Nodejs/server/package-lock.json b/Agora-Restful-Recording-Nodejs/server/package-lock.json index f4e8c49..5423975 100644 --- a/Agora-Restful-Recording-Nodejs/server/package-lock.json +++ b/Agora-Restful-Recording-Nodejs/server/package-lock.json @@ -9,7 +9,7 @@ "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=", "requires": { - "mime-types": "2.1.21", + "mime-types": "~2.1.18", "negotiator": "0.6.1" } }, @@ -24,15 +24,15 @@ "integrity": "sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ=", "requires": { "bytes": "3.0.0", - "content-type": "1.0.4", + "content-type": "~1.0.4", "debug": "2.6.9", - "depd": "1.1.2", - "http-errors": "1.6.3", + "depd": "~1.1.2", + "http-errors": "~1.6.3", "iconv-lite": "0.4.23", - "on-finished": "2.3.0", + "on-finished": "~2.3.0", "qs": "6.5.2", "raw-body": "2.3.3", - "type-is": "1.6.16" + "type-is": "~1.6.16" } }, "bytes": { @@ -103,36 +103,36 @@ "resolved": "https://registry.npmjs.org/express/-/express-4.16.4.tgz", "integrity": "sha512-j12Uuyb4FMrd/qQAm6uCHAkPtO8FDTRJZBDd5D2KOL2eLaz1yUNdUB/NOIyq0iU4q4cFarsUCrnFDPBcnksuOg==", "requires": { - "accepts": "1.3.5", + "accepts": "~1.3.5", "array-flatten": "1.1.1", "body-parser": "1.18.3", "content-disposition": "0.5.2", - "content-type": "1.0.4", + "content-type": "~1.0.4", "cookie": "0.3.1", "cookie-signature": "1.0.6", "debug": "2.6.9", - "depd": "1.1.2", - "encodeurl": "1.0.2", - "escape-html": "1.0.3", - "etag": "1.8.1", + "depd": "~1.1.2", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", "finalhandler": "1.1.1", "fresh": "0.5.2", "merge-descriptors": "1.0.1", - "methods": "1.1.2", - "on-finished": "2.3.0", - "parseurl": "1.3.2", + "methods": "~1.1.2", + "on-finished": "~2.3.0", + "parseurl": "~1.3.2", "path-to-regexp": "0.1.7", - "proxy-addr": "2.0.4", + "proxy-addr": "~2.0.4", "qs": "6.5.2", - "range-parser": "1.2.0", + "range-parser": "~1.2.0", "safe-buffer": "5.1.2", "send": "0.16.2", "serve-static": "1.13.2", "setprototypeof": "1.1.0", - "statuses": "1.4.0", - "type-is": "1.6.16", + "statuses": "~1.4.0", + "type-is": "~1.6.16", "utils-merge": "1.0.1", - "vary": "1.1.2" + "vary": "~1.1.2" } }, "finalhandler": { @@ -141,12 +141,12 @@ "integrity": "sha512-Y1GUDo39ez4aHAw7MysnUD5JzYX+WaIj8I57kO3aEPT1fFRL4sr7mjei97FgnwhAyyzRYmQZaTHb2+9uZ1dPtg==", "requires": { "debug": "2.6.9", - "encodeurl": "1.0.2", - "escape-html": "1.0.3", - "on-finished": "2.3.0", - "parseurl": "1.3.2", - "statuses": "1.4.0", - "unpipe": "1.0.0" + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "on-finished": "~2.3.0", + "parseurl": "~1.3.2", + "statuses": "~1.4.0", + "unpipe": "~1.0.0" } }, "forwarded": { @@ -164,10 +164,10 @@ "resolved": "http://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", "integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=", "requires": { - "depd": "1.1.2", + "depd": "~1.1.2", "inherits": "2.0.3", "setprototypeof": "1.1.0", - "statuses": "1.4.0" + "statuses": ">= 1.4.0 < 2" } }, "iconv-lite": { @@ -175,7 +175,7 @@ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz", "integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==", "requires": { - "safer-buffer": "2.1.2" + "safer-buffer": ">= 2.1.2 < 3" } }, "inherits": { @@ -218,7 +218,7 @@ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.21.tgz", "integrity": "sha512-3iL6DbwpyLzjR3xHSFNFeb9Nz/M8WDkX33t1GFQnFOllWk8pOrh/LSrB5OXlnlW5P9LH73X6loW/eogc+F5lJg==", "requires": { - "mime-db": "1.37.0" + "mime-db": "~1.37.0" } }, "ms": { @@ -254,7 +254,7 @@ "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.4.tgz", "integrity": "sha512-5erio2h9jp5CHGwcybmxmVqHmnCBZeewlfJ0pex+UW7Qny7OOZXTtH56TGNyBizkgiOwhJtMKrVzDTeKcySZwA==", "requires": { - "forwarded": "0.1.2", + "forwarded": "~0.1.2", "ipaddr.js": "1.8.0" } }, @@ -295,18 +295,18 @@ "integrity": "sha512-E64YFPUssFHEFBvpbbjr44NCLtI1AohxQ8ZSiJjQLskAdKuriYEP6VyGEsRDH8ScozGpkaX1BGvhanqCwkcEZw==", "requires": { "debug": "2.6.9", - "depd": "1.1.2", - "destroy": "1.0.4", - "encodeurl": "1.0.2", - "escape-html": "1.0.3", - "etag": "1.8.1", + "depd": "~1.1.2", + "destroy": "~1.0.4", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", "fresh": "0.5.2", - "http-errors": "1.6.3", + "http-errors": "~1.6.2", "mime": "1.4.1", "ms": "2.0.0", - "on-finished": "2.3.0", - "range-parser": "1.2.0", - "statuses": "1.4.0" + "on-finished": "~2.3.0", + "range-parser": "~1.2.0", + "statuses": "~1.4.0" } }, "serve-static": { @@ -314,9 +314,9 @@ "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz", "integrity": "sha512-p/tdJrO4U387R9oMjb1oj7qSMaMfmOyd4j9hOFoxZe2baQszgHcSWjuya/CiT5kgZZKRudHNOA0pYXOl8rQ5nw==", "requires": { - "encodeurl": "1.0.2", - "escape-html": "1.0.3", - "parseurl": "1.3.2", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "parseurl": "~1.3.2", "send": "0.16.2" } }, @@ -336,7 +336,7 @@ "integrity": "sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q==", "requires": { "media-typer": "0.3.0", - "mime-types": "2.1.21" + "mime-types": "~2.1.18" } }, "unpipe": { diff --git a/Agora-Restful-Recording-Nodejs/server/recordManager.js b/Agora-Restful-Recording-Nodejs/server/recordManager.js index 3b78ac8..9d13caa 100644 --- a/Agora-Restful-Recording-Nodejs/server/recordManager.js +++ b/Agora-Restful-Recording-Nodejs/server/recordManager.js @@ -69,7 +69,7 @@ class RecordManager{ console.error(`sdk stopped due to err code: ${err} stat: ${stat}`); console.log(`stop recorder ${appid} ${channel} ${sid}`) //clear recorder if error received - delete this.recorders[`${sid}`]; + this.onCleanup(sid) }); sdk.on("userleave", (uid) => { console.log(`user leave ${uid}`); @@ -134,9 +134,21 @@ class RecordManager{ stop(sid) { let recorder = this.recorders[sid]; if(recorder) { - let {sdk, appid, channel} = recorder; - sdk.leaveChannel(); + let {appid, channel} = recorder; console.log(`stop recorder ${appid} ${channel} ${sid}`) + this.onCleanup(sid); + } else { + throw new Error('recorder not exists'); + } + } + + onCleanup(sid) { + let recorder = this.recorders[sid]; + if(recorder) { + let {sdk} = recorder; + console.log(`releasing ${sid}`) + sdk.leaveChannel() + sdk.release() delete this.recorders[`${sid}`]; } else { throw new Error('recorder not exists');