No Description

RCTAgora.m 113KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456
  1. //
  2. // RCTAgora.m
  3. // RCTAgora
  4. //
  5. // Created by 邓博 on 2017/6/13.
  6. // Copyright © 2017年 Syan. All rights reserved.
  7. //
  8. #import "RCTAgora.h"
  9. #import <React/RCTEventDispatcher.h>
  10. #import <React/RCTBridge.h>
  11. #import <React/RCTUIManager.h>
  12. #import <React/RCTView.h>
  13. #import "AgoraConst.h"
  14. @interface RCTAgora ()
  15. @property (strong, nonatomic) AgoraRtcEngineKit *rtcEngine;
  16. @end
  17. @implementation RCTAgora {
  18. RCTResponseSenderBlock _block;
  19. bool hasListeners;
  20. }
  21. +(BOOL)requiresMainQueueSetup {
  22. return YES;
  23. }
  24. RCT_EXPORT_MODULE();
  25. - (NSError *) makeNSError:(NSDictionary *)options {
  26. NSError *error = [NSError errorWithDomain:RCTAgoraErrorDomain
  27. code:[options[@"code"] integerValue]
  28. userInfo:options[@"message"]];
  29. return error;
  30. }
  31. - (AgoraImage *) makeAgoraImage:(NSDictionary *)options {
  32. AgoraImage *img = [AgoraImage new];
  33. img.url = [NSURL URLWithString:[options[@"url"] stringValue]];
  34. img.rect = CGRectMake((CGFloat)[options[@"x"] floatValue],
  35. (CGFloat)[options[@"y"] floatValue],
  36. (CGFloat)[options[@"width"] floatValue],
  37. (CGFloat)[options[@"height"] floatValue]);
  38. return img;
  39. }
  40. - (NSDictionary *)constantsToExport {
  41. return @{
  42. @"FPS1": @(AgoraVideoFrameRateFps1),
  43. @"FPS7": @(AgoraVideoFrameRateFps7),
  44. @"FPS10": @(AgoraVideoFrameRateFps10),
  45. @"FPS15": @(AgoraVideoFrameRateFps15),
  46. @"FPS24": @(AgoraVideoFrameRateFps24),
  47. @"FPS30": @(AgoraVideoFrameRateFps30),
  48. @"FPS60": @(AgoraVideoFrameRateFps60),
  49. @"Adaptative": @(AgoraVideoOutputOrientationModeAdaptative),
  50. @"FixedLandscape": @(AgoraVideoOutputOrientationModeFixedLandscape),
  51. @"FixedPortrait": @(AgoraVideoOutputOrientationModeFixedPortrait),
  52. @"Host": @(AgoraClientRoleBroadcaster),
  53. @"Audience": @(AgoraClientRoleAudience),
  54. @"UserOfflineReasonQuit": @(AgoraUserOfflineReasonQuit),
  55. @"UserOfflineReasonDropped": @(AgoraUserOfflineReasonDropped),
  56. @"UserOfflineReasonBecomeAudience": @(AgoraUserOfflineReasonBecomeAudience),
  57. @"CodecTypeBaseLine": @(AgoraVideoCodecProfileTypeBaseLine),
  58. @"CodecTypeMain": @(AgoraVideoCodecProfileTypeMain),
  59. @"CodecTypeHigh": @(AgoraVideoCodecProfileTypeHigh),
  60. @"AudioSampleRateType32000": @(AgoraAudioSampleRateType32000),
  61. @"AudioSampleRateType44100": @(AgoraAudioSampleRateType44100),
  62. @"AudioSampleRateType48000": @(AgoraAudioSampleRateType48000),
  63. @"QualityLow": @(AgoraAudioRecordingQualityLow),
  64. @"QualityMedium": @(AgoraAudioRecordingQualityMedium),
  65. @"QualityHigh": @(AgoraAudioRecordingQualityHigh),
  66. @"Disconnected": @(AgoraConnectionStateDisconnected),
  67. @"Connecting": @(AgoraConnectionStateConnecting),
  68. @"Connected": @(AgoraConnectionStateConnected),
  69. @"Reconnecting": @(AgoraConnectionStateReconnecting),
  70. @"ConnectionFailed": @(AgoraConnectionStateFailed),
  71. @"ConnectionChangedConnecting": @(AgoraConnectionChangedConnecting),
  72. @"ConnectionChangedJoinSuccess": @(AgoraConnectionChangedJoinSuccess),
  73. @"ConnectionChangedInterrupted": @(AgoraConnectionChangedInterrupted),
  74. @"ConnectionChangedBannedByServer": @(AgoraConnectionChangedBannedByServer),
  75. @"ConnectionChangedJoinFailed": @(AgoraConnectionChangedJoinFailed),
  76. @"ConnectionChangedLeaveChannel": @(AgoraConnectionChangedLeaveChannel),
  77. @"AudioOutputRoutingDefault": @(AgoraAudioOutputRoutingDefault),
  78. @"AudioOutputRoutingHeadset": @(AgoraAudioOutputRoutingHeadset),
  79. @"AudioOutputRoutingEarpiece": @(AgoraAudioOutputRoutingEarpiece),
  80. @"AudioOutputRoutingHeadsetNoMic": @(AgoraAudioOutputRoutingHeadsetNoMic),
  81. @"AudioOutputRoutingSpeakerphone": @(AgoraAudioOutputRoutingSpeakerphone),
  82. @"AudioOutputRoutingLoudspeaker": @(AgoraAudioOutputRoutingLoudspeaker),
  83. @"AudioOutputRoutingHeadsetBluetooth": @(AgoraAudioOutputRoutingHeadsetBluetooth),
  84. @"NetworkQualityUnknown": @(AgoraNetworkQualityUnknown),
  85. @"NetworkQualityExcellent": @(AgoraNetworkQualityExcellent),
  86. @"NetworkQualityGood": @(AgoraNetworkQualityGood),
  87. @"NetworkQualityPoor": @(AgoraNetworkQualityPoor),
  88. @"NetworkQualityBad": @(AgoraNetworkQualityBad),
  89. @"NetworkQualityVBad": @(AgoraNetworkQualityVBad),
  90. @"NetworkQualityDown": @(AgoraNetworkQualityDown),
  91. @"ErrorCodeNoError": @(AgoraErrorCodeNoError),
  92. @"ErrorCodeFailed": @(AgoraErrorCodeFailed),
  93. @"ErrorCodeInvalidArgument": @(AgoraErrorCodeInvalidArgument),
  94. @"ErrorCodeTimedOut": @(AgoraErrorCodeTimedOut),
  95. @"ErrorCodeAlreadyInUse": @(AgoraErrorCodeAlreadyInUse),
  96. @"ErrorCodeAbort": @(AgoraErrorCodeAbort),
  97. @"ErrorCodeResourceLimited": @(AgoraErrorCodeResourceLimited),
  98. @"AudioProfileDefault": @(AgoraAudioProfileDefault),
  99. @"AudioProfileSpeechStandard": @(AgoraAudioProfileSpeechStandard),
  100. @"AudioProfileMusicStandard": @(AgoraAudioProfileMusicStandard),
  101. @"AudioProfileMusicStandardStereo": @(AgoraAudioProfileMusicStandardStereo),
  102. @"AudioProfileMusicHighQuality": @(AgoraAudioProfileMusicHighQuality),
  103. @"AudioProfileMusicHighQualityStereo": @(AgoraAudioProfileMusicHighQualityStereo),
  104. @"AudioScenarioDefault": @(AgoraAudioScenarioDefault),
  105. @"AudioScenarioChatRoomEntertainment": @(AgoraAudioScenarioChatRoomEntertainment),
  106. @"AudioScenarioEducation": @(AgoraAudioScenarioEducation),
  107. @"AudioScenarioGameStreaming": @(AgoraAudioScenarioGameStreaming),
  108. @"AudioScenarioShowRoom": @(AgoraAudioScenarioShowRoom),
  109. @"AudioScenarioChatRoomGaming": @(AgoraAudioScenarioChatRoomGaming),
  110. @"AudioEqualizationBand31": @(AgoraAudioEqualizationBand31),
  111. @"AudioEqualizationBand62": @(AgoraAudioEqualizationBand62),
  112. @"AudioEqualizationBand125": @(AgoraAudioEqualizationBand125),
  113. @"AudioEqualizationBand250": @(AgoraAudioEqualizationBand250),
  114. @"AudioEqualizationBand500": @(AgoraAudioEqualizationBand500),
  115. @"AudioEqualizationBand1K": @(AgoraAudioEqualizationBand1K),
  116. @"AudioEqualizationBand2K": @(AgoraAudioEqualizationBand2K),
  117. @"AudioEqualizationBand4K": @(AgoraAudioEqualizationBand4K),
  118. @"AudioEqualizationBand8K": @(AgoraAudioEqualizationBand8K),
  119. @"AudioEqualizationBand16K": @(AgoraAudioEqualizationBand16K),
  120. @"AudioRawFrameOperationModeReadOnly": @(AgoraAudioRawFrameOperationModeReadOnly),
  121. @"AudioRawFrameOperationModeWriteOnly": @(AgoraAudioRawFrameOperationModeWriteOnly),
  122. @"AudioRawFrameOperationModeReadWrite": @(AgoraAudioRawFrameOperationModeReadWrite),
  123. @"VideoStreamTypeHigh": @(AgoraVideoStreamTypeHigh),
  124. @"VideoStreamTypeLow": @(AgoraVideoStreamTypeLow),
  125. @"AgoraVideoMirrorModeAuto": @(AgoraVideoMirrorModeAuto),
  126. @"AgoraVideoMirrorModeEnabled": @(AgoraVideoMirrorModeEnabled),
  127. @"AgoraVideoMirrorModeDisabled": @(AgoraVideoMirrorModeDisabled),
  128. @"AgoraChannelProfileCommunication": @(AgoraChannelProfileCommunication),
  129. @"AgoraChannelProfileLiveBroadcasting": @(AgoraChannelProfileLiveBroadcasting),
  130. @"AgoraChannelProfileGame": @(AgoraChannelProfileGame),
  131. @"AgoraAudioMode": @(AgoraAudioMode),
  132. @"AgoraVideoMode": @(AgoraVideoMode),
  133. };
  134. }
  135. // init
  136. RCT_EXPORT_METHOD(init:(NSDictionary *)options) {
  137. [self startObserving];
  138. NSLog(@"startObserving events");
  139. [AgoraConst share].appid = options[@"appid"];
  140. self.rtcEngine = [AgoraRtcEngineKit sharedEngineWithAppId:options[@"appid"] delegate:self];
  141. [AgoraConst share].rtcEngine = self.rtcEngine;
  142. //channel mode
  143. [self.rtcEngine setChannelProfile:[options[@"channelProfile"] integerValue]];
  144. //enable dual stream
  145. if ([options objectForKey:@"dualStream"]) {
  146. [self.rtcEngine enableDualStreamMode:[options[@"dualStream"] boolValue]];
  147. }
  148. if ([options objectForKey:@"mode"]) {
  149. switch([options[@"mode"] integerValue]) {
  150. case AgoraAudioMode: {
  151. [self.rtcEngine enableAudio];
  152. [self.rtcEngine disableVideo];
  153. break;
  154. }
  155. case AgoraVideoMode: {
  156. [self.rtcEngine enableVideo];
  157. [self.rtcEngine disableAudio];
  158. break;
  159. }
  160. }
  161. } else {
  162. [self.rtcEngine enableVideo];
  163. [self.rtcEngine enableAudio];
  164. }
  165. if ([options objectForKey:@"beauty"]) {
  166. AgoraBeautyOptions *beautyOption = [[AgoraBeautyOptions alloc] init];
  167. beautyOption.lighteningContrastLevel = [options[@"beauty"][@"lighteningContrastLevel"] integerValue];
  168. beautyOption.lighteningLevel = [options[@"beauty"][@"lighteningLevel"] floatValue];
  169. beautyOption.smoothnessLevel = [options[@"beauty"][@"smoothnessLevel"] floatValue];
  170. beautyOption.rednessLevel = [options[@"beauty"][@"rednessLevel"] floatValue];
  171. [self.rtcEngine setBeautyEffectOptions:true options:beautyOption];
  172. }
  173. if ([options objectForKey:@"voice"]) {
  174. NSInteger voiceValue = [options[@"voice"][@"value"] integerValue];
  175. NSString *voiceType = options[@"voice"][@"type"];
  176. if ([voiceType isEqualToString: @"changer"]) {
  177. [self.rtcEngine setLocalVoiceChanger:(AgoraAudioVoiceChanger)voiceValue];
  178. }
  179. if ([voiceType isEqualToString: @"reverbPreset"]) {
  180. [self.rtcEngine setLocalVoiceReverbPreset:(AgoraAudioReverbPreset)voiceValue];
  181. }
  182. }
  183. if (options[@"secret"] != nil) {
  184. [self.rtcEngine setEncryptionSecret:[options[@"secret"] stringValue]];
  185. if (options[@"secretMode"] != nil) {
  186. [self.rtcEngine setEncryptionMode:[options[@"secretMode"] stringValue]];
  187. }
  188. }
  189. AgoraVideoEncoderConfiguration *video_encoder_config = [[AgoraVideoEncoderConfiguration new] initWithWidth:[options[@"videoEncoderConfig"][@"width"] integerValue] height:[options[@"videoEncoderConfig"][@"height"] integerValue] frameRate:[options[@"videoEncoderConfig"][@"frameRate"] integerValue] bitrate:[options[@"videoEncoderConfig"][@"bitrate"] integerValue] orientationMode: (AgoraVideoOutputOrientationMode)[options[@"videoEncoderConfig"][@"orientationMode"] integerValue]];
  190. [self.rtcEngine setVideoEncoderConfiguration:video_encoder_config];
  191. [self.rtcEngine setClientRole:(AgoraClientRole)[options[@"clientRole"] integerValue]];
  192. [self.rtcEngine setAudioProfile:(AgoraAudioProfile)[options[@"audioProfile"] integerValue]
  193. scenario:(AgoraAudioScenario)[options[@"audioScenario"] integerValue]];
  194. //Enable Agora Native SDK be Interoperable with Agora Web SDK
  195. [self.rtcEngine enableWebSdkInteroperability:YES];
  196. }
  197. // renew token
  198. RCT_EXPORT_METHOD(renewToken
  199. :(NSString *)token
  200. resolve:(RCTPromiseResolveBlock)resolve
  201. reject:(RCTPromiseRejectBlock)reject) {
  202. NSInteger res = [self.rtcEngine renewToken:token];
  203. if (res == 0) {
  204. resolve(@{@"success": @(YES)});
  205. } else {
  206. reject(@"131002", @"renew token failed", [self makeNSError:@{
  207. @"code": @(131002),
  208. @"message":@{
  209. @"success": @(NO),
  210. @"value":[NSNumber numberWithInteger:res]
  211. }
  212. }]);
  213. }
  214. }
  215. // enable websdk interoperability
  216. RCT_EXPORT_METHOD(enableWebSdkInteroperability: (BOOL)enabled
  217. resolve:(RCTPromiseResolveBlock)resolve
  218. reject:(RCTPromiseRejectBlock)reject) {
  219. NSInteger res = [self.rtcEngine enableWebSdkInteroperability:enabled];
  220. if (res == 0) {
  221. resolve(@{@"success": @(YES)});
  222. } else {
  223. reject(@"131003", @"renew token failed", [self makeNSError:@{
  224. @"code": @(131003),
  225. @"message":@{
  226. @"success": @(NO),
  227. @"value":[NSNumber numberWithInteger:res]
  228. }
  229. }]);
  230. }
  231. }
  232. // get agora connection state
  233. RCT_EXPORT_METHOD(getConnectionState
  234. :(RCTPromiseResolveBlock) resolve
  235. reject:(RCTPromiseRejectBlock) reject) {
  236. resolve(@{@"success": @(YES), @"state": @([self.rtcEngine getConnectionState])});
  237. }
  238. // set client role
  239. RCT_EXPORT_METHOD(setClientRole:(NSInteger) role) {
  240. [self.rtcEngine setClientRole:(AgoraClientRole)role];
  241. }
  242. // join channel
  243. RCT_EXPORT_METHOD(joinChannel:(NSDictionary *) options) {
  244. [AgoraConst share].localUid = [options[@"uid"] integerValue];
  245. [self.rtcEngine joinChannelByToken:options[@"token"] channelId:options[@"channelName"] info:options[@"info"] uid:[AgoraConst share].localUid joinSuccess:nil];
  246. }
  247. // leave channel
  248. RCT_EXPORT_METHOD(leaveChannel
  249. :(RCTPromiseResolveBlock) resolve
  250. reject:(RCTPromiseRejectBlock) reject) {
  251. int res = [self.rtcEngine leaveChannel:^(AgoraChannelStats * _Nonnull stat) {
  252. [self sendEvent:AGLeaveChannel params:@{
  253. @"message": @"leaveChannel",
  254. @"duration": @(stat.duration),
  255. @"txBytes": @(stat.txBytes),
  256. @"rxBytes": @(stat.rxBytes),
  257. @"txAudioKBitrate": @(stat.txAudioKBitrate),
  258. @"rxAudioKBitrate": @(stat.rxAudioKBitrate),
  259. @"txVideoKBitrate": @(stat.txVideoKBitrate),
  260. @"rxVideoKBitrate": @(stat.rxVideoKBitrate),
  261. @"lastmileDelay": @(stat.lastmileDelay),
  262. @"userCount": @(stat.userCount),
  263. @"cpuAppUsage": @(stat.cpuAppUsage),
  264. @"cpuTotalUsage": @(stat.cpuTotalUsage)
  265. }];
  266. }];
  267. if (res != 0) {
  268. reject(@"131038", @"leaveChannel failed", [self makeNSError:@{
  269. @"code": @(131038),
  270. @"message":@{
  271. @"success": @(NO),
  272. @"value":[NSNumber numberWithInteger:res]
  273. }
  274. }]);
  275. } else {
  276. resolve(@{
  277. @"success": @(YES),
  278. @"value": @(res)
  279. });
  280. }
  281. }
  282. // destroy
  283. RCT_EXPORT_METHOD(destroy) {
  284. [self stopObserving];
  285. [AgoraRtcEngineKit destroy];
  286. }
  287. // set local video canvas
  288. RCT_EXPORT_METHOD(setupLocalVideo:(NSDictionary *)options){
  289. AgoraRtcVideoCanvas *canvas = [AgoraRtcVideoCanvas new];
  290. canvas.uid = [AgoraConst share].localUid;
  291. canvas.view = [self.bridge.uiManager viewForReactTag:options[@"reactTag"]];
  292. canvas.renderMode = [options[@"renderMode"] integerValue];
  293. [self.rtcEngine setupLocalVideo:canvas];
  294. }
  295. // set remote video canvas
  296. RCT_EXPORT_METHOD(setupRemoteVideo:(NSDictionary *) options) {
  297. AgoraRtcVideoCanvas *canvas = [AgoraRtcVideoCanvas new];
  298. canvas.uid = [options[@"uid"] integerValue];
  299. canvas.view = [self.bridge.uiManager viewForReactTag:options[@"reactTag"]];
  300. canvas.renderMode = [options[@"renderMode"] integerValue];
  301. [self.rtcEngine setupRemoteVideo:canvas];
  302. }
  303. // set local video render mode
  304. RCT_EXPORT_METHOD(setLocalRenderMode:(NSInteger) mode) {
  305. [self.rtcEngine setLocalRenderMode:mode];
  306. }
  307. // set remote video render mode
  308. RCT_EXPORT_METHOD(setRemoteRenderMode:(NSInteger) uid
  309. mode:(NSInteger) mode) {
  310. [self.rtcEngine setRemoteRenderMode:uid mode:mode];
  311. }
  312. // start video preview
  313. RCT_EXPORT_METHOD(startPreview) {
  314. [self.rtcEngine startPreview];
  315. }
  316. // stop video preview
  317. RCT_EXPORT_METHOD(stopPreview){
  318. [self.rtcEngine stopPreview];
  319. }
  320. /* enable speaker phone
  321. * @params enableSpeaker: BOOL
  322. YES: Audio output to speaker
  323. No: Audio output to the handset
  324. */
  325. RCT_EXPORT_METHOD(setEnableSpeakerphone:(BOOL)enableSpeaker){
  326. [self.rtcEngine setEnableSpeakerphone: enableSpeaker];
  327. }
  328. /* set default audio speaker
  329. * @params defaultToSpeaker: BOOL
  330. YES: Audio output to speaker
  331. No: Audio output to the handset
  332. */
  333. RCT_EXPORT_METHOD(setDefaultAudioRouteToSpeakerphone:(BOOL)defaultToSpeaker){
  334. [self.rtcEngine setDefaultAudioRouteToSpeakerphone:defaultToSpeaker];
  335. }
  336. RCT_EXPORT_METHOD(setDefaultMuteAllRemoteAudioStreams:(BOOL)defaultToSpeaker){
  337. [self.rtcEngine setDefaultMuteAllRemoteAudioStreams:defaultToSpeaker];
  338. }
  339. // enable video
  340. RCT_EXPORT_METHOD(enableVideo) {
  341. [self.rtcEngine enableVideo];
  342. }
  343. // disable Video
  344. RCT_EXPORT_METHOD(disableVideo) {
  345. [self.rtcEngine disableVideo];
  346. }
  347. // enable local video
  348. RCT_EXPORT_METHOD(enableLocalVideo:(BOOL)enabled){
  349. [self.rtcEngine enableLocalVideo:enabled];
  350. }
  351. // mute local video stream
  352. RCT_EXPORT_METHOD(muteLocalVideoStream:(BOOL)muted) {
  353. [self.rtcEngine muteLocalVideoStream:muted];
  354. }
  355. // mute all remote video streams
  356. RCT_EXPORT_METHOD(muteAllRemoteVideoStreams:(BOOL)muted){
  357. [self.rtcEngine muteAllRemoteVideoStreams:muted];
  358. }
  359. // mute video stream by uid
  360. RCT_EXPORT_METHOD(muteRemoteVideoStream:(NSUInteger)uid mute:(BOOL)mute){
  361. [self.rtcEngine muteRemoteVideoStream:uid mute:mute];
  362. }
  363. RCT_EXPORT_METHOD(setDefaultMuteAllRemoteVideoStreams:(BOOL)mute) {
  364. [self.rtcEngine setDefaultMuteAllRemoteVideoStreams:mute];
  365. }
  366. // enable audio
  367. RCT_EXPORT_METHOD(enableAudio) {
  368. [self.rtcEngine enableAudio];
  369. }
  370. // disable audio
  371. RCT_EXPORT_METHOD(disableAudio) {
  372. [self.rtcEngine disableAudio];
  373. }
  374. // enable local audio
  375. RCT_EXPORT_METHOD(enableLocalAudio:(BOOL)enabled){
  376. [self.rtcEngine enableLocalAudio:enabled];
  377. }
  378. // mute local audio stream
  379. RCT_EXPORT_METHOD(muteLocalAudioStream:(BOOL)mute){
  380. [self.rtcEngine muteLocalAudioStream:mute];
  381. }
  382. // mute all remote audio stream
  383. RCT_EXPORT_METHOD(muteAllRemoteAudioStreams:(BOOL)mute){
  384. [self.rtcEngine muteAllRemoteAudioStreams:mute];
  385. }
  386. // mute one remote audio stream by uid
  387. RCT_EXPORT_METHOD(muteRemoteAudioStream:(NSUInteger)uid muted:(BOOL)mute){
  388. [self.rtcEngine muteRemoteAudioStream:uid mute:mute];
  389. }
  390. // adjust recorcding signal volume
  391. RCT_EXPORT_METHOD(adjustRecordingSignalVolume: (NSInteger) volume){
  392. [self.rtcEngine adjustRecordingSignalVolume:volume];
  393. }
  394. // adjust playback signal volume
  395. RCT_EXPORT_METHOD(adjustPlaybackSignalVolume: (NSInteger) volume) {
  396. [self.rtcEngine adjustPlaybackSignalVolume:volume];
  397. }
  398. // enable audio volume indication
  399. RCT_EXPORT_METHOD(enableAudioVolumeIndication: (NSInteger) interval smooth:(NSInteger)smooth) {
  400. [self.rtcEngine enableAudioVolumeIndication:interval smooth:smooth];
  401. }
  402. RCT_EXPORT_METHOD(sendMessage
  403. :(NSDictionary *)options
  404. resolve:(RCTPromiseResolveBlock)resolve
  405. reject:(RCTPromiseRejectBlock)reject) {
  406. NSInteger uid = 0;
  407. if (options[@"streamID"] != nil) {
  408. uid = [options[@"streamID"] integerValue];
  409. }
  410. NSInteger streamID = [self.rtcEngine createDataStream:&uid reliable:[options[@"reliable"] boolValue] ordered:[options[@"ordered"] boolValue]];
  411. if (streamID < 0) {
  412. reject(@"131001", @"createDataStream failed", [self makeNSError:@{
  413. @"code": @(131001),
  414. @"message":@{
  415. @"success": @(NO),
  416. @"value":[NSNumber numberWithInteger:uid]
  417. }
  418. }]);
  419. }
  420. NSString *dataStr = options[@"data"];
  421. NSData *data = [dataStr dataUsingEncoding:NSUTF8StringEncoding];
  422. NSInteger res = [self.rtcEngine sendStreamMessage:uid data:data];
  423. if (res == 0) {
  424. resolve(@{@"success": @(YES), @"streamID": @(uid)});
  425. } else {
  426. reject(@"131001", @"sendStreamMessage failed", [self makeNSError:@{
  427. @"code": @(131001),
  428. @"message":@{
  429. @"success": @(NO),
  430. @"value":[NSNumber numberWithInteger:res]
  431. }
  432. }]);
  433. }
  434. }
  435. // is speaker phone enabled
  436. RCT_EXPORT_METHOD(methodisSpeakerphoneEnabled:(RCTResponseSenderBlock)callback) {
  437. callback(@[@{@"status": @([self.rtcEngine isSpeakerphoneEnabled])}]);
  438. }
  439. // enable in ear monitoring
  440. RCT_EXPORT_METHOD(enableInEarMonitoring:(BOOL)enabled) {
  441. [self.rtcEngine enableInEarMonitoring:enabled];
  442. }
  443. // set in ear monitoring
  444. RCT_EXPORT_METHOD(setInEarMonitoringVolume:(NSInteger) volume) {
  445. [self.rtcEngine setInEarMonitoringVolume:volume];
  446. }
  447. // set local voice pitch
  448. RCT_EXPORT_METHOD(setLocalVoicePitch:(double) pitch) {
  449. [self.rtcEngine setLocalVoicePitch:pitch];
  450. }
  451. // set local video equalization of band frequency
  452. RCT_EXPORT_METHOD(setLocalVoiceEqualization:(NSInteger)band gain:(NSInteger)gain) {
  453. AgoraAudioEqualizationBandFrequency bandType = AgoraAudioEqualizationBand31;
  454. switch (band) {
  455. case AgoraAudioEqualizationBand31:
  456. bandType = AgoraAudioEqualizationBand31;
  457. break;
  458. case AgoraAudioEqualizationBand62:
  459. bandType = AgoraAudioEqualizationBand62;
  460. break;
  461. case AgoraAudioEqualizationBand125:
  462. bandType = AgoraAudioEqualizationBand125;
  463. break;
  464. case AgoraAudioEqualizationBand250:
  465. bandType = AgoraAudioEqualizationBand250;
  466. break;
  467. case AgoraAudioEqualizationBand500:
  468. bandType = AgoraAudioEqualizationBand500;
  469. break;
  470. case AgoraAudioEqualizationBand1K:
  471. bandType = AgoraAudioEqualizationBand1K;
  472. break;
  473. case AgoraAudioEqualizationBand2K:
  474. bandType = AgoraAudioEqualizationBand2K;
  475. break;
  476. case AgoraAudioEqualizationBand4K:
  477. bandType = AgoraAudioEqualizationBand4K;
  478. break;
  479. case AgoraAudioEqualizationBand8K:
  480. bandType = AgoraAudioEqualizationBand8K;
  481. break;
  482. case AgoraAudioEqualizationBand16K:
  483. bandType = AgoraAudioEqualizationBand16K;
  484. break;
  485. }
  486. [self.rtcEngine setLocalVoiceEqualizationOfBandFrequency:bandType withGain:gain];
  487. }
  488. // set local voice reverb of type
  489. RCT_EXPORT_METHOD(setLocalVoiceReverb:(NSInteger)reverb value:(NSInteger)value) {
  490. AgoraAudioReverbType reverbType = AgoraAudioReverbDryLevel;
  491. switch (reverb) {
  492. case AgoraAudioReverbDryLevel:
  493. reverbType = AgoraAudioReverbDryLevel;
  494. break;
  495. case AgoraAudioReverbWetLevel:
  496. reverbType = AgoraAudioReverbWetLevel;
  497. break;
  498. case AgoraAudioReverbRoomSize:
  499. reverbType = AgoraAudioReverbRoomSize;
  500. break;
  501. case AgoraAudioReverbWetDelay:
  502. reverbType = AgoraAudioReverbWetDelay;
  503. break;
  504. case AgoraAudioReverbStrength:
  505. reverbType = AgoraAudioReverbStrength;
  506. break;
  507. }
  508. [self.rtcEngine setLocalVoiceReverbOfType:reverb withValue:value];
  509. }
  510. // start audio mixing
  511. RCT_EXPORT_METHOD(startAudioMixing:(NSDictionary *) options) {
  512. [self.rtcEngine startAudioMixing:[options[@"filepath"] stringValue]
  513. loopback:[options[@"loopback"] boolValue]
  514. replace:[options[@"replace"] boolValue]
  515. cycle:[options[@"cycle"] integerValue]];
  516. }
  517. // stop audio mixing
  518. RCT_EXPORT_METHOD(stopAudioMixing) {
  519. [self.rtcEngine stopAudioMixing];
  520. }
  521. // pause audio mixing
  522. RCT_EXPORT_METHOD(pauseAudioMixing) {
  523. [self.rtcEngine pauseAudioMixing];
  524. }
  525. // resume audio mixing
  526. RCT_EXPORT_METHOD(resumeAudioMixing) {
  527. [self.rtcEngine resumeAudioMixing];
  528. }
  529. // adjust audio mixing volume
  530. RCT_EXPORT_METHOD(adjustAudioMixingVolume:(NSInteger) volume) {
  531. [self.rtcEngine adjustAudioMixingVolume:volume];
  532. }
  533. // adjust audio mixing playout volume
  534. RCT_EXPORT_METHOD(adjustAudioMixingPlayoutVolume:(NSInteger) volume) {
  535. [self.rtcEngine adjustAudioMixingPlayoutVolume:volume];
  536. }
  537. // adjust audio mixing publish volume
  538. RCT_EXPORT_METHOD(adjustAudioMixingPublishVolume:(NSInteger) volume) {
  539. [self.rtcEngine adjustAudioMixingPublishVolume:volume];
  540. }
  541. // get audio mixing duration
  542. RCT_EXPORT_METHOD(getAudioMixingDuration
  543. :(RCTPromiseResolveBlock)resolve
  544. reject:(RCTPromiseRejectBlock)reject) {
  545. NSInteger res = [self.rtcEngine getAudioMixingDuration];
  546. if (res != 0) {
  547. reject(@"131004", @"getAudioMixingDuration failed", [self makeNSError:@{
  548. @"code": @(131004),
  549. @"message":@{
  550. @"success": @(NO),
  551. @"value":[NSNumber numberWithInteger:res]
  552. }
  553. }]);
  554. } else {
  555. resolve(@{
  556. @"success": @(YES),
  557. @"value": @(res)
  558. });
  559. }
  560. }
  561. // get audio mixing current position
  562. RCT_EXPORT_METHOD(getAudioMixingCurrentPosition
  563. :(RCTPromiseResolveBlock)resolve
  564. reject:(RCTPromiseRejectBlock)reject) {
  565. NSInteger res = [self.rtcEngine getAudioMixingDuration];
  566. if (res != 0) {
  567. reject(@"131005", @"getAudioMixingCurrentPosition failed", [self makeNSError:@{
  568. @"code": @(131005),
  569. @"message":@{
  570. @"success": @(NO),
  571. @"value":[NSNumber numberWithInteger:res]
  572. }
  573. }]);
  574. } else {
  575. resolve(@{
  576. @"success": @(YES),
  577. @"value": @(res)
  578. });
  579. }
  580. }
  581. // set audio mixing position
  582. RCT_EXPORT_METHOD(setAudioMixingPosition
  583. :(NSInteger) pos
  584. resolve:(RCTPromiseResolveBlock)resolve
  585. reject:(RCTPromiseRejectBlock)reject) {
  586. NSInteger res = [self.rtcEngine setAudioMixingPosition:pos];
  587. if (res != 0) {
  588. reject(@"131006", @"setAudioMixingPosition failed", [self makeNSError:@{
  589. @"code": @(131006),
  590. @"message":@{
  591. @"success": @(NO),
  592. @"value":[NSNumber numberWithInteger:res]
  593. }
  594. }]);
  595. } else {
  596. resolve(@{
  597. @"success": @(YES)
  598. });
  599. }
  600. }
  601. // get effects volume
  602. RCT_EXPORT_METHOD(getEffectsVolume
  603. :(RCTPromiseResolveBlock)resolve
  604. reject:(RCTPromiseRejectBlock)reject) {
  605. double res = [self.rtcEngine getEffectsVolume];
  606. if (res != 0) {
  607. reject(@"131007", @"getEffectsVolume failed", [self makeNSError:@{
  608. @"code": @(131007),
  609. @"message":@{
  610. @"success": @(NO),
  611. @"value":@(res)
  612. }
  613. }]);
  614. } else {
  615. resolve(@{
  616. @"success": @(YES),
  617. @"value": @(res)
  618. });
  619. }
  620. }
  621. // set effects volume
  622. RCT_EXPORT_METHOD(setEffectsVolume
  623. :(double) volume
  624. resolve:(RCTPromiseResolveBlock)resolve
  625. reject:(RCTPromiseRejectBlock)reject) {
  626. NSInteger res = [self.rtcEngine setEffectsVolume:volume];
  627. if (res != 0) {
  628. reject(@"131008", @"setEffectsVolume failed", [self makeNSError:@{
  629. @"code": @(131008),
  630. @"message":@{
  631. @"success": @(NO),
  632. @"value":@(res)
  633. }
  634. }]);
  635. } else {
  636. resolve(@{
  637. @"success": @(YES),
  638. @"value": @(res)
  639. });
  640. }
  641. }
  642. // set volume of effect
  643. RCT_EXPORT_METHOD(setVolumeOfEffect
  644. :(NSInteger) soundId
  645. volume:(double)volume
  646. resolve:(RCTPromiseResolveBlock)resolve
  647. reject:(RCTPromiseRejectBlock)reject) {
  648. NSInteger res = [self.rtcEngine setVolumeOfEffect:soundId withVolume:volume];
  649. if (res != 0) {
  650. reject(@"131009", @"setVolumeOfEffect failed", [self makeNSError:@{
  651. @"code": @(131009),
  652. @"message":@{
  653. @"success": @(NO),
  654. @"value":@(res)
  655. }
  656. }]);
  657. } else {
  658. resolve(@{
  659. @"success": @(YES),
  660. @"value": @(res)
  661. });
  662. }
  663. }
  664. // play effect
  665. RCT_EXPORT_METHOD(playEffect
  666. :(NSDictionary *)options
  667. resolve:(RCTPromiseResolveBlock)resolve
  668. reject:(RCTPromiseRejectBlock)reject) {
  669. NSInteger res = [self.rtcEngine playEffect:(int)[options[@"soundid"] integerValue]
  670. filePath:[options[@"filepath"] stringValue]
  671. loopCount:(int)[options[@"loopcount"] integerValue]
  672. pitch:[options[@"pitch"] doubleValue]
  673. pan:[options[@"pan"] doubleValue]
  674. gain:[options[@"gain"] doubleValue]
  675. publish:[options[@"publish"] boolValue]];
  676. if (res != 0) {
  677. reject(@"131010", @"playEffect failed", [self makeNSError:@{
  678. @"code": @(131010),
  679. @"message":@{
  680. @"success": @(NO),
  681. @"value":@(res)
  682. }
  683. }]);
  684. } else {
  685. resolve(@{
  686. @"success": @(YES),
  687. @"value": @(res)
  688. });
  689. }
  690. }
  691. // stop effect by soundId
  692. RCT_EXPORT_METHOD(stopEffect
  693. :(NSInteger) soundId
  694. resolve:(RCTPromiseResolveBlock)resolve
  695. reject:(RCTPromiseRejectBlock)reject) {
  696. NSInteger res = [self.rtcEngine stopEffect:(int)soundId];
  697. if (res != 0) {
  698. reject(@"131011", @"stopEffect failed", [self makeNSError:@{
  699. @"code": @(131011),
  700. @"message":@{
  701. @"success": @(NO),
  702. @"value":@(res)
  703. }
  704. }]);
  705. } else {
  706. resolve(@{
  707. @"success": @(YES),
  708. @"value": @(res)
  709. });
  710. }
  711. }
  712. // stopAllEffects
  713. RCT_EXPORT_METHOD(stopAllEffects
  714. :(RCTPromiseResolveBlock)resolve
  715. reject:(RCTPromiseRejectBlock)reject) {
  716. NSInteger res = [self.rtcEngine stopAllEffects];
  717. if (res != 0) {
  718. reject(@"131012", @"stopAllEffects failed", [self makeNSError:@{
  719. @"code": @(131012),
  720. @"message":@{
  721. @"success": @(NO),
  722. @"value":@(res)
  723. }
  724. }]);
  725. } else {
  726. resolve(@{
  727. @"success": @(YES),
  728. @"value": @(res)
  729. });
  730. }
  731. }
  732. // preloadEffect
  733. RCT_EXPORT_METHOD(preloadEffect
  734. :(NSInteger) soundId
  735. filePath:(NSString *)filePath
  736. resolve:(RCTPromiseResolveBlock)resolve
  737. reject:(RCTPromiseRejectBlock)reject) {
  738. NSInteger res = [self.rtcEngine preloadEffect:(int)soundId filePath:filePath];
  739. if (res != 0) {
  740. reject(@"131013", @"preloadEffect failed", [self makeNSError:@{
  741. @"code": @(131013),
  742. @"message":@{
  743. @"success": @(NO),
  744. @"value":@(res)
  745. }
  746. }]);
  747. } else {
  748. resolve(@{
  749. @"success": @(YES),
  750. @"value": @(res)
  751. });
  752. }
  753. }
  754. // unload effect
  755. RCT_EXPORT_METHOD(unloadEffect
  756. :(NSInteger) soundId
  757. resolve:(RCTPromiseResolveBlock)resolve
  758. reject:(RCTPromiseRejectBlock)reject) {
  759. NSInteger res = [self.rtcEngine unloadEffect:(int)soundId];
  760. if (res != 0) {
  761. reject(@"131014", @"unloadEffect failed", [self makeNSError:@{
  762. @"code": @(131014),
  763. @"message":@{
  764. @"success": @(NO),
  765. @"value":@(res)
  766. }
  767. }]);
  768. } else {
  769. resolve(@{
  770. @"success": @(YES),
  771. @"value": @(res)
  772. });
  773. }
  774. }
  775. // pause effect by id
  776. RCT_EXPORT_METHOD(pauseEffect
  777. :(NSInteger) soundId
  778. resolve:(RCTPromiseResolveBlock)resolve
  779. reject:(RCTPromiseRejectBlock)reject) {
  780. NSInteger res = [self.rtcEngine pauseEffect:(int)soundId];
  781. if (res != 0) {
  782. reject(@"131014", @"pauseEffect failed", [self makeNSError:@{
  783. @"code": @(131014),
  784. @"message":@{
  785. @"success": @(NO),
  786. @"value":@(res)
  787. }
  788. }]);
  789. } else {
  790. resolve(@{
  791. @"success": @(YES),
  792. @"value": @(res)
  793. });
  794. }
  795. }
  796. // pause all effects
  797. RCT_EXPORT_METHOD(pauseAllEffects
  798. :(RCTPromiseResolveBlock)resolve
  799. reject:(RCTPromiseRejectBlock)reject) {
  800. NSInteger res = [self.rtcEngine pauseAllEffects];
  801. if (res != 0) {
  802. reject(@"131014", @"pauseAllEffects failed", [self makeNSError:@{
  803. @"code": @(131014),
  804. @"message":@{
  805. @"success": @(NO),
  806. @"value":@(res)
  807. }
  808. }]);
  809. } else {
  810. resolve(@{
  811. @"success": @(YES),
  812. @"value": @(res)
  813. });
  814. }
  815. }
  816. // resume effect by id
  817. RCT_EXPORT_METHOD(resumeEffect:(NSInteger) soundId
  818. resolve:(RCTPromiseResolveBlock)resolve
  819. reject:(RCTPromiseRejectBlock)reject) {
  820. NSInteger res = [self.rtcEngine resumeEffect:(int)soundId];
  821. if (res != 0) {
  822. reject(@"131015", @"resumeEffect failed", [self makeNSError:@{
  823. @"code": @(131015),
  824. @"message":@{
  825. @"success": @(NO),
  826. @"value":@(res)
  827. }
  828. }]);
  829. } else {
  830. resolve(@{
  831. @"success": @(YES),
  832. @"value": @(res)
  833. });
  834. }
  835. }
  836. // resume all effect
  837. RCT_EXPORT_METHOD(resumeAllEffects
  838. :(RCTPromiseResolveBlock)resolve
  839. reject:(RCTPromiseRejectBlock)reject) {
  840. NSInteger res = [self.rtcEngine resumeAllEffects];
  841. if (res != 0) {
  842. reject(@"131016", @"resumeAllEffects failed", [self makeNSError:@{
  843. @"code": @(131016),
  844. @"message":@{
  845. @"success": @(NO),
  846. @"value":@(res)
  847. }
  848. }]);
  849. } else {
  850. resolve(@{
  851. @"success": @(YES),
  852. @"value": @(res)
  853. });
  854. }
  855. }
  856. // start audio recording quality
  857. RCT_EXPORT_METHOD(startAudioRecording:(NSDictionary *)options
  858. resolve:(RCTPromiseResolveBlock)resolve
  859. reject:(RCTPromiseRejectBlock)reject) {
  860. AgoraAudioRecordingQuality qualityType = AgoraAudioRecordingQualityLow;
  861. switch ([options[@"quality"] integerValue]) {
  862. case AgoraAudioRecordingQualityLow:
  863. qualityType = AgoraAudioRecordingQualityLow;
  864. break;
  865. case AgoraAudioRecordingQualityHigh:
  866. qualityType = AgoraAudioRecordingQualityHigh;
  867. break;
  868. case AgoraAudioRecordingQualityMedium:
  869. qualityType = AgoraAudioRecordingQualityMedium;
  870. break;
  871. }
  872. NSInteger res = [self.rtcEngine startAudioRecording:[options[@"filepath"] stringValue] quality:qualityType];
  873. if (res != 0) {
  874. reject(@"131017", @"startAudioRecording failed", [self makeNSError:@{
  875. @"code": @(131017),
  876. @"message":@{
  877. @"success": @(NO),
  878. @"value":@(res)
  879. }
  880. }]);
  881. } else {
  882. resolve(@{
  883. @"success": @(YES),
  884. @"value": @(res)
  885. });
  886. }
  887. }
  888. // stop audio recording
  889. RCT_EXPORT_METHOD(stopAudioRecording
  890. :(RCTPromiseResolveBlock)resolve
  891. reject:(RCTPromiseRejectBlock)reject) {
  892. NSInteger res = [self.rtcEngine stopAudioRecording];
  893. if (res != 0) {
  894. reject(@"131018", @"stopAudioRecording failed", [self makeNSError:@{
  895. @"code": @(131018),
  896. @"message":@{
  897. @"success": @(NO),
  898. @"value":@(res)
  899. }
  900. }]);
  901. } else {
  902. resolve(@{
  903. @"success": @(YES),
  904. @"value": @(res)
  905. });
  906. }
  907. }
  908. // set audio session operation restriction
  909. RCT_EXPORT_METHOD(setAudioSessionOperationRestriction
  910. :(NSInteger) restriction) {
  911. AgoraAudioSessionOperationRestriction restrictionType = AgoraAudioSessionOperationRestrictionNone;
  912. switch (restriction) {
  913. case AgoraAudioSessionOperationRestrictionNone:
  914. restrictionType = AgoraAudioSessionOperationRestrictionNone;
  915. break;
  916. case AgoraAudioSessionOperationRestrictionSetCategory:
  917. restrictionType = AgoraAudioSessionOperationRestrictionSetCategory;
  918. break;
  919. case AgoraAudioSessionOperationRestrictionConfigureSession:
  920. restrictionType = AgoraAudioSessionOperationRestrictionConfigureSession;
  921. break;
  922. case AgoraAudioSessionOperationRestrictionDeactivateSession:
  923. restrictionType = AgoraAudioSessionOperationRestrictionDeactivateSession;
  924. break;
  925. case AgoraAudioSessionOperationRestrictionAll:
  926. restrictionType = AgoraAudioSessionOperationRestrictionAll;
  927. break;
  928. }
  929. [self.rtcEngine setAudioSessionOperationRestriction:restrictionType];
  930. }
  931. // deprecated
  932. // gateway test start echo
  933. //RCT_EXPORT_METHOD(startEchoTest
  934. // :(RCTPromiseResolveBlock)resolve
  935. // reject:(RCTPromiseRejectBlock)reject) {
  936. // NSInteger res = [self.rtcEngine startEchoTest:^(NSString * _Nonnull channel, NSUInteger uid, NSInteger elapsed) {
  937. // _block(@{
  938. // @"channel": channel,
  939. // @"uid": @(uid),
  940. // @"elapsed": @(elapsed)
  941. // });
  942. // }];
  943. // if (res != 0) {
  944. // reject(@"131019", @"startEchoTest failed", [self makeNSError:@{
  945. // @"code": @(131019),
  946. // @"message":@{
  947. // @"success": @(NO),
  948. // @"value":@(res)
  949. // }
  950. // }]);
  951. // } else {
  952. // resolve(@{
  953. // @"success": @(YES),
  954. // @"value": @(res)
  955. // });
  956. // }
  957. //}
  958. // gateway test stop echo
  959. RCT_EXPORT_METHOD(stopEchoTest
  960. :(RCTPromiseResolveBlock)resolve
  961. reject:(RCTPromiseRejectBlock)reject) {
  962. NSInteger res = [self.rtcEngine stopEchoTest];
  963. if (res != 0) {
  964. reject(@"131020", @"stopEchoTest failed", [self makeNSError:@{
  965. @"code": @(131020),
  966. @"message":@{
  967. @"success": @(NO),
  968. @"value":@(res)
  969. }
  970. }]);
  971. } else {
  972. resolve(@{
  973. @"success": @(YES),
  974. @"value": @(res)
  975. });
  976. }
  977. }
  978. // enable last mile test
  979. RCT_EXPORT_METHOD(enableLastmileTest
  980. :(RCTPromiseResolveBlock)resolve
  981. reject:(RCTPromiseRejectBlock)reject) {
  982. NSInteger res = [self.rtcEngine enableLastmileTest];
  983. if (res != 0) {
  984. reject(@"131021", @"enableLastmileTest failed", [self makeNSError:@{
  985. @"code": @(131021),
  986. @"message":@{
  987. @"success": @(NO),
  988. @"value":@(res)
  989. }
  990. }]);
  991. } else {
  992. resolve(@{
  993. @"success": @(YES),
  994. @"value": @(res)
  995. });
  996. }
  997. }
  998. // disable last mile test
  999. RCT_EXPORT_METHOD(disableLastmileTest
  1000. :(RCTPromiseResolveBlock)resolve
  1001. reject:(RCTPromiseRejectBlock)reject) {
  1002. NSInteger res = [self.rtcEngine disableLastmileTest];
  1003. if (res != 0) {
  1004. reject(@"131022", @"disableLastmileTest failed", [self makeNSError:@{
  1005. @"code": @(131022),
  1006. @"message":@{
  1007. @"success": @(NO),
  1008. @"value":@(res)
  1009. }
  1010. }]);
  1011. } else {
  1012. resolve(@{
  1013. @"success": @(YES),
  1014. @"value": @(res)
  1015. });
  1016. }
  1017. }
  1018. // set recording audioframe parameters with samplerate
  1019. RCT_EXPORT_METHOD(setRecordingAudioFrameParameters:(NSDictionary *) options
  1020. resolve:(RCTPromiseResolveBlock)resolve
  1021. reject:(RCTPromiseRejectBlock)reject) {
  1022. NSInteger res = [self.rtcEngine setRecordingAudioFrameParametersWithSampleRate:[options[@"sampleRate"] integerValue]
  1023. channel:[options[@"channel"] integerValue]
  1024. mode:(AgoraAudioRawFrameOperationMode)[options[@"mode"] integerValue]
  1025. samplesPerCall:[options[@"samplesPerCall"] integerValue]
  1026. ];
  1027. if (res != 0) {
  1028. reject(@"131023", @"setRecordingAudioFrameParameters failed", [self makeNSError:@{
  1029. @"code": @(131023),
  1030. @"message":@{
  1031. @"success": @(NO),
  1032. @"value":@(res)
  1033. }
  1034. }]);
  1035. } else {
  1036. resolve(@{
  1037. @"success": @(YES),
  1038. @"value": @(res)
  1039. });
  1040. }
  1041. }
  1042. // set playback audioframe parameters with samplerate
  1043. RCT_EXPORT_METHOD(setPlaybackAudioFrameParameters:(NSDictionary *) options
  1044. resolve:(RCTPromiseResolveBlock)resolve
  1045. reject:(RCTPromiseRejectBlock)reject) {
  1046. NSInteger res = [self.rtcEngine setPlaybackAudioFrameParametersWithSampleRate:[options[@"sampleRate"] integerValue]
  1047. channel:[options[@"channel"] integerValue]
  1048. mode:(AgoraAudioRawFrameOperationMode)[options[@"mode"] integerValue]
  1049. samplesPerCall:[options[@"samplesPerCall"] integerValue]
  1050. ];
  1051. if (res != 0) {
  1052. reject(@"131024", @"setPlaybackAudioFrameParameters failed", [self makeNSError:@{
  1053. @"code": @(131024),
  1054. @"message":@{
  1055. @"success":@(NO),
  1056. @"value":@(res)
  1057. }
  1058. }]);
  1059. } else {
  1060. resolve(@{
  1061. @"success": @(YES),
  1062. @"value": @(res)
  1063. });
  1064. }
  1065. }
  1066. // set mixed audio frame parameters with sample rate
  1067. RCT_EXPORT_METHOD(setMixedAudioFrameParametersWithSampleRate
  1068. :(NSDictionary *)options
  1069. resolve:(RCTPromiseResolveBlock)resolve
  1070. reject:(RCTPromiseRejectBlock)reject) {
  1071. NSInteger res = [self.rtcEngine setMixedAudioFrameParametersWithSampleRate:[options[@"sampleRate"] integerValue] samplesPerCall:[options[@"samplesPerCall"] integerValue]];
  1072. if (res != 0) {
  1073. reject(@"131025", @"setMixedAudioFrameParametersWithSampleRate failed", [self makeNSError:@{
  1074. @"code": @(131025),
  1075. @"message":@{
  1076. @"success":@(NO),
  1077. @"value":@(res)
  1078. }
  1079. }]);
  1080. } else {
  1081. resolve(@{
  1082. @"success": @(YES),
  1083. @"value": @(res)
  1084. });
  1085. }
  1086. }
  1087. // add video watermark
  1088. RCT_EXPORT_METHOD(addVideoWatermark:(NSDictionary *)options
  1089. resolve:(RCTPromiseResolveBlock)resolve
  1090. reject:(RCTPromiseRejectBlock)reject) {
  1091. NSInteger res = [self.rtcEngine addVideoWatermark:[self makeAgoraImage:@{
  1092. @"url": options[@"url"],
  1093. @"x": options[@"x"],
  1094. @"y": options[@"y"],
  1095. @"width": options[@"width"],
  1096. @"height": options[@"height"]
  1097. }]];
  1098. if (res != 0) {
  1099. reject(@"131026", @"addVideoWatermark failed", [self makeNSError:@{
  1100. @"code": @(131026),
  1101. @"message":@{
  1102. @"success":@(NO),
  1103. @"value":@(res)
  1104. }
  1105. }]);
  1106. } else {
  1107. resolve(@{
  1108. @"success": @(YES),
  1109. @"value": @(res)
  1110. });
  1111. }
  1112. }
  1113. // clear video watermark
  1114. RCT_EXPORT_METHOD(clearVideoWatermarks
  1115. :(RCTPromiseResolveBlock)resolve
  1116. reject:(RCTPromiseRejectBlock)reject) {
  1117. NSInteger res = [self.rtcEngine clearVideoWatermarks];
  1118. if (res != 0) {
  1119. reject(@"131027", @"clearVideoWatermarks failed", [self makeNSError:@{
  1120. @"code": @(131027),
  1121. @"message":@{
  1122. @"success":@(NO),
  1123. @"value":@(res)
  1124. }
  1125. }]);
  1126. } else {
  1127. resolve(@{
  1128. @"success": @(YES),
  1129. @"value": @(res)
  1130. });
  1131. }
  1132. }
  1133. // set local publish fallback option
  1134. RCT_EXPORT_METHOD(setLocalPublishFallbackOption:(NSInteger)option
  1135. resolve:(RCTPromiseResolveBlock)resolve
  1136. reject:(RCTPromiseRejectBlock)reject) {
  1137. NSInteger res = [self.rtcEngine setLocalPublishFallbackOption:option];
  1138. if (res != 0) {
  1139. reject(@"131039", @"setLocalPublishFallbackOption failed", [self makeNSError:@{
  1140. @"code": @(131039),
  1141. @"message":@{
  1142. @"success":@(NO),
  1143. @"value":@(res)
  1144. }
  1145. }]);
  1146. } else {
  1147. resolve(@{
  1148. @"success": @(YES),
  1149. @"value": @(res)
  1150. });
  1151. }
  1152. }
  1153. // set remote subscribe fallback option
  1154. RCT_EXPORT_METHOD(setRemoteSubscribeFallbackOption:(NSInteger)option
  1155. resolve:(RCTPromiseResolveBlock)resolve
  1156. reject:(RCTPromiseRejectBlock)reject) {
  1157. NSInteger res = [self.rtcEngine setRemoteSubscribeFallbackOption:option];
  1158. if (res != 0) {
  1159. reject(@"131040", @"setRemoteSubscribeFallbackOption failed", [self makeNSError:@{
  1160. @"code": @(131040),
  1161. @"message":@{
  1162. @"success":@(NO),
  1163. @"value":@(res)
  1164. }
  1165. }]);
  1166. } else {
  1167. resolve(@{
  1168. @"success": @(YES),
  1169. @"value": @(res)
  1170. });
  1171. }
  1172. }
  1173. // enable dual stream mode
  1174. RCT_EXPORT_METHOD(enableDualStreamMode
  1175. :(BOOL) enabled
  1176. resolve:(RCTPromiseResolveBlock)resolve
  1177. reject:(RCTPromiseRejectBlock)reject) {
  1178. NSInteger res = [self.rtcEngine enableDualStreamMode:enabled];
  1179. if (res != 0) {
  1180. reject(@"131028", @"enableDualStreamMode failed", [self makeNSError:@{
  1181. @"code": @(131028),
  1182. @"message":@{
  1183. @"success":@(NO),
  1184. @"value":@(res)
  1185. }
  1186. }]);
  1187. } else {
  1188. resolve(@{
  1189. @"success": @(YES),
  1190. @"value": @(res)
  1191. });
  1192. }
  1193. }
  1194. // set remote video stream
  1195. RCT_EXPORT_METHOD(setRemoteVideoStreamType
  1196. :(NSDictionary *) options
  1197. resolve:(RCTPromiseResolveBlock)resolve
  1198. reject:(RCTPromiseRejectBlock)reject) {
  1199. NSInteger res = [self.rtcEngine setRemoteVideoStream:[options[@"uid"] integerValue]
  1200. type:(AgoraVideoStreamType)[options[@"streamType"] integerValue]];
  1201. if (res != 0) {
  1202. reject(@"131029", @"setRemoteVideoStreamType failed", [self makeNSError:@{
  1203. @"code": @(131029),
  1204. @"message":@{
  1205. @"success":@(NO),
  1206. @"value":@(res)
  1207. }
  1208. }]);
  1209. } else {
  1210. resolve(@{
  1211. @"success": @(YES),
  1212. @"value": @(res)
  1213. });
  1214. }
  1215. }
  1216. // set remote default video stream
  1217. RCT_EXPORT_METHOD(setRemoteDefaultVideoStreamType
  1218. :(NSDictionary *) options
  1219. resolve:(RCTPromiseResolveBlock)resolve
  1220. reject:(RCTPromiseRejectBlock)reject) {
  1221. NSInteger res = [self.rtcEngine setRemoteDefaultVideoStreamType:(AgoraVideoStreamType)[options[@"streamType"] integerValue]];
  1222. if (res != 0) {
  1223. reject(@"131030", @"setRemoteDefaultVideoStreamType failed", [self makeNSError:@{
  1224. @"code": @(131030),
  1225. @"message":@{
  1226. @"success":@(NO),
  1227. @"value":@(res)
  1228. }
  1229. }]);
  1230. } else {
  1231. resolve(@{
  1232. @"success": @(YES),
  1233. @"value": @(res)
  1234. });
  1235. }
  1236. }
  1237. // add injection stream url
  1238. RCT_EXPORT_METHOD(addInjectStreamUrl
  1239. :(NSDictionary *)options
  1240. resolve:(RCTPromiseResolveBlock)resolve
  1241. reject:(RCTPromiseRejectBlock)reject) {
  1242. AgoraLiveInjectStreamConfig *config = [AgoraLiveInjectStreamConfig new];
  1243. config.size = CGSizeMake([options[@"config"][@"size"][@"width"] floatValue], [options[@"config"][@"size"][@"height"] floatValue]);
  1244. config.videoGop = [options[@"config"][@"videoGop"] integerValue];
  1245. config.videoFramerate = [options[@"config"][@"videoFramerate"] integerValue];
  1246. config.videoBitrate = [options[@"config"][@"videoBitrate"] integerValue];
  1247. config.audioSampleRate = (AgoraAudioSampleRateType)[options[@"config"][@"audioSampleRate"] integerValue];
  1248. config.audioBitrate = [options[@"config"][@"audioBitrate"] integerValue];
  1249. config.audioChannels = [options[@"config"][@"audioChannels"] integerValue];
  1250. NSInteger res = [self.rtcEngine addInjectStreamUrl:[options[@"url"] stringValue]
  1251. config:config];
  1252. if (res != 0) {
  1253. reject(@"131031", @"addInjectStreamUrl failed", [self makeNSError:@{
  1254. @"code": @(131031),
  1255. @"message":@{
  1256. @"success":@(NO),
  1257. @"value":@(res)
  1258. }
  1259. }]);
  1260. } else {
  1261. resolve(@{
  1262. @"success": @(YES),
  1263. @"value": @(res)
  1264. });
  1265. }
  1266. }
  1267. // remove injection stream url
  1268. RCT_EXPORT_METHOD(removeInjectStreamUrl
  1269. :(NSString *)url
  1270. resolve:(RCTPromiseResolveBlock)resolve
  1271. reject:(RCTPromiseRejectBlock)reject) {
  1272. NSInteger res = [self.rtcEngine removeInjectStreamUrl:url];
  1273. if (res != 0) {
  1274. reject(@"131032", @"removeInjectStreamUrl failed", [self makeNSError:@{
  1275. @"code": @(131032),
  1276. @"message":@{
  1277. @"success":@(NO),
  1278. @"value":@(res)
  1279. }
  1280. }]);
  1281. } else {
  1282. resolve(@{
  1283. @"success": @(YES),
  1284. @"value": @(res)
  1285. });
  1286. }
  1287. }
  1288. // deprecated
  1289. // set video quality
  1290. //RCT_EXPORT_METHOD(setVideoQualityParameters
  1291. // :(BOOL) quality
  1292. // resolve:(RCTPromiseResolveBlock)resolve
  1293. // reject:(RCTPromiseRejectBlock)reject) {
  1294. // NSInteger res = [self.rtcEngine setVideoQualityParameters:quality];
  1295. // if (res == 0) {
  1296. // resolve(@{@"success": @(YES)});
  1297. // } else {
  1298. // reject(@"131033", @"setVideoQualityParameters failed", [self makeNSError:@{
  1299. // @"code": @(131033),
  1300. // @"message":@{
  1301. // @"success": @(NO),
  1302. // @"value":[NSNumber numberWithInteger:res]
  1303. // }
  1304. // }]);
  1305. // }
  1306. //}
  1307. // set local video mirror mode
  1308. RCT_EXPORT_METHOD(setLocalVideoMirrorMode
  1309. :(NSInteger) mode
  1310. resolve:(RCTPromiseResolveBlock)resolve
  1311. reject:(RCTPromiseRejectBlock)reject) {
  1312. NSInteger res = [self.rtcEngine setLocalVideoMirrorMode:(AgoraVideoMirrorMode) mode];
  1313. if (res == 0) {
  1314. resolve(@{@"success": @(YES)});
  1315. } else {
  1316. reject(@"131034", @"setLocalVideoMirroMode failed", [self makeNSError:@{
  1317. @"code": @(131034),
  1318. @"message":@{
  1319. @"success": @(NO),
  1320. @"value":[NSNumber numberWithInteger:res]
  1321. }
  1322. }]);
  1323. }
  1324. }
  1325. // switchCamera
  1326. RCT_EXPORT_METHOD(switchCamera
  1327. :(RCTPromiseResolveBlock)resolve
  1328. reject:(RCTPromiseRejectBlock)reject) {
  1329. NSInteger res = [self.rtcEngine switchCamera];
  1330. if (res == 0) {
  1331. resolve(@{
  1332. @"success": @(YES),
  1333. @"value": @(res)
  1334. });
  1335. } else {
  1336. reject(@"131035", @"switchCamera failed", [self makeNSError:@{
  1337. @"code": @(131035),
  1338. @"message":@{
  1339. @"success": @(NO),
  1340. @"value":[NSNumber numberWithInteger:res]
  1341. }
  1342. }]);
  1343. }
  1344. }
  1345. // isCameraZoomSupported
  1346. RCT_EXPORT_METHOD(isCameraZoomSupported
  1347. :(RCTPromiseResolveBlock)resolve
  1348. reject:(RCTPromiseRejectBlock)reject) {
  1349. BOOL res = [self.rtcEngine isCameraZoomSupported];
  1350. resolve(@{
  1351. @"success": @(YES),
  1352. @"value": @(res)
  1353. });
  1354. }
  1355. // isCameraTorchSupported
  1356. RCT_EXPORT_METHOD(isCameraTorchSupported
  1357. :(RCTPromiseResolveBlock)resolve
  1358. reject:(RCTPromiseRejectBlock)reject) {
  1359. BOOL res = [self.rtcEngine isCameraTorchSupported];
  1360. resolve(@{
  1361. @"success": @(YES),
  1362. @"value": @(res)
  1363. });
  1364. }
  1365. // isCameraFocusSupported
  1366. RCT_EXPORT_METHOD(isCameraFocusSupported
  1367. :(RCTPromiseResolveBlock)resolve
  1368. reject:(RCTPromiseRejectBlock)reject) {
  1369. BOOL res = [self.rtcEngine isCameraFocusPositionInPreviewSupported];
  1370. resolve(@{
  1371. @"success": @(YES),
  1372. @"value": @(res)
  1373. });
  1374. }
  1375. // isCameraExposurePositionSupported
  1376. RCT_EXPORT_METHOD(isCameraExposurePositionSupported
  1377. :(RCTPromiseResolveBlock)resolve
  1378. reject:(RCTPromiseRejectBlock)reject) {
  1379. BOOL res = [self.rtcEngine isCameraExposurePositionSupported];
  1380. resolve(@{
  1381. @"success": @(YES),
  1382. @"value": @(res)
  1383. });
  1384. }
  1385. // isCameraAutoFocusFaceModeSupported
  1386. RCT_EXPORT_METHOD(isCameraAutoFocusFaceModeSupported
  1387. :(RCTPromiseResolveBlock)resolve
  1388. reject:(RCTPromiseRejectBlock)reject) {
  1389. BOOL res = [self.rtcEngine isCameraAutoFocusFaceModeSupported];
  1390. resolve(@{
  1391. @"success": @(YES),
  1392. @"value": @(res)
  1393. });
  1394. }
  1395. // setCameraZoomFactor
  1396. RCT_EXPORT_METHOD(setCameraZoomFactor
  1397. :(float)zoomFactor
  1398. resolve:(RCTPromiseResolveBlock)resolve
  1399. reject:(RCTPromiseRejectBlock)reject) {
  1400. BOOL res = [self.rtcEngine setCameraZoomFactor:(CGFloat)zoomFactor];
  1401. resolve(@{
  1402. @"success": @(YES),
  1403. @"value": @(res)
  1404. });
  1405. }
  1406. // setCameraFocusPositionInPreview
  1407. RCT_EXPORT_METHOD(setCameraFocusPositionInPreview
  1408. :(NSDictionary *)options
  1409. resolve:(RCTPromiseResolveBlock)resolve
  1410. reject:(RCTPromiseRejectBlock)reject) {
  1411. BOOL res = [self.rtcEngine setCameraFocusPositionInPreview:CGPointMake((CGFloat)[options[@"x"] floatValue], (CGFloat)[options[@"y"] floatValue])];
  1412. resolve(@{
  1413. @"success": @(YES),
  1414. @"value": @(res)
  1415. });
  1416. }
  1417. // setCameraExposurePosition
  1418. RCT_EXPORT_METHOD(setCameraExposurePosition
  1419. :(NSDictionary *)options
  1420. resolve:(RCTPromiseResolveBlock)resolve
  1421. reject:(RCTPromiseRejectBlock)reject) {
  1422. BOOL res = [self.rtcEngine setCameraExposurePosition:CGPointMake((CGFloat)[options[@"x"] floatValue], (CGFloat)[options[@"y"] floatValue])];
  1423. resolve(@{
  1424. @"success": @(YES),
  1425. @"value": @(res)
  1426. });
  1427. }
  1428. // enable camera torch
  1429. RCT_EXPORT_METHOD(setCameraTorchOn:(BOOL)isOn
  1430. resolve:(RCTPromiseResolveBlock)resolve
  1431. reject:(RCTPromiseRejectBlock)reject) {
  1432. BOOL res = [self.rtcEngine setCameraTorchOn:isOn];
  1433. resolve(@{
  1434. @"success": @(YES),
  1435. @"value": @(res)
  1436. });
  1437. }
  1438. // enable auto focus face mode
  1439. RCT_EXPORT_METHOD(setCameraAutoFocusFaceModeEnabled:(BOOL)enable
  1440. resolve:(RCTPromiseResolveBlock)resolve
  1441. reject:(RCTPromiseRejectBlock)reject) {
  1442. BOOL res = [self.rtcEngine setCameraAutoFocusFaceModeEnabled:enable];
  1443. resolve(@{
  1444. @"success": @(YES),
  1445. @"value": @(res)
  1446. });
  1447. }
  1448. // getCallId
  1449. RCT_EXPORT_METHOD(getCallId
  1450. :(RCTPromiseResolveBlock)resolve
  1451. reject:(RCTPromiseRejectBlock)reject) {
  1452. resolve(@{
  1453. @"success": @(YES),
  1454. @"value": [self.rtcEngine getCallId]
  1455. });
  1456. }
  1457. // setLogFile and setLogFilter
  1458. RCT_EXPORT_METHOD(setLog
  1459. :(NSString *)filePath
  1460. level:(NSUInteger)level
  1461. size:(NSUInteger)size
  1462. resolve:(RCTPromiseResolveBlock)resolve
  1463. reject:(RCTPromiseRejectBlock)reject) {
  1464. int res = [self.rtcEngine setLogFileSize:size];
  1465. if (res != 0) {
  1466. reject(@"131036", @"setLogFileSize failed", [self makeNSError:@{
  1467. @"code": @(131036),
  1468. @"message":@{
  1469. @"success": @(NO),
  1470. @"value":[NSNumber numberWithInteger:res]
  1471. }
  1472. }]);
  1473. } else {
  1474. resolve(@{
  1475. @"success": @(YES),
  1476. @"value": @(res)
  1477. });
  1478. }
  1479. res = [self.rtcEngine setLogFilter:level];
  1480. if (res != 0) {
  1481. reject(@"131036", @"setLogFilter failed", [self makeNSError:@{
  1482. @"code": @(131036),
  1483. @"message":@{
  1484. @"success": @(NO),
  1485. @"value":[NSNumber numberWithInteger:res]
  1486. }
  1487. }]);
  1488. } else {
  1489. resolve(@{
  1490. @"success": @(YES),
  1491. @"value": @(res)
  1492. });
  1493. }
  1494. res = [self.rtcEngine setLogFile:filePath];
  1495. if (res != 0) {
  1496. reject(@"131037", @"setLogFile failed", [self makeNSError:@{
  1497. @"code": @(131037),
  1498. @"message":@{
  1499. @"success": @(NO),
  1500. @"value":[NSNumber numberWithInteger:res]
  1501. }
  1502. }]);
  1503. } else {
  1504. resolve(@{
  1505. @"success": @(YES),
  1506. @"value": @(res)
  1507. });
  1508. }
  1509. }
  1510. // get sdk version
  1511. RCT_EXPORT_METHOD(getSdkVersion
  1512. :(RCTPromiseResolveBlock) resolve
  1513. reject:(RCTPromiseRejectBlock) reject) {
  1514. resolve(@[[AgoraRtcEngineKit getSdkVersion]]);
  1515. }
  1516. // add publish stream url
  1517. RCT_EXPORT_METHOD(addPublishStreamUrl:(NSDictionary *)options) {
  1518. [self.rtcEngine addPublishStreamUrl:options[@"url"] transcodingEnabled:[options[@"enable"] boolValue]];
  1519. }
  1520. // remove publish stream url
  1521. RCT_EXPORT_METHOD(removePublishStreamUrl:(NSDictionary *)options) {
  1522. [self.rtcEngine removePublishStreamUrl:options[@"url"]];
  1523. }
  1524. // set living transcoding
  1525. RCT_EXPORT_METHOD(setLiveTranscoding:(NSDictionary *)options) {
  1526. AgoraLiveTranscoding *transcoding = AgoraLiveTranscoding.defaultTranscoding;
  1527. if (options[@"size"] != nil) {
  1528. transcoding.size = CGSizeMake([options[@"size"][@"width"] doubleValue], [options[@"size"][@"height"] doubleValue]);
  1529. }
  1530. if (options[@"videoBitrate"] != nil) {
  1531. transcoding.videoBitrate = [options[@"videoBitrate"] integerValue];
  1532. }
  1533. if (options[@"videoFramerate"] != nil) {
  1534. transcoding.videoFramerate = [options[@"videoFramerate"] integerValue];
  1535. }
  1536. if (options[@"lowLatency"] != nil) {
  1537. transcoding.lowLatency = [options[@"lowLatancy"] boolValue];
  1538. }
  1539. if (options[@"videoGop"] != nil) {
  1540. transcoding.videoGop = [options[@"videoGop"] integerValue];
  1541. }
  1542. if (options[@"videoCodecProfile"] != nil) {
  1543. transcoding.videoCodecProfile = (AgoraVideoCodecProfileType)[options[@"videoCodecProfile"] integerValue];
  1544. }
  1545. if (options[@"transcodingUsers"] != nil) {
  1546. NSMutableArray<AgoraLiveTranscodingUser*> *transcodingUsers = [NSMutableArray new];
  1547. for (NSDictionary *optionUser in options[@"users"]) {
  1548. AgoraLiveTranscodingUser *liveUser = [AgoraLiveTranscodingUser new];
  1549. liveUser.uid = (NSUInteger)[optionUser[@"uid"] integerValue];
  1550. liveUser.rect = CGRectMake((CGFloat)[options[@"backgroundColor"][@"x"] floatValue], (CGFloat)[options[@"backgroundColor"][@"y"] floatValue], (CGFloat)[options[@"backgroundColor"][@"width"] floatValue], (CGFloat)[options[@"backgroundColor"][@"height"] floatValue]);
  1551. liveUser.zOrder = [optionUser[@"zOrder"] integerValue];
  1552. liveUser.alpha = [optionUser[@"alpha"] doubleValue];
  1553. liveUser.audioChannel = [optionUser[@"audioChannel"] integerValue];
  1554. [transcodingUsers addObject:liveUser];
  1555. }
  1556. transcoding.transcodingUsers = transcodingUsers;
  1557. }
  1558. if (options[@"transcodingExtraInfo"] != nil) {
  1559. transcoding.transcodingExtraInfo = [options[@"transcodingExtraInfo"] stringValue];
  1560. }
  1561. if (options[@"watermark"] != nil) {
  1562. transcoding.watermark = [self makeAgoraImage:@{
  1563. @"url": options[@"watermark"][@"url"],
  1564. @"x": options[@"watermark"][@"x"],
  1565. @"y": options[@"watermark"][@"y"],
  1566. @"width": options[@"watermark"][@"width"],
  1567. @"height": options[@"watermark"][@"height"]
  1568. }];
  1569. }
  1570. if (options[@"backgroundImage"] != nil) {
  1571. transcoding.backgroundImage = [self makeAgoraImage:@{
  1572. @"url": options[@"backgroundImage"][@"url"],
  1573. @"x": options[@"backgroundImage"][@"x"],
  1574. @"y": options[@"backgroundImage"][@"y"],
  1575. @"width": options[@"backgroundImage"][@"width"],
  1576. @"height": options[@"backgroundImage"][@"height"]
  1577. }];
  1578. }
  1579. if (options[@"backgroundColor"] != nil) {
  1580. transcoding.backgroundColor = [[UIColor new] initWithRed:(CGFloat)[options[@"backgroundColor"][@"red"] floatValue] green:(CGFloat)[options[@"backgroundColor"][@"green"] floatValue] blue:(CGFloat)[options[@"backgroundColor"][@"blue"] floatValue] alpha:(CGFloat)[options[@"backgroundColor"][@"alpha"] floatValue]];
  1581. }
  1582. if (options[@"audioSampleRate"] != nil) {
  1583. transcoding.audioSampleRate = (AgoraAudioSampleRateType)[options[@"audioSampleRate"] integerValue];
  1584. }
  1585. if (options[@"audioBitrate"] != nil) {
  1586. transcoding.audioBitrate = [options[@"audioBitrate"] integerValue];
  1587. }
  1588. if (options[@"audioChannels"] != nil) {
  1589. transcoding.audioChannels = [options[@"audioChannels"] integerValue];
  1590. }
  1591. [self.rtcEngine setLiveTranscoding:transcoding];
  1592. }
  1593. RCT_EXPORT_METHOD(setBeautyEffectOptions:(bool) enabled
  1594. options:(NSDictionary *)options
  1595. resolve:(RCTPromiseResolveBlock)resolve
  1596. reject:(RCTPromiseRejectBlock)reject) {
  1597. int res = [self.rtcEngine setBeautyEffectOptions:enabled options:options];
  1598. if (res != 0) {
  1599. reject(@"131037", @"setBeautyEffectOptions failed", [self makeNSError:@{
  1600. @"code": @(131037),
  1601. @"message":@{
  1602. @"success": @(NO),
  1603. @"value":[NSNumber numberWithInteger:res]
  1604. }
  1605. }]);
  1606. } else {
  1607. resolve(@{
  1608. @"success": @(YES),
  1609. @"value": @(res)
  1610. });
  1611. }
  1612. }
  1613. RCT_EXPORT_METHOD(setLocalVoiceChanger:(NSInteger) voiceChanger
  1614. resolve:(RCTPromiseResolveBlock)resolve
  1615. reject:(RCTPromiseRejectBlock)reject) {
  1616. int res = [self.rtcEngine setLocalVoiceChanger:(AgoraAudioVoiceChanger)voiceChanger];
  1617. if (res != 0) {
  1618. reject(@"131037", @"setBeautyEffectOptions failed", [self makeNSError:@{
  1619. @"code": @(131037),
  1620. @"message":@{
  1621. @"success": @(NO),
  1622. @"value":[NSNumber numberWithInteger:res]
  1623. }
  1624. }]);
  1625. } else {
  1626. resolve(@{
  1627. @"success": @(YES),
  1628. @"value": @(res)
  1629. });
  1630. }
  1631. }
  1632. RCT_EXPORT_METHOD(setLocalVoiceReverbPreset:(NSInteger) reverbPreset
  1633. resolve:(RCTPromiseResolveBlock)resolve
  1634. reject:(RCTPromiseRejectBlock)reject) {
  1635. int res = [self.rtcEngine setLocalVoiceReverbPreset:(AgoraAudioReverbPreset)reverbPreset];
  1636. if (res != 0) {
  1637. reject(@"131037", @"setLocalVoiceReverbPreset failed", [self makeNSError:@{
  1638. @"code": @(131037),
  1639. @"message":@{
  1640. @"success": @(NO),
  1641. @"value":[NSNumber numberWithInteger:res]
  1642. }
  1643. }]);
  1644. } else {
  1645. resolve(@{
  1646. @"success": @(YES),
  1647. @"value": @(res)
  1648. });
  1649. }
  1650. }
  1651. RCT_EXPORT_METHOD(enableSoundPositionIndication:(bool) enabled
  1652. resolve:(RCTPromiseResolveBlock)resolve
  1653. reject:(RCTPromiseRejectBlock)reject) {
  1654. int res = [self.rtcEngine enableSoundPositionIndication:enabled];
  1655. if (res != 0) {
  1656. reject(@"131037", @"enableSoundPositionIndication failed", [self makeNSError:@{
  1657. @"code": @(131037),
  1658. @"message":@{
  1659. @"success": @(NO),
  1660. @"value":[NSNumber numberWithInteger:res]
  1661. }
  1662. }]);
  1663. } else {
  1664. resolve(@{
  1665. @"success": @(YES),
  1666. @"value": @(res)
  1667. });
  1668. }
  1669. }
  1670. RCT_EXPORT_METHOD(setRemoteVoicePosition:(NSInteger) uid
  1671. pan:(float)pan
  1672. gain:(float)gain
  1673. resolve:(RCTPromiseResolveBlock)resolve
  1674. reject:(RCTPromiseRejectBlock)reject) {
  1675. int res = [self.rtcEngine setRemoteVoicePosition:uid pan:pan gain: gain];
  1676. if (res != 0) {
  1677. reject(@"131037", @"setRemoteVoicePosition failed", [self makeNSError:@{
  1678. @"code": @(131037),
  1679. @"message":@{
  1680. @"success": @(NO),
  1681. @"value":[NSNumber numberWithInteger:res]
  1682. }
  1683. }]);
  1684. } else {
  1685. resolve(@{
  1686. @"success": @(YES),
  1687. @"value": @(res)
  1688. });
  1689. }
  1690. }
  1691. RCT_EXPORT_METHOD(startLastmileProbeTest:(NSDictionary*)config
  1692. resolve:(RCTPromiseResolveBlock)resolve
  1693. reject:(RCTPromiseRejectBlock)reject) {
  1694. AgoraLastmileProbeConfig* probeConfig = [[AgoraLastmileProbeConfig alloc] init];
  1695. probeConfig.probeUplink = [config[@"probeUplink"] boolValue];
  1696. probeConfig.probeDownlink = [config[@"probeDownlink"] boolValue];
  1697. probeConfig.expectedUplinkBitrate = [config[@"expectedUplinkBitrate"] integerValue];
  1698. probeConfig.expectedDownlinkBitrate = [config[@"expectedDownlinkBitrate"] integerValue];
  1699. int res = [self.rtcEngine startLastmileProbeTest:probeConfig];
  1700. if (res != 0) {
  1701. reject(@"131037", @"startLastmileProbeTest failed", [self makeNSError:@{
  1702. @"code": @(131037),
  1703. @"message":@{
  1704. @"success": @(NO),
  1705. @"value":[NSNumber numberWithInteger:res]
  1706. }
  1707. }]);
  1708. } else {
  1709. resolve(@{
  1710. @"success": @(YES),
  1711. @"value": @(res)
  1712. });
  1713. }
  1714. }
  1715. RCT_EXPORT_METHOD(setRemoteUserPriority:(NSUInteger)uid
  1716. userPriority:(NSInteger)userPriority
  1717. resolve:(RCTPromiseResolveBlock)resolve
  1718. reject:(RCTPromiseRejectBlock)reject) {
  1719. int res = [self.rtcEngine setRemoteUserPriority:uid type:(AgoraUserPriority)userPriority];
  1720. if (res != 0) {
  1721. reject(@"131037", @"setRemoteUserPriority failed", [self makeNSError:@{
  1722. @"code": @(131037),
  1723. @"message":@{
  1724. @"success": @(NO),
  1725. @"value":[NSNumber numberWithInteger:res]
  1726. }
  1727. }]);
  1728. } else {
  1729. resolve(@{
  1730. @"success": @(YES),
  1731. @"value": @(res)
  1732. });
  1733. }
  1734. }
  1735. RCT_EXPORT_METHOD(startEchoTestWithInterval:(NSInteger)interval
  1736. resolve:(RCTPromiseResolveBlock)resolve
  1737. reject:(RCTPromiseRejectBlock)reject) {
  1738. int res = [self.rtcEngine startEchoTestWithInterval:interval successBlock:^(NSString * _Nonnull channel, NSUInteger uid, NSInteger elapsed) {
  1739. [self sendEvent:AGIntervalTest params:@{
  1740. @"message": @"StartEchoTestWithInterval",
  1741. @"channel": channel,
  1742. @"uid": @(uid),
  1743. @"elapsed": @(elapsed),
  1744. }];
  1745. }];
  1746. if (res != 0) {
  1747. reject(@"131037", @"startEchoTestWithInterval failed", [self makeNSError:@{
  1748. @"code": @(131037),
  1749. @"message":@{
  1750. @"success": @(NO),
  1751. @"value":[NSNumber numberWithInteger:res]
  1752. }
  1753. }]);
  1754. } else {
  1755. resolve(@{
  1756. @"success": @(YES),
  1757. @"value": @(res)
  1758. });
  1759. }
  1760. }
  1761. RCT_EXPORT_METHOD(setCameraCapturerConfiguration:(NSDictionary *)config
  1762. resolve:(RCTPromiseResolveBlock)resolve
  1763. reject:(RCTPromiseRejectBlock)reject) {
  1764. AgoraCameraCapturerConfiguration* configuration = [[AgoraCameraCapturerConfiguration alloc] init];
  1765. configuration.preference = [config[@"preference"] integerValue];
  1766. int res = [self.rtcEngine setCameraCapturerConfiguration:configuration];
  1767. if (res != 0) {
  1768. reject(@"131037", @"setCameraCapturerConfiguration failed", [self makeNSError:@{
  1769. @"code": @(131037),
  1770. @"message":@{
  1771. @"success": @(NO),
  1772. @"value":[NSNumber numberWithInteger:res]
  1773. }
  1774. }]);
  1775. } else {
  1776. resolve(@{
  1777. @"success": @(YES),
  1778. @"value": @(res)
  1779. });
  1780. }
  1781. }
  1782. - (NSArray<NSString *> *)supportedEvents {
  1783. return @[
  1784. AGWarning,
  1785. AGError,
  1786. AGApiCallExecute,
  1787. AGJoinChannelSuccess,
  1788. AGRejoinChannelSuccess,
  1789. AGLeaveChannel,
  1790. AGClientRoleChanged,
  1791. AGUserJoined,
  1792. AGUserOffline,
  1793. AGConnectionStateChanged,
  1794. AGConnectionLost,
  1795. AGTokenPrivilegeWillExpire,
  1796. AGRequestToken,
  1797. AGMicrophoneEnabled,
  1798. AGAudioVolumeIndication,
  1799. AGActiveSpeaker,
  1800. AGFirstLocalAudioFrame,
  1801. AGFirstRemoteAudioFrame,
  1802. AGVideoStopped,
  1803. AGFirstLocalVideoFrame,
  1804. AGFirstRemoteVideoDecoded,
  1805. AGFirstRemoteVideoFrame,
  1806. AGUserMuteAudio,
  1807. AGUserMuteVideo,
  1808. AGUserEnableVideo,
  1809. AGUserEnableLocalVideo,
  1810. AGVideoSizeChanged,
  1811. AGRemoteVideoStateChanged,
  1812. AGLocalPublishFallbackToAudioOnly,
  1813. AGRemoteSubscribeFallbackToAudioOnly,
  1814. AGAudioRouteChanged,
  1815. AGCameraReady,
  1816. AGCameraFocusAreaChanged,
  1817. AGCameraExposureAreaChanged,
  1818. AGRtcStats,
  1819. AGLastmileQuality,
  1820. AGNetworkQuality,
  1821. AGLocalVideoStats,
  1822. AGRemoteVideoStats,
  1823. AGRemoteAudioStats,
  1824. AGAudioTransportStatsOfUid,
  1825. AGVideoTransportStatsOfUid,
  1826. AGLocalAudioMixingFinish,
  1827. AGRemoteAudioMixingStart,
  1828. AGRemoteAudioMixingFinish,
  1829. AGAudioEffectFinish,
  1830. AGStreamPublished,
  1831. AGStreamUnpublish,
  1832. AGTranscodingUpdate,
  1833. AGStreamInjectedStatus,
  1834. AGReceiveStreamMessage,
  1835. AGOccurStreamMessageError,
  1836. AGMediaEngineLoaded,
  1837. AGMediaEngineStartCall,
  1838. AGIntervalTest,
  1839. AGAudioMixingStateChanged,
  1840. AGLastmileProbeTestResult
  1841. ];
  1842. }
  1843. - (void) sendEvent:(NSString *)msg params:(NSDictionary *)params {
  1844. if (hasListeners) {
  1845. [self sendEventWithName:msg body:params];
  1846. }
  1847. }
  1848. - (void) startObserving {
  1849. hasListeners = YES;
  1850. }
  1851. - (void) stopObserving {
  1852. hasListeners = NO;
  1853. }
  1854. #pragma mark - <AgoraRtcEngineDelegate>
  1855. // EVENT CALLBACKS
  1856. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOccurWarning:(AgoraWarningCode)warningCode {
  1857. [self sendEvent:AGWarning params:@{@"message": @"AgoraWarning", @"code": @(warningCode)}];
  1858. }
  1859. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOccurError:(AgoraErrorCode)errorCode {
  1860. [self sendEvent:AGError params:@{@"message": @"AgoraError", @"code": @(errorCode)}];
  1861. }
  1862. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didApiCallExecute:(NSInteger)error api:(NSString *_Nonnull)api result:(NSString *_Nonnull)result {
  1863. if (error != 0) {
  1864. [self sendEvent:AGError params:@{
  1865. @"api": api,
  1866. @"result": result,
  1867. @"error": @(error)
  1868. }];
  1869. } else {
  1870. [self sendEvent:AGApiCallExecute params:@{
  1871. @"api": api,
  1872. @"result": result,
  1873. @"error": @(error)
  1874. }];
  1875. }
  1876. }
  1877. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didJoinChannel:(NSString *_Nonnull)channel withUid:(NSUInteger)uid elapsed:(NSInteger)elapsed {
  1878. [self sendEvent:AGJoinChannelSuccess params:@{
  1879. @"channel": channel,
  1880. @"uid": @(uid),
  1881. @"elapsed": @(elapsed)
  1882. }];
  1883. }
  1884. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didRejoinChannel:(NSString *_Nonnull)channel withUid:(NSUInteger)uid elapsed:(NSInteger)elapsed {
  1885. [self sendEvent:AGRejoinChannelSuccess params:@{
  1886. @"channel": channel,
  1887. @"uid": @(uid),
  1888. @"elapsed": @(elapsed)
  1889. }];
  1890. }
  1891. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didLeaveChannelWithStats:(AgoraChannelStats *_Nonnull)stats {
  1892. [self sendEvent:AGLeaveChannel params:@{
  1893. @"stats": @{
  1894. @"duration": @(stats.duration),
  1895. @"txBytes": @(stats.txBytes),
  1896. @"rxBytes": @(stats.rxBytes),
  1897. @"txAudioKBitrate": @(stats.txAudioKBitrate),
  1898. @"rxAudioKBitrate": @(stats.rxVideoKBitrate),
  1899. @"txVideoKBitrate": @(stats.txVideoKBitrate),
  1900. @"rxVideoKBitrate": @(stats.rxVideoKBitrate),
  1901. @"lastmileDelay": @(stats.lastmileDelay),
  1902. @"userCount": @(stats.userCount),
  1903. @"cpuAppUsage": @(stats.cpuAppUsage),
  1904. @"cpuTotalUsage": @(stats.cpuTotalUsage)
  1905. }
  1906. }];
  1907. }
  1908. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didClientRoleChanged:(AgoraClientRole)oldRole newRole:(AgoraClientRole)newRole {
  1909. [self sendEvent:AGClientRoleChanged params:@{
  1910. @"oldRole": @(oldRole),
  1911. @"newRole": @(newRole)
  1912. }];
  1913. }
  1914. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didJoinedOfUid:(NSUInteger)uid elapsed:(NSInteger)elapsed {
  1915. [self sendEvent:AGUserJoined params:@{
  1916. @"uid": @(uid),
  1917. @"elapsed": @(elapsed)
  1918. }];
  1919. }
  1920. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOfflineOfUid:(NSUInteger)uid reason:(AgoraUserOfflineReason)reason {
  1921. [self sendEvent:AGUserOffline params:@{
  1922. @"uid": @(uid),
  1923. @"reason": @(reason)
  1924. }];
  1925. }
  1926. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine connectionChangedToState:(AgoraConnectionStateType)state reason:(AgoraConnectionChangedReason)reason {
  1927. [self sendEvent:AGConnectionStateChanged params:@{
  1928. @"state": @(state),
  1929. @"reason": @(reason)
  1930. }];
  1931. }
  1932. - (void)rtcEngineConnectionDidLost:(AgoraRtcEngineKit *_Nonnull)engine {
  1933. [self sendEvent:AGConnectionLost params:@{
  1934. @"message": @"connectionLost"
  1935. }];
  1936. }
  1937. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine tokenPrivilegeWillExpire:(NSString *_Nonnull)token {
  1938. [self sendEvent:AGTokenPrivilegeWillExpire params:@{
  1939. @"token": token
  1940. }];
  1941. }
  1942. - (void)rtcEngineRequestToken:(AgoraRtcEngineKit *_Nonnull)engine {
  1943. [self sendEvent:AGRequestToken params:@{
  1944. @"message": @"RequestToken"
  1945. }];
  1946. }
  1947. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didMicrophoneEnabled:(BOOL)enabled {
  1948. [self sendEvent:AGMicrophoneEnabled params:@{
  1949. @"enabled": @(enabled)
  1950. }];
  1951. }
  1952. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine reportAudioVolumeIndicationOfSpeakers:(NSArray<AgoraRtcAudioVolumeInfo*> *_Nonnull)speakers totalVolume:(NSInteger)totalVolume {
  1953. NSMutableArray *result = [NSMutableArray new];
  1954. for (AgoraRtcAudioVolumeInfo *speaker in speakers) {
  1955. [result addObject:@{
  1956. @"uid": @(speaker.uid),
  1957. @"volume": @(speaker.volume)
  1958. }];
  1959. }
  1960. [self sendEvent:AGAudioVolumeIndication params:@{
  1961. @"speakers": result,
  1962. @"totalVolume": @(totalVolume)
  1963. }];
  1964. }
  1965. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine activeSpeaker:(NSUInteger)speakerUid {
  1966. [self sendEvent:AGActiveSpeaker params:@{
  1967. @"uid": @(speakerUid)
  1968. }];
  1969. }
  1970. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine firstLocalAudioFrame:(NSInteger)elapsed {
  1971. [self sendEvent:AGFirstLocalAudioFrame params:@{
  1972. @"elapsed": @(elapsed)
  1973. }];
  1974. }
  1975. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine firstRemoteAudioFrameOfUid:(NSUInteger)uid elapsed:(NSInteger)elapsed {
  1976. [self sendEvent:AGFirstRemoteAudioFrame params:@{
  1977. @"uid": @(uid),
  1978. @"elapsed": @(elapsed)
  1979. }];
  1980. }
  1981. - (void)rtcEngineVideoDidStop:(AgoraRtcEngineKit *_Nonnull)engine {
  1982. [self sendEvent:AGVideoStopped params:@{
  1983. @"message": @"VideoStopped"
  1984. }];
  1985. }
  1986. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine firstLocalVideoFrameWithSize:(CGSize)size elapsed:(NSInteger)elapsed {
  1987. [self sendEvent:AGFirstLocalVideoFrame params:@{
  1988. @"width": @(size.width),
  1989. @"height": @(size.height),
  1990. @"elapsed": @(elapsed)
  1991. }];
  1992. }
  1993. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine firstRemoteVideoDecodedOfUid:(NSUInteger)uid size:(CGSize)size elapsed:(NSInteger)elapsed {
  1994. [self sendEvent:AGFirstRemoteVideoDecoded params:@{
  1995. @"uid": @(uid),
  1996. @"width": @(size.width),
  1997. @"height": @(size.height),
  1998. @"elapsed": @(elapsed)
  1999. }];
  2000. }
  2001. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine firstRemoteVideoFrameOfUid:(NSUInteger)uid size:(CGSize)size elapsed:(NSInteger)elapsed {
  2002. [self sendEvent:AGFirstRemoteVideoFrame params:@{
  2003. @"uid": @(uid),
  2004. @"width": @(size.width),
  2005. @"height": @(size.height),
  2006. @"elapsed": @(elapsed)}];
  2007. }
  2008. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didAudioMuted:(BOOL)muted byUid:(NSUInteger)uid {
  2009. [self sendEvent:AGUserMuteAudio params:@{
  2010. @"muted": @(muted),
  2011. @"uid": @(uid)
  2012. }];
  2013. }
  2014. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didVideoMuted:(BOOL)muted byUid:(NSUInteger)uid {
  2015. [self sendEvent:AGUserMuteVideo params:@{
  2016. @"muted": @(muted),
  2017. @"uid": @(uid)
  2018. }];
  2019. }
  2020. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didVideoEnabled:(BOOL)enabled byUid:(NSUInteger)uid {
  2021. [self sendEvent:AGUserEnableVideo params:@{
  2022. @"enabled": @(enabled),
  2023. @"uid": @(uid)
  2024. }];
  2025. }
  2026. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didLocalVideoEnabled:(BOOL)enabled byUid:(NSUInteger)uid {
  2027. [self sendEvent:AGUserEnableLocalVideo params:@{
  2028. @"enabled": @(enabled),
  2029. @"uid": @(uid)
  2030. }];
  2031. }
  2032. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine videoSizeChangedOfUid:(NSUInteger)uid size:(CGSize)size rotation:(NSInteger)rotation {
  2033. [self sendEvent:AGVideoSizeChanged params:@{
  2034. @"uid": @(uid),
  2035. @"width": @(size.width),
  2036. @"height": @(size.height),
  2037. @"roration": @(rotation)
  2038. }];
  2039. }
  2040. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine remoteVideoStateChangedOfUid:(NSUInteger)uid state:(AgoraVideoRemoteState)state {
  2041. [self sendEvent:AGRemoteVideoStateChanged params:@{
  2042. @"uid": @(uid),
  2043. @"state": @(state)
  2044. }];
  2045. }
  2046. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didLocalPublishFallbackToAudioOnly:(BOOL)isFallbackOrRecover {
  2047. [self sendEvent:AGLocalPublishFallbackToAudioOnly params:@{
  2048. @"isFallbackOrRecover": @(isFallbackOrRecover)
  2049. }];
  2050. }
  2051. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didRemoteSubscribeFallbackToAudioOnly:(BOOL)isFallbackOrRecover byUid:(NSUInteger)uid {
  2052. [self sendEvent:AGRemoteSubscribeFallbackToAudioOnly params:@{
  2053. @"isFallbackOrRecover": @(isFallbackOrRecover),
  2054. @"uid": @(uid)
  2055. }];
  2056. }
  2057. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didAudioRouteChanged:(AgoraAudioOutputRouting)routing {
  2058. [self sendEvent:AGAudioRouteChanged params:@{
  2059. @"routing": @(routing)
  2060. }];
  2061. }
  2062. - (void)rtcEngineCameraDidReady:(AgoraRtcEngineKit *_Nonnull)engine {
  2063. [self sendEvent:AGCameraReady params:@{
  2064. @"message": @"CameraDidReady"
  2065. }];
  2066. }
  2067. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine cameraFocusDidChangedToRect:(CGRect)rect {
  2068. [self sendEvent:AGCameraFocusAreaChanged params:@{
  2069. @"rect": @(rect)
  2070. }];
  2071. }
  2072. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine cameraExposureDidChangedToRect:(CGRect)rect {
  2073. [self sendEvent:AGCameraExposureAreaChanged params:@{
  2074. @"rect": @(rect)
  2075. }];
  2076. }
  2077. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine remoteAudioStats:(AgoraRtcRemoteAudioStats *_Nonnull)stats {
  2078. [self sendEvent:AGRemoteAudioStats params:@{
  2079. @"stats": @{
  2080. @"uid": @(stats.uid),
  2081. @"quality": @(stats.quality),
  2082. @"networkTransportDelay": @(stats.networkTransportDelay),
  2083. @"jitterBufferDelay": @(stats.jitterBufferDelay),
  2084. @"audioLossRate": @(stats.audioLossRate)
  2085. }
  2086. }];
  2087. }
  2088. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine reportRtcStats:(AgoraChannelStats *_Nonnull)stats {
  2089. [self sendEvent:AGRtcStats params:@{
  2090. @"stats": @{
  2091. @"duration": @(stats.duration),
  2092. @"txBytes": @(stats.txBytes),
  2093. @"rxBytes": @(stats.rxBytes),
  2094. @"txAudioKBitrate": @(stats.txAudioKBitrate),
  2095. @"rxAudioKBitrate": @(stats.rxAudioKBitrate),
  2096. @"txVideoKBitrate": @(stats.txVideoKBitrate),
  2097. @"rxVideoKBitrate": @(stats.rxVideoKBitrate),
  2098. @"lastmileDelay": @(stats.lastmileDelay),
  2099. @"userCount": @(stats.userCount),
  2100. @"cpuAppUsage": @(stats.cpuAppUsage),
  2101. @"cpuTotalUsage": @(stats.cpuTotalUsage)
  2102. }
  2103. }];
  2104. }
  2105. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine lastmileQuality:(AgoraNetworkQuality)quality {
  2106. [self sendEvent:AGLastmileQuality params:@{
  2107. @"quality": @(quality)
  2108. }];
  2109. }
  2110. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine networkQuality:(NSUInteger)uid txQuality:(AgoraNetworkQuality)txQuality rxQuality:(AgoraNetworkQuality)rxQuality {
  2111. [self sendEvent:AGNetworkQuality params:@{
  2112. @"uid": @(uid),
  2113. @"txQuality": @(txQuality),
  2114. @"rxQuality": @(rxQuality)
  2115. }];
  2116. }
  2117. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine localVideoStats:(AgoraRtcLocalVideoStats *_Nonnull)stats {
  2118. [self sendEvent:AGLocalVideoStats params:@{
  2119. @"stats": @{
  2120. @"sentBitrate": @(stats.sentBitrate),
  2121. @"sentFrameRate": @(stats.sentFrameRate)
  2122. }
  2123. }];
  2124. }
  2125. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine remoteVideoStats:(AgoraRtcRemoteVideoStats *_Nonnull)stats {
  2126. [self sendEvent:AGRemoteVideoStats params:@{
  2127. @"stats": @{
  2128. @"uid": @(stats.uid),
  2129. @"width": @(stats.width),
  2130. @"height": @(stats.height),
  2131. @"receivedBitrate": @(stats.receivedBitrate),
  2132. @"receivedFrameRate": @(stats.receivedFrameRate),
  2133. @"rxStreamType": @(stats.rxStreamType)
  2134. }
  2135. }];
  2136. }
  2137. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine audioTransportStatsOfUid:(NSUInteger)uid delay:(NSUInteger)delay lost:(NSUInteger)lost rxKBitRate:(NSUInteger)rxKBitRate {
  2138. [self sendEvent:AGAudioTransportStatsOfUid params:@{
  2139. @"uid": @(uid),
  2140. @"delay": @(delay),
  2141. @"lost": @(lost),
  2142. @"rxKBitrate": @(rxKBitRate)
  2143. }];
  2144. }
  2145. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine videoTransportStatsOfUid:(NSUInteger)uid delay:(NSUInteger)delay lost:(NSUInteger)lost rxKBitRate:(NSUInteger)rxKBitRate {
  2146. [self sendEvent:AGVideoTransportStatsOfUid params:@{
  2147. @"uid": @(uid),
  2148. @"delay": @(delay),
  2149. @"lost": @(lost),
  2150. @"rxKBitrate": @(rxKBitRate)
  2151. }];
  2152. }
  2153. - (void)rtcEngineLocalAudioMixingDidFinish:(AgoraRtcEngineKit *_Nonnull)engine {
  2154. [self sendEvent:AGLocalAudioMixingFinish params:@{
  2155. @"message": @"LocalAudioMixingSucceedFinish"
  2156. }];
  2157. }
  2158. - (void)rtcEngineRemoteAudioMixingDidStart:(AgoraRtcEngineKit *_Nonnull)engine {
  2159. [self sendEvent:AGRemoteAudioMixingStart params:@{
  2160. @"message": @"RemoteAudioMixingStarted"
  2161. }];
  2162. }
  2163. - (void)rtcEngineRemoteAudioMixingDidFinish:(AgoraRtcEngineKit *_Nonnull)engine {
  2164. [self sendEvent:AGRemoteAudioMixingFinish params:@{
  2165. @"message": @"RemoteAudioMixingFinish"
  2166. }];
  2167. }
  2168. - (void)rtcEngineDidAudioEffectFinish:(AgoraRtcEngineKit *_Nonnull)engine soundId:(NSInteger)soundId {
  2169. [self sendEvent:AGAudioEffectFinish params:@{
  2170. @"soundid": @(soundId)
  2171. }];
  2172. }
  2173. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine streamPublishedWithUrl:(NSString *_Nonnull)url errorCode:(AgoraErrorCode)errorCode {
  2174. [self sendEvent:AGStreamPublished params:@{
  2175. @"url": url,
  2176. @"code": @(errorCode)
  2177. }];
  2178. }
  2179. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine streamUnpublishedWithUrl:(NSString *_Nonnull)url {
  2180. [self sendEvent:AGStreamUnpublish params:@{
  2181. @"url": url,
  2182. }];
  2183. }
  2184. - (void)rtcEngineTranscodingUpdated:(AgoraRtcEngineKit *_Nonnull)engine {
  2185. [self sendEvent:AGTranscodingUpdate params:@{
  2186. @"message": @"AGTranscodingUpdate"
  2187. }];
  2188. }
  2189. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine streamInjectedStatusOfUrl:(NSString *_Nonnull)url uid:(NSUInteger)uid status:(AgoraInjectStreamStatus)status {
  2190. [self sendEvent:AGStreamInjectedStatus params:@{
  2191. @"uid": @(uid),
  2192. @"url": url,
  2193. @"status": @(status)
  2194. }];
  2195. }
  2196. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine receiveStreamMessageFromUid:(NSUInteger)uid streamId:(NSInteger)streamId data:(NSData *_Nonnull)data {
  2197. [self sendEvent:AGReceiveStreamMessage params:@{
  2198. @"uid": @(uid),
  2199. @"streamId": @(streamId),
  2200. @"data": data
  2201. }];
  2202. }
  2203. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOccurStreamMessageErrorFromUid:(NSUInteger)uid streamId:(NSInteger)streamId error:(NSInteger)error missed:(NSInteger)missed cached:(NSInteger)cached {
  2204. [self sendEvent:AGOccurStreamMessageError params:@{
  2205. @"uid": @(uid),
  2206. @"streamId": @(streamId),
  2207. @"error": @(error),
  2208. @"missed": @(missed),
  2209. @"cached": @(cached)
  2210. }];
  2211. }
  2212. - (void)rtcEngineMediaEngineDidLoaded:(AgoraRtcEngineKit *_Nonnull)engine {
  2213. [self sendEvent:AGMediaEngineLoaded params:@{
  2214. @"message": @"MediaEngineLoaded"
  2215. }];
  2216. }
  2217. - (void)rtcEngineMediaEngineDidStartCall:(AgoraRtcEngineKit *_Nonnull)engine {
  2218. [self sendEvent:AGMediaEngineStartCall params:@{
  2219. @"message": @"AGMediaEngineStartCall"
  2220. }];
  2221. }
  2222. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine localAudioMixingStateDidChanged:(AgoraAudioMixingStateCode)state errorCode:(AgoraAudioMixingErrorCode)errorCode {
  2223. [self sendEvent:AGAudioMixingStateChanged params:@{
  2224. @"message": @"AudioMixingStateChanged",
  2225. @"state": @(state),
  2226. @"errorCode": @(errorCode)
  2227. }];
  2228. }
  2229. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine lastmileProbeTestResult:(AgoraLastmileProbeResult *_Nonnull)result {
  2230. [self sendEvent:AGLastmileProbeTestResult params:@{
  2231. @"message":@"LastmileProbeTestResult",
  2232. @"result": @{
  2233. @"state": @(result.state),
  2234. @"rtt": @(result.rtt),
  2235. @"uplinkReport": @{
  2236. @"packetLossRate": @(result.uplinkReport.packetLossRate),
  2237. @"jitter": @(result.uplinkReport.jitter),
  2238. @"availableBandwidth": @(result.uplinkReport.availableBandwidth),
  2239. },
  2240. @"downlinkReport": @{
  2241. @"packetLossRate": @(result.downlinkReport.packetLossRate),
  2242. @"jitter": @(result.downlinkReport.jitter),
  2243. @"availableBandwidth": @(result.downlinkReport.availableBandwidth),
  2244. }
  2245. }
  2246. }];
  2247. }
  2248. @end