No Description

RtcEngine.native.ts 40KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  1. import {
  2. NativeModules,
  3. NativeEventEmitter,
  4. Platform
  5. } from 'react-native';
  6. import {
  7. Option, Callback,
  8. VideoOption,
  9. AudioMixingOption,
  10. DataStreamOption,
  11. PlayEffectOption,
  12. AudioRecordingOption,
  13. AudioFrameOption,
  14. MixedAudioFrameOption,
  15. ImageOption,
  16. VideoStreamOption,
  17. DefaultVideoStreamOption,
  18. InjectStreamOption,
  19. RemoveInjectStreamOption,
  20. PublishStreamOption,
  21. RemovePublishStreamOption,
  22. LiveTranscodingOption,
  23. PositionOption,
  24. BeautyOption,
  25. LastmileProbeConfig,
  26. CameraCapturerConfiguration
  27. } from "./types";
  28. const { Agora } = NativeModules;
  29. const AgoraEventEmitter = new NativeEventEmitter(Agora);
  30. /**
  31. * RtcEngine is the javascript object for control agora native sdk through react native bridge.
  32. *
  33. * You can use the RtcEngine methods to create {@link init}
  34. *
  35. * Other methods of the RtcEngine object serve for agora native sdk and set up error logging.
  36. */
  37. class RtcEngine {
  38. private static eventTypes: Set<string> = new Set<string>();
  39. /**
  40. * Creates a RtcEngine Object internal.
  41. *
  42. * This method creates and start event observer. You should call this method once.
  43. * @example `RtcEngine.init(option)`
  44. * @param options Defines the property of the client, see {@link Option} for details.
  45. */
  46. public static init(options: Option): void {
  47. Agora.init(options);
  48. }
  49. /**
  50. * join specified channel
  51. *
  52. * This method joins and begin rendering the video stream. when join succeeds.
  53. * Otherwise, it will invoke error by the event
  54. * @param channelName
  55. * @param uid
  56. * @param token
  57. * @param info
  58. */
  59. public static joinChannel(channelName: string, uid?: number, token?: string, info?: Object): void {
  60. return Agora.joinChannel({channelName, uid, token, info});
  61. }
  62. /**
  63. * add event listener
  64. *
  65. * This method subscribes specified eventType and run listener. You should call this method at first.
  66. * @param eventType
  67. * @param listener
  68. */
  69. public static on(eventType: string, listener: (...args: any[]) => any) {
  70. this.eventTypes.add(eventType);
  71. AgoraEventEmitter.addListener(eventType, listener);
  72. }
  73. /**
  74. * remove event listeners
  75. *
  76. * This method unsubscribes specified eventType related all listeners. You should call this method when you want to unsubscribe some eventType.
  77. * @param eventType
  78. */
  79. public static off(eventType: string) {
  80. AgoraEventEmitter.removeAllListeners(eventType);
  81. this.eventTypes.delete(eventType);
  82. }
  83. /**
  84. * remove all events listeners
  85. *
  86. * This method unsubscribes all eventTypes related listeners.
  87. *
  88. * @param token
  89. */
  90. public static removeAllListeners() {
  91. for (let eventType of this.eventTypes) {
  92. AgoraEventEmitter.removeAllListeners(eventType);
  93. }
  94. this.eventTypes.clear();
  95. }
  96. /**
  97. * renew token
  98. *
  99. * This method renews a new token.
  100. * @param token
  101. */
  102. public static renewToken(token: string) {
  103. return Agora.renewToken(token);
  104. }
  105. /**
  106. * enable websdk interoperability
  107. *
  108. * This method used to enable websdk interoperability, so that it can connect with agora websdk apps.
  109. *
  110. * @param enabled
  111. * @returns Promise<{success, value}>
  112. */
  113. public static enableWebSdkInteroperability(enabled: boolean): Promise<any> {
  114. return Agora.enableWebSdkInteroperability(enabled);
  115. }
  116. /**
  117. * get agora native sdk connection state
  118. *
  119. * This method gets agora native sdk connection state
  120. * @returns Promise<{success: true, state: (connection state)}>
  121. */
  122. public static getConnectionState() {
  123. return Agora.getConnectionState();
  124. }
  125. /**
  126. * change the client role
  127. *
  128. * This method changes the client of role.
  129. * @param role (audience: 0, host: 1)
  130. */
  131. public static setClientRole(role: number) {
  132. Agora.setClientRole(role);
  133. }
  134. /**
  135. * leave channel
  136. *
  137. * This method leaves the joined channel, then your video view will not render ever.
  138. * You should call it, when you dont need render video stream.
  139. *
  140. * @returns Promise<{success, value}>
  141. */
  142. public static leaveChannel(): Promise<any> {
  143. return Agora.leaveChannel();
  144. }
  145. /**
  146. * destroy
  147. *
  148. * This method stops event subscribe and destroy the RtcEngine instance's.
  149. * You should call it, when you want to destroy the engine.
  150. *
  151. * @returns Promise<{success, value}>
  152. */
  153. public static destroy(): Promise<any> {
  154. return Agora.destroy();
  155. }
  156. /**
  157. * show local video
  158. *
  159. * This method calls native sdk render canvas for local video.
  160. * @param options {@link VideoOption}
  161. */
  162. public static setupLocalVideo(options: VideoOption) {
  163. Agora.setupLocalVideo(options);
  164. }
  165. /**
  166. * show remote video
  167. *
  168. * This method calls native sdk render canvas for remote video.
  169. * @param options {@link VideoOption}
  170. */
  171. public static setupRemoteVideo(options: VideoOption) {
  172. Agora.setupRemoteVideo(options);
  173. }
  174. /**
  175. * set local video render mode
  176. *
  177. * This method calls native sdk render mode for local video.
  178. * @param mode
  179. */
  180. public static setLocalRenderMode(mode: number) {
  181. Agora.setLocalRenderMode(mode);
  182. }
  183. /**
  184. * set the specified remote video render mode
  185. *
  186. * This method calls native sdk render mode for the specified remote video.
  187. *
  188. * @param uid
  189. * @param mode
  190. */
  191. public static setRemoteRenderMode(uid: number, mode: number) {
  192. Agora.setRemoteRenderMode(uid, mode);
  193. }
  194. /**
  195. * start video preview
  196. *
  197. * This method start video preview for video.
  198. */
  199. public static startPreview() {
  200. Agora.startPreview();
  201. }
  202. /**
  203. * stop video preview
  204. *
  205. * This method stops video preview for video.
  206. */
  207. public static stopPreview() {
  208. Agora.stopPreview();
  209. }
  210. /**
  211. * set enable speaker phone
  212. *
  213. * This method set the speaker phone enable or disable by pass boolean parameter.
  214. * @param enabled
  215. */
  216. public static setEnableSpeakerphone(enabled: boolean) {
  217. Agora.setEnableSpeakerphone(enabled);
  218. }
  219. /**
  220. * set default audio speaker
  221. *
  222. * This method set the default audio speaker enable or disable by pass boolean parameter.
  223. * @param enabled
  224. */
  225. public static setDefaultAudioRouteToSpeakerphone(enabled: boolean) {
  226. Agora.setDefaultAudioRouteToSpeakerphone(enabled);
  227. }
  228. /**
  229. * set default mute all remote audio streams
  230. *
  231. * This method set default mute all remote audio streams enable or not by pass boolean parameter.
  232. * @param enabled
  233. */
  234. public static setDefaultMuteAllRemoteAudioStreams(enabled: boolean) {
  235. Agora.setDefaultMuteAllRemoteAudioStreams(enabled);
  236. }
  237. /**
  238. * enable video
  239. *
  240. * This method enables video.
  241. */
  242. public static enableVideo() {
  243. Agora.enableVideo();
  244. }
  245. /**
  246. * disable video
  247. *
  248. * This method disables video.
  249. */
  250. public static disableVideo() {
  251. Agora.disableVideo();
  252. }
  253. /**
  254. * enable local video
  255. *
  256. * This method enables the local video by the boolean parameter.
  257. * @param enabled
  258. */
  259. public static enableLocalVideo(enabled: boolean) {
  260. Agora.enableLocalVideo(enabled);
  261. }
  262. /**
  263. * mute local video stream
  264. *
  265. * This method mutes video stream by the boolean parameter.
  266. * @param muted
  267. */
  268. public static muteLocalVideoStream(muted: boolean) {
  269. Agora.muteLocalVideoStream(muted);
  270. }
  271. /**
  272. * mute all remote video streams
  273. *
  274. * This method mutes all remote streams by the boolean parameter.
  275. * @param muted
  276. */
  277. public static muteAllRemoteVideoStreams(muted: boolean) {
  278. Agora.muteAllRemoteVideoStreams(muted);
  279. }
  280. /**
  281. * mute specified remote video stream.
  282. *
  283. * This method mutes remote video stream by the number of uid and boolean parameter.
  284. * @param uid
  285. * @param muted
  286. */
  287. public static muteRemoteVideoStream(uid: number, muted: boolean) {
  288. Agora.muteRemoteVideoStream(uid, muted);
  289. }
  290. /**
  291. * set default mute all remote video stream
  292. *
  293. * This method mutes all remote video stream default by the boolean parameter.
  294. * @param muted
  295. */
  296. public static setDefaultMuteAllRemoteVideoStreams(muted: boolean) {
  297. Agora.setDefaultMuteAllRemoteVideoStreams(muted);
  298. }
  299. /**
  300. * enable audio
  301. *
  302. * This method enables audio
  303. */
  304. public static enableAudio() {
  305. Agora.enableAudio();
  306. }
  307. /**
  308. * disable audio
  309. *
  310. * This method disables audio
  311. */
  312. public static disableAudio() {
  313. Agora.disableAudio();
  314. }
  315. /**
  316. * enable local audio
  317. *
  318. * This method enables local audio by the boolean parameter.
  319. * @param enabled
  320. */
  321. public static enableLocalAudio(enabled: boolean) {
  322. Agora.enableLocalAudio(enabled);
  323. }
  324. /**
  325. * mute local audio stream
  326. *
  327. * This method mutes the local audio stream by muted.
  328. * @param muted
  329. */
  330. public static disableLocalAudio(muted: boolean) {
  331. Agora.disableLocalAudio(muted);
  332. }
  333. /**
  334. * mute all remote audio streams
  335. *
  336. * This method mutes all remote audio streams by muted
  337. */
  338. public static muteAllRemoteAudioStreams(muted: boolean) {
  339. Agora.muteAllRemoteAudioStreams(muted);
  340. }
  341. /**
  342. * mute specified remote audio stream by muted
  343. *
  344. * This method mutes specified remote audio stream by number uid and boolean muted.
  345. * @param uid
  346. * @param muted
  347. */
  348. public static muteRemoteAudioStream(uid: number, muted: boolean) {
  349. Agora.muteRemoteAudioStream(uid, muted);
  350. }
  351. /**
  352. * adjust recording signal volume
  353. *
  354. * This method adjusts recording your signal by volume.
  355. * @param volume
  356. */
  357. public static adjustRecordingSignalVolume(volume: number) {
  358. Agora.adjustRecordingSignalVolume(volume);
  359. }
  360. /**
  361. * adjust playback signal volume
  362. *
  363. * This method adjusts playback signal by volume.
  364. * @param volume
  365. */
  366. public static adjustPlaybackSignalVolume(volume: number) {
  367. Agora.adjustPlaybackSignalVolume(volume);
  368. }
  369. /**
  370. * enable audio volume indication
  371. *
  372. * This method enables audio volume by interval and smooth
  373. * @param interval
  374. * @param smooth
  375. */
  376. public static enableAudioVolumeIndication(interval: number, smooth: number) {
  377. Agora.enableAudioVolumeIndication(interval, smooth);
  378. }
  379. /**
  380. * create data stream
  381. *
  382. * This method creates data stream with options
  383. *
  384. * @param options {@link DataStreamOption}
  385. */
  386. public static createDataStream(options: DataStreamOption) {
  387. return Agora.createDataStream(options);
  388. }
  389. /**
  390. * check for mobile phone speaker enabled
  391. *
  392. * This method checks the phone speaker is enabled
  393. * @param callback
  394. */
  395. public static methodisSpeakerphoneEnabled(callback: Callback<any>) {
  396. Agora.methodisSpeakerphoneEnabled(callback);
  397. }
  398. /**
  399. * enable in-ear monitor
  400. *
  401. * This method enables in-ear monitoring by boolean parameter enabled
  402. *
  403. * @param enabled
  404. */
  405. public static enableInEarMonitoring(enabled: boolean) {
  406. Agora.enableInEarMonitoring(enabled);
  407. }
  408. /**
  409. * set in-ear monitoring volume
  410. *
  411. * This method sets the in-ear-monitoring volume by number parameter volume
  412. *
  413. * @param volume
  414. */
  415. public static setInEarMonitoringVolume(volume: number) {
  416. Agora.setInEarMonitoringVolume(volume);
  417. }
  418. /**
  419. * set local voice pitch
  420. *
  421. * This method sets the local voice pitch by float parameter pitch
  422. *
  423. * @param pitch
  424. */
  425. public static setLocalVoicePitch(pitch: number) {
  426. Agora.setLocalVoicePitch(pitch);
  427. }
  428. /**
  429. * set local voice equalization
  430. *
  431. * This method set local video equalization of band frequency by enum band number and number of gain
  432. *
  433. * @param band
  434. * @param gain
  435. */
  436. public static setLocalVoiceEqualization(band: number, gain: number) {
  437. Agora.setLocalVoiceEqualization(band ,gain);
  438. }
  439. /**
  440. * set local voice reverb
  441. *
  442. * This method sets local voice by reverb and value
  443. * @param reverb
  444. * @param value
  445. */
  446. public static setLocalVoiceReverb(reverb: number, value: number) {
  447. Agora.setLocalVoiceReverb(reverb, value);
  448. }
  449. /**
  450. * start audio mixing
  451. *
  452. * This method will start audio mixing by option config
  453. *
  454. * @param options {@link AudioMixingOption}
  455. */
  456. public static startAudioMixing(options: AudioMixingOption) {
  457. Agora.startAudioMixing(options);
  458. }
  459. /**
  460. * stop audio mixing
  461. *
  462. * This methods stops for audio mixing.
  463. */
  464. public static stopAudioMixing() {
  465. Agora.stopAudioMixing();
  466. }
  467. /**
  468. * pause audio mixing
  469. *
  470. * This method pauses for audio mixing.
  471. */
  472. public static pauseAudioMixing() {
  473. Agora.pauseAudioMixing();
  474. }
  475. /**
  476. * resume audio mixing
  477. *
  478. * This method resumes for audio mixing.
  479. */
  480. public static resumeAudioMixing() {
  481. Agora.resumeAudioMixing();
  482. }
  483. /**
  484. * adjust audio mixing volume
  485. *
  486. * This method adjusts audio mixing volume by the volume number parameter
  487. * @param volume
  488. */
  489. public static adjustAudioMixingVolume(volume: number) {
  490. Agora.adjustAudioMixingVolume(volume);
  491. }
  492. /**
  493. * adjust audio mixing playout volume
  494. *
  495. * This method adjusts audio mixing playout by the volume parameter
  496. * @param volume
  497. */
  498. public static adjustAudioMixingPlayoutVolume(volume: number) {
  499. Agora.adjustAudioMixingPlayoutVolume(volume);
  500. }
  501. /**
  502. * adjust audio mixing publish volume
  503. *
  504. * This method adjusts audio mixing publish by the volume paraemter
  505. * @param volume
  506. */
  507. public static adjustAudioMixingPublishVolume(volume: number) {
  508. Agora.adjustAudioMixingPublishVolume(volume);
  509. }
  510. /**
  511. * get audio mixing duration
  512. *
  513. * This method gets the audio mixing duration
  514. * @returns Promise<{success, value}>
  515. */
  516. public static getAudioMixingDuration(): Promise<any> {
  517. return Agora.getAudioMixingDuration();
  518. }
  519. /**
  520. * get audio mixing current position
  521. *
  522. * This method gets audio mixing current position value.
  523. * @returns Promise<{success, value}>
  524. */
  525. public static getAudioMixingCurrentPosition(): Promise<any> {
  526. return Agora.getAudioMixingCurrentPosition();
  527. }
  528. /**
  529. * set audio mixing position
  530. *
  531. * This method sets audio mixing position by the parameter pos
  532. * @param pos
  533. */
  534. public static setAudioMixingPosition(pos: number): Promise<any> {
  535. return Agora.setAudioMixingPosition(pos);
  536. }
  537. /**
  538. * get effects of volume
  539. *
  540. * This methods get audio mixing effects volume value.
  541. * @returns Promise<{success, value}>
  542. */
  543. public static getEffectsVolume(): Promise<any> {
  544. return Agora.getEffectsVolume();
  545. }
  546. /**
  547. * set effects volume
  548. *
  549. * This methods set audio mixing effects volume by float parameter.
  550. * @param volume
  551. * @returns Promise<{success, value}>
  552. */
  553. public static setEffectsVolume(volume: number): Promise<any> {
  554. return Agora.setEffectsVolume(volume);
  555. }
  556. /**
  557. * set volume for playing effects.
  558. *
  559. * This methods set for playing audio mixing effects
  560. * @returns Promise<{success, value}>
  561. */
  562. public static setVolumeOfEffect(volume: number): Promise<any> {
  563. return Agora.setVolumeOfEffect(volume);
  564. }
  565. /**
  566. * play specified effect for audio mixing
  567. *
  568. * This methos plays the specified effect of audio mixing file by option config.
  569. * @param options {@link PlayEffectOption}
  570. * @returns Promise<{success, value}>
  571. */
  572. public static playEffect(options: PlayEffectOption): Promise<any> {
  573. return Agora.playEffect(options);
  574. }
  575. /**
  576. * stop play effect for audio mixing
  577. *
  578. * This methods stops the specified effect for audio mixing file by soundid.
  579. * @param sounid
  580. * @returns Promise<{success, value}>
  581. */
  582. public static stopEffect(soundId: number): Promise<any> {
  583. return Agora.stopEffect(soundId);
  584. }
  585. /**
  586. * stop play all for effect audio mixing.
  587. *
  588. * This methods stops all effect audio mixing.
  589. * @returns Promise<{success, value}>
  590. */
  591. public static stopAllEffects(): Promise<any> {
  592. return Agora.stopAllEffects();
  593. }
  594. /**
  595. * preload effect for audio mixing file.
  596. *
  597. * This methods preloads the specified audio mixing file to memory by the soundid
  598. * @param soundid
  599. * @param filepath
  600. * @returns Promise<{success, value}>
  601. */
  602. public static preloadEffect(soundId: number, filepath: string): Promise<any> {
  603. return Agora.preloadEffect(soundId, filepath);
  604. }
  605. /**
  606. * unload effect
  607. *
  608. * This methods unload the already loaded audio mixing file from memory by the soundid.
  609. * @param soundid
  610. * @returns Promise<{success, value}>
  611. */
  612. public static unloadEffect(soundId: number): Promise<any> {
  613. return Agora.unloadEffect(soundId);
  614. }
  615. /**
  616. * pause the specified effect for audio mixing by soundid
  617. *
  618. * This method pauses the specified effect for audio mixing by soundid.
  619. * @param soundid
  620. * @returns Promise<{success, value}>
  621. */
  622. public static pauseEffect(soundId: number): Promise<any> {
  623. return Agora.pauseEffect(soundId);
  624. }
  625. /**
  626. * pause all effects for audio mixing
  627. *
  628. * This method pause all effects for audio mixing.
  629. * @param soundid
  630. * @returns Promise<{success, value}>
  631. */
  632. public static pauseAllEffects(): Promise<any> {
  633. return Agora.pauseAllEffects();
  634. }
  635. /**
  636. * resume audio mixing effect by the specified soundid
  637. *
  638. * This method resumes audio mixing effect by the specified soundid
  639. * @param soundid
  640. * @returns Promise<{success, value}>
  641. */
  642. public static resumeEffect(soundId: number): Promise<any> {
  643. return Agora.resumeEffect(soundId);
  644. }
  645. /**
  646. * resume all audio mixing effects.
  647. *
  648. * This method resumes all audio mixing effects.
  649. * @returns Promise<{success, value}>
  650. */
  651. public static resumeAllEffects(): Promise<any> {
  652. return Agora.resumeAllEffects();
  653. }
  654. /**
  655. * start audio recording by quality
  656. *
  657. * This method start audio recording by quality config
  658. * @param options {@link AudioRecordingOption}
  659. * @returns Promise<{success, value}>
  660. */
  661. public static startAudioRecording(options: AudioRecordingOption): Promise<any> {
  662. return Agora.startAudioRecording(options);
  663. }
  664. /**
  665. * stop audio recording
  666. *
  667. * This method stops audio recording.
  668. * @returns Promise<{success, value}>
  669. */
  670. public static stopAudioRecording(): Promise<any> {
  671. return Agora.stopAudioRecording();
  672. }
  673. /**
  674. * set audio session operation restriction
  675. *
  676. * The SDK and the app can both configure the audio session by default. The app may occasionally use other apps or third-party components to manipulate the audio session and restrict the SDK from doing so. This method allows the app to restrict the SDK’s manipulation of the audio session.
  677. * You can call this method at any time to return the control of the audio sessions to the SDK.
  678. * This method restricts the SDK’s manipulation of the audio session. Any operation to the audio session relies solely on the app, other apps, or third-party components.
  679. * @notice iOS support only
  680. */
  681. public static setAudioSessionOperationRestriction() {
  682. if (Platform.OS != 'ios') throw Error(`setAudioSessionOperationRestriction is not support on your platform. Please check the details in react-native-agora docs`);
  683. Agora.setAudioSessionOperationRestriction();
  684. }
  685. /**
  686. * @deprecated
  687. * start echo test
  688. *
  689. * This method launches an audio call test to determine whether the audio devices (for example, headset and speaker) and the network connection are working properly.
  690. * @returns Promise<{success, value}>
  691. */
  692. // public static startEchoTest(): Promise<any> {
  693. // return Agora.startEchoTest();
  694. // }
  695. /**
  696. * stop echo test
  697. *
  698. * This method stop launched an audio call test.
  699. * @returns Promise<{success, value}>
  700. */
  701. public static stopEchoTest(): Promise<any> {
  702. return Agora.stopEchoTest();
  703. }
  704. /**
  705. * enable lastmile test
  706. *
  707. * This method enables the network connection qualit test.
  708. *
  709. * @returns Promise<{success, value}>
  710. */
  711. public static enableLastmileTest(): Promise<any> {
  712. return Agora.enableLastmileTest();
  713. }
  714. /**
  715. * disable lastmile test
  716. *
  717. * This method disable the network connection qualit test.
  718. *
  719. * @returns Promise<{success, value}>
  720. */
  721. public static disableLastmileTest(): Promise<any> {
  722. return Agora.disableLastmileTest();
  723. }
  724. /**
  725. * set recording audio frame parameters
  726. *
  727. * This method Sets the audio recording format for the audioFrame callback.
  728. *
  729. * @param options {@link RecordingAudioFrameOption}
  730. * @returns Promise<{success, value}>
  731. */
  732. public static setRecordingAudioFrameParameters(options: AudioFrameOption): Promise<any> {
  733. return Agora.setRecordingAudioFrameParameters(options);
  734. }
  735. /**
  736. * set playback audio frame parameters
  737. *
  738. * This method Sets the audio frame format for the playbackFrame callback.
  739. *
  740. * @param options {@link AudioFrameOption}
  741. * @returns Promise<{success, value}>
  742. */
  743. public static setPlaybackAudioFrameParameters(options: AudioFrameOption): Promise<any> {
  744. return Agora.setPlaybackAudioFrameParameters(options);
  745. }
  746. /**
  747. * set mixed audio frame parameters
  748. *
  749. * This method Sets the audio frame format for the mixedAudioFrame callback.
  750. *
  751. * @param options {@link MixedAudioFrameOption}
  752. * @returns Promise<{success, value}>
  753. */
  754. public static setMixedAudioFrameParameters(options: MixedAudioFrameOption): Promise<any> {
  755. return Agora.setMixedAudioFrameParameters(options);
  756. }
  757. /**
  758. * add video watermark
  759. *
  760. * This method adds video watermark to the local video.
  761. *
  762. * @param options {@link ImageOption}
  763. * @returns Promise<{success, value}>
  764. */
  765. public static addVideoWatermark(options: ImageOption): Promise<any> {
  766. return Agora.addVideoWatermark(options);
  767. }
  768. /**
  769. * clear video watermarks
  770. *
  771. * This method removes the watermark image from the video stream added by addVideoWatermark.
  772. *
  773. * @returns Promise<{success, value}>
  774. */
  775. public static removclearVideoWatermarkse(): Promise<any> {
  776. return Agora.clearVideoWatermarks();
  777. }
  778. /**
  779. * set local publish fallback
  780. *
  781. * This method sets the fallback option for the locally published video stream based on the network conditions.
  782. *
  783. * @param option {0, 1, 2} [more details](https://docs.agora.io/en/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_constants.html#a3e453c93766e783a7e5eca05b1776238)
  784. * @returns Promise<{success, value}>
  785. */
  786. public static setLocalPublishFallbackOption(option: number): Promise<any> {
  787. return Agora.setLocalPublishFallbackOption(option);
  788. }
  789. /**
  790. * set remote publish fallback
  791. *
  792. * This method sets the fallback option for the remotely subscribed video stream based on the network conditions.
  793. *
  794. * @param option {0, 1, 2} [more details](https://docs.agora.io/en/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_constants.html#a3e453c93766e783a7e5eca05b1776238)
  795. * @returns Promise<{success, value}>
  796. */
  797. public static setRemoteSubscribeFallbackOption(option: number): Promise<any> {
  798. return Agora.setRemoteSubscribeFallbackOption(option);
  799. }
  800. /**
  801. * enable dual stream mode
  802. *
  803. * This method enables the dual stream by parameter mode.
  804. *
  805. * @param enabled
  806. * @returns Promise<{success, value}>
  807. */
  808. public static enableDualStreamMode(enabled: boolean): Promise<any> {
  809. return Agora.enableDualStreamMode(enabled);
  810. }
  811. /**
  812. * set remote video stream type
  813. *
  814. * This method sets the remote video stream type by uid and streamType.
  815. *
  816. * @param options {@link VideoStreamOption}
  817. * @returns Promise<{success, value}>
  818. */
  819. public static setRemoteVideoStreamType(options: VideoStreamOption): Promise<any> {
  820. return Agora.setRemoteVideoStreamType(options);
  821. }
  822. /**
  823. * set remote default video stream type
  824. *
  825. * This method sets the default video stream type.
  826. *
  827. * @param options {@link DefaultVideoStreamOption}
  828. * @returns Promise<{success, value}>
  829. */
  830. public static setRemoteDefaultVideoStreamType(options: DefaultVideoStreamOption): Promise<any> {
  831. return Agora.setRemoteDefaultVideoStreamType(options);
  832. }
  833. /**
  834. * add inject stream url
  835. *
  836. * This method injects an online media stream to a live broadcast.
  837. *
  838. * @param options {@link InjectStreamOption}
  839. * @returns Promise<{success, value}>
  840. */
  841. public static addInjectStreamUrl(options: InjectStreamOption): Promise<any> {
  842. return Agora.addInjectStreamUrl(options);
  843. }
  844. /**
  845. * remove inject stream url
  846. *
  847. * This method removes stream by addInjectsStreamUrl.
  848. *
  849. * @param options {@link RemoveInjectStreamOption}
  850. * @returns Promise<{success, value}>
  851. */
  852. public static removeInjectStreamUrl(options: RemoveInjectStreamOption): Promise<any> {
  853. return Agora.removeInjectStreamUrl(options);
  854. }
  855. /**
  856. * @deprecated
  857. * set video quality
  858. *
  859. * This method sets the preferences for the video quality. (Live broadcast only).
  860. *
  861. * @param quality boolean
  862. * @returns Promise<{success, value}>
  863. */
  864. // public static setVideoQualityParameters(quality: boolean): Promise<any> {
  865. // return Agora.setVideoQualityParameters(quality);
  866. // }
  867. /**
  868. * set local video mirror mode
  869. *
  870. * This method sets local video mirror mode
  871. *
  872. * @param mode
  873. * @returns Promise<{success, value}>
  874. */
  875. public static setLocalVideoMirrorMode(mode: number): Promise<any> {
  876. return Agora.setLocalVideoMirrorMode(mode);
  877. }
  878. /**
  879. * switch camera
  880. *
  881. * This method switches camera between front and rear.
  882. *
  883. * @returns Promise<{success, value}>
  884. */
  885. public static switchCamera(): Promise<any> {
  886. return Agora.switchCamera();
  887. }
  888. /**
  889. * is camera zoom supported
  890. *
  891. * This method checks whether the camera zoom function is supported.
  892. *
  893. * @returns Promise<{success, value}>
  894. */
  895. public static isCameraZoomSupported(): Promise<any> {
  896. return Agora.isCameraZoomSupported();
  897. }
  898. /**
  899. * is camera torch supported
  900. *
  901. * This method checks whether the camera flash function is supported.
  902. *
  903. * @returns Promise<{success, value}>
  904. */
  905. public static isCameraTorchSupported(): Promise<any> {
  906. return Agora.isCameraTorchSupported();
  907. }
  908. /**
  909. * is camera focus supported
  910. *
  911. * This method checks whether the camera mannual focus function is supported.
  912. *
  913. * @returns Promise<{success, value}>
  914. */
  915. public static isCameraFocusSupported(): Promise<any> {
  916. return Agora.isCameraFocusSupported();
  917. }
  918. /**
  919. * is camera exposure position supported
  920. *
  921. * This method checks whether the camera mannual exposure function is supported.
  922. *
  923. * @returns Promise<{success, value}>
  924. */
  925. public static isCameraExposurePositionSupported(): Promise<any> {
  926. return Agora.isCameraExposurePositionSupported();
  927. }
  928. /**
  929. * is camera auto focus face mode supported
  930. *
  931. * This method checks whether the camera mannual auto-face focus function is supported.
  932. *
  933. * @returns Promise<{success, value}>
  934. */
  935. public static isCameraAutoFocusFaceModeSupported(): Promise<any> {
  936. return Agora.isCameraAutoFocusFaceModeSupported();
  937. }
  938. /**
  939. * set camera zoom ratio
  940. *
  941. * This method sets the camera zoom ratio.
  942. *
  943. * @param zoomFactor
  944. * @returns Promise<{success, value}>
  945. */
  946. public static setCameraZoomFactor(zoomFactor: number): Promise<any> {
  947. return Agora.setCameraZoomFactor(zoomFactor);
  948. }
  949. /**
  950. * get camera max zoom ratio
  951. *
  952. * This method gets the camera maximum zoom ratio.
  953. *
  954. * @notice Android Only
  955. * @returns Promise<{success, value}>
  956. */
  957. public static getCameraMaxZoomFactor(): Promise<any> {
  958. return Agora.getCameraMaxZoomFactor();
  959. }
  960. /**
  961. * set camera focus position in preview
  962. *
  963. * This method sets the mannual focus position.
  964. *
  965. * @param options {@link PositionOption}
  966. * @returns Promise<{success, value}>
  967. */
  968. public static setCameraFocusPositionInPreview(options: PositionOption): Promise<any> {
  969. return Agora.setCameraFocusPositionInPreview(options);
  970. }
  971. /**
  972. * set camera exposure position
  973. *
  974. * This method sets the mannual exposure position.
  975. *
  976. * @param options {@link PositionOption}
  977. * @returns Promise<{success, value}>
  978. */
  979. public static setCameraExposurePosition(options: PositionOption): Promise<any> {
  980. return Agora.setCameraExposurePosition(options);
  981. }
  982. /**
  983. * set camera torch on
  984. *
  985. * This method enables the camera flash function.
  986. *
  987. * @param enabled
  988. * @returns Promise<{success, value}>
  989. */
  990. public static setCameraTorchOn(enabled: boolean): Promise<any> {
  991. return Agora.setCameraTorchOn(enabled);
  992. }
  993. /**
  994. * set enable auto focus face mode
  995. *
  996. * This method enables auto-focus face mode function.
  997. *
  998. * @param enabled boolean
  999. * @returns Promise<{success, value}>
  1000. */
  1001. public static setCameraAutoFocusFaceModeEnabled(enabled: boolean): Promise<any> {
  1002. return Agora.setCameraAutoFocusFaceModeEnabled(enabled);
  1003. }
  1004. /**
  1005. * get call id
  1006. *
  1007. * This method is used to get call id.
  1008. *
  1009. * @returns Promise<{success, value}>
  1010. */
  1011. public static getCallId(): Promise<any> {
  1012. return Agora.getCallId();
  1013. }
  1014. /**
  1015. * set log file and log filter
  1016. *
  1017. * This method sets the log file generated path and specified the log level.
  1018. *
  1019. * @param filepath string
  1020. * @param level enum
  1021. * @param maxfileSize integer (KB)
  1022. * @returns Promise<{success, value}>
  1023. */
  1024. public static setLog(filepath: string, level: number, maxfileSize: number): Promise<any> {
  1025. return Agora.setLog(filepath, level, maxfileSize)
  1026. }
  1027. /**
  1028. * send stream message
  1029. *
  1030. * This method sends stream message by specified uid
  1031. *
  1032. * @param uid
  1033. * @param data
  1034. * @returns Promise<{success, value}>
  1035. */
  1036. public static sendMessage(streamID: number, data: any, reliable: boolean, ordered: boolean): Promise<any> {
  1037. return Agora.sendMessage({streamID, data, reliable, ordered});
  1038. }
  1039. /**
  1040. * add publish stream url
  1041. *
  1042. * This method add publish stream by option.
  1043. *
  1044. * @param options {@link PublishStreamOption}
  1045. * @returns Promise<{success, value}>
  1046. */
  1047. public static addPublishStreamUrl(options: PublishStreamOption): Promise<any> {
  1048. return Agora.addPublishStreamUrl(options);
  1049. }
  1050. /**
  1051. * remove publish stream url
  1052. *
  1053. * This method remove publish stream by options.
  1054. *
  1055. * @param options {@link RemovePublishStreamOption}
  1056. * @returns Promise<{success, value}>
  1057. */
  1058. public static removePublishStreamUrl(options: RemovePublishStreamOption): Promise<any> {
  1059. return Agora.removePublishStreamUrl(options);
  1060. }
  1061. /**
  1062. * set live transcoding
  1063. *
  1064. * This method sets the video layout and audio settings for CDN live.
  1065. *
  1066. * @param options {@link LiveTranscoding}
  1067. * @returns Promise<{success, value}>
  1068. */
  1069. public static setLiveTranscoding(options: LiveTranscodingOption): Promise<any> {
  1070. return Agora.setLiveTranscoding(options);
  1071. }
  1072. /**
  1073. * get sdk version
  1074. *
  1075. * This method gets the sdk version details and passed it into callback function
  1076. *
  1077. * @param callback to handle resolve from getSdkVersion
  1078. * @param errorHandler to handle reject error from getSdkVersion
  1079. */
  1080. public static getSdkVersion(callback: Callback<any>, errorHandler?: Callback<any>) {
  1081. return Agora.getSdkVersion().then(callback).catch(errorHandler);
  1082. }
  1083. /**
  1084. * mute local audio stream
  1085. *
  1086. * This method sends/stops sending the local audio.
  1087. *
  1088. * @param enabled
  1089. */
  1090. public static muteLocalAudioStream(enabled: boolean) {
  1091. Agora.muteLocalAudioStream(enabled);
  1092. }
  1093. /**
  1094. * video pre-process/post-process
  1095. *
  1096. * This method enables/disables image enhancement and sets the options.
  1097. *
  1098. * @param enable boolean
  1099. * @param options {@link BeautyOptions}
  1100. * @returns Promise<{success, value}>
  1101. */
  1102. static setBeautyEffectOptions(enabled: boolean, options: BeautyOption): Promise<any> {
  1103. return Agora.setBeautyEffectOptions(enabled, options);
  1104. }
  1105. /**
  1106. * set local voice change
  1107. *
  1108. * This method changes local speaker voice with voiceChanger
  1109. *
  1110. * @param voiceChanger integer
  1111. * @voiceChanger value ranges [
  1112. * 0: "The original voice",
  1113. * 1: "An old man’s voice",
  1114. * 2: "A little boy’s voice.",
  1115. * 3: "A little girl’s voice.",
  1116. * 4: "TBD",
  1117. * 5: "Ethereal vocal effects.",
  1118. * 6: "Hulk’s voice."
  1119. * ]
  1120. * @returns Promise<{success, value}>
  1121. */
  1122. static setLocalVoiceChanger(voiceChanger: number): Promise<any> {
  1123. return Agora.setLocalVoiceChanger(voiceChanger);
  1124. }
  1125. /**
  1126. * set the preset local voice reverberation effect.
  1127. *
  1128. * This method sets the preset local voice reverberation effect.
  1129. *
  1130. * @param preset integer
  1131. * @returns Promise<{success, value}>
  1132. */
  1133. static setLocalVoiceReverbPreset(preset: number): Promise<any> {
  1134. return Agora.setLocalVoiceReverbPreset(preset);
  1135. }
  1136. /**
  1137. * control stereo panning for remote users
  1138. *
  1139. * This method enables/disables stereo panning for remote users.
  1140. *
  1141. * @param enabled boolean
  1142. * @returns Promise<{success, value}>
  1143. */
  1144. static enableSoundPositionIndication(enabled: boolean): Promise<any> {
  1145. return Agora.enableSoundPositionIndication(enabled);
  1146. }
  1147. /**
  1148. * set the sound position of a remote user
  1149. *
  1150. * This method sets the sound position of a remote user by uid
  1151. *
  1152. * @param uid number | The ID of the remote user
  1153. * @param pan float | The sound position of the remote user. The value ranges from -1.0 to 1.0
  1154. * @pan
  1155. * 0.0: the remote sound comes from the front.
  1156. * -1.0: the remote sound comes from the left.
  1157. * 1.0: the remote sound comes from the right.
  1158. * @param gain float | Gain of the remote user. The value ranges from 0.0 to 100.0. The default value is 100.0 (the original gain of the remote user). The smaller the value, the less the gain.
  1159. * @returns Promise<{success, value}>
  1160. */
  1161. static setRemoteVoicePosition(uid: number, pan: number, gain: number): Promise<any> {
  1162. return Agora.setRemoteVoicePosition(uid, pan, gain)
  1163. }
  1164. /**
  1165. * start the lastmile probe test
  1166. *
  1167. * This method start the last-mile network probe test before joining a channel to get the uplink and downlink last-mile network statistics, including the bandwidth, packet loss, jitter, and round-trip time (RTT).
  1168. *
  1169. * @param config LastmileProbeConfig {@link LastmileProbeConfig}
  1170. *
  1171. * @event onLastmileQuality: the SDK triggers this callback within two seconds depending on the network conditions. This callback rates the network conditions with a score and is more closely linked to the user experience.
  1172. * @event onLastmileProbeResult: the SDK triggers this callback within 30 seconds depending on the network conditions. This callback returns the real-time statistics of the network conditions and is more objective.
  1173. * @returns Promise<{success, value}>
  1174. */
  1175. static startLastmileProbeTest(config: LastmileProbeConfig): Promise<any> {
  1176. return Agora.startLastmileProbeTest(config);
  1177. }
  1178. /**
  1179. * stop the lastmile probe test
  1180. *
  1181. * This method stop the lastmile probe test.
  1182. *
  1183. * @returns Promise<{success, value}>
  1184. */
  1185. static stopLastmileProbeTest(): Promise<any> {
  1186. return Agora.stopLastmileProbeTest();
  1187. }
  1188. /**
  1189. * sets the priority of a remote user's media stream.
  1190. *
  1191. * note: Use this method with the setRemoteSubscribeFallbackOption method. If the fallback function is enabled for a subscribed stream, the SDK ensures the high-priority user gets the best possible stream quality.
  1192. *
  1193. * This method sets the priority of a remote user's media stream.
  1194. * @param uid number
  1195. * @param userPriority number | The value range is [50 is "user's priority is hgih", 100 is "the default user's priority is normal"]
  1196. *
  1197. * @returns Promise<{success, value}>
  1198. */
  1199. static setRemoteUserPriority(uid: number, userPrority: number): Promise<any> {
  1200. return Agora.setRemoteUserPriority(uid, userPrority);
  1201. }
  1202. /**
  1203. * start an audio call test.
  1204. *
  1205. * note:
  1206. * Call this method before joining a channel.
  1207. * After calling this method, call the stopEchoTest method to end the test. Otherwise, the app cannot run the next echo test, or call the joinchannel method.
  1208. * In the Live-broadcast profile, only a host can call this method.
  1209. * This method will start an audio call test with interval parameter.
  1210. * In the audio call test, you record your voice. If the recording plays back within the set time interval, the audio devices and the network connection are working properly.
  1211. *
  1212. * @param interval number
  1213. *
  1214. * @returns Promise<{success, value}>
  1215. */
  1216. static startEchoTestWithInterval(interval: number): Promise<any> {
  1217. return Agora.startEchoTestWithInterval(interval)
  1218. }
  1219. /**
  1220. * set the camera capture preference.
  1221. *
  1222. * note:
  1223. * For a video call or live broadcast, generally the SDK controls the camera output parameters. When the default camera capture settings do not meet special requirements or cause performance problems, we recommend using this method to set the camera capture preference:
  1224. * If the resolution or frame rate of the captured raw video data are higher than those set by setVideoEncoderConfiguration, processing video frames requires extra CPU and RAM usage and degrades performance. We recommend setting config as CAPTURER_OUTPUT_PREFERENCE_PERFORMANCE(1) to avoid such problems.
  1225. * If you do not need local video preview or are willing to sacrifice preview quality, we recommend setting config as CAPTURER_OUTPUT_PREFERENCE_PERFORMANCE(1) to optimize CPU and RAM usage.
  1226. * If you want better quality for the local video preview, we recommend setting config as CAPTURER_OUTPUT_PREFERENCE_PREVIEW(2).
  1227. *
  1228. * This method will set the camera capture preference.
  1229. *
  1230. * @param config {@link CameraCapturerConfiguration}
  1231. *
  1232. * @returns Promise<{success, value}>
  1233. */
  1234. static setCameraCapturerConfiguration(config: CameraCapturerConfiguration): Promise<any> {
  1235. return Agora.setCameraCapturerConfiguration(config);
  1236. }
  1237. }
  1238. export default RtcEngine;