Нет описания

RtcEngine.native.js 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const react_native_1 = require("react-native");
  4. const { Agora } = react_native_1.NativeModules;
  5. const AgoraEventEmitter = new react_native_1.NativeEventEmitter(Agora);
  6. /**
  7. * @class RtcEngine
  8. */
  9. class RtcEngine {
  10. /**
  11. * init AgoraRtcEngine
  12. * @param options: Option
  13. */
  14. static init(options) {
  15. this.removeEmitter();
  16. Agora.init(options);
  17. this.listeners = [];
  18. }
  19. /**
  20. * join channel
  21. * @param channelName String for channel name
  22. * @param uid Number user id is optional
  23. * @param token String secure token
  24. * @param info Object extra info
  25. * @return Promise
  26. */
  27. static joinChannel(channelName, uid, token, info) {
  28. return Agora.joinChannel({ channelName, uid, token, info });
  29. }
  30. /**
  31. * RtcEngine events register
  32. * @param eventScheduler EventScheduler
  33. */
  34. static eventEmitter(eventScheduler) {
  35. this.removeEmitter();
  36. // const events = EventSchedulerKeys;
  37. const events = [
  38. "onWarning",
  39. "onError",
  40. "onJoinChannelSuccess",
  41. "onRejoinChannelSuccess",
  42. "onLeaveChannel",
  43. "onClientRoleChanged",
  44. "onUserJoined",
  45. "onUserOffline",
  46. "onConnectionStateChanged",
  47. "onConnectionInterrupted",
  48. "onConnectionLost",
  49. "onConnectionBanned",
  50. "onApiCallExecuted",
  51. "onTokenPrivilegeWillExpire",
  52. "onRequestToken",
  53. "onMicrophoneEnabled",
  54. "onAudioVolumeIndication",
  55. "onActiveSpeaker",
  56. "onFirstLocalAudioFrame",
  57. "onFirstRemoteAudioFrame",
  58. "onVideoStopped",
  59. "onFirstLocalVideoFrame",
  60. "onFirstRemoteVideoDecoded",
  61. "onFirstRemoteVideoFrame",
  62. "onUserMuteAudio",
  63. "onUserMuteVideo",
  64. "onUserEnableVideo",
  65. "onUserEnableLocalVideo",
  66. "onVideoSizeChanged",
  67. "onRemoteVideoStateChanged",
  68. "onLocalPublishFallbackToAudioOnly",
  69. "onRemoteSubscribeFallbackToAudioOnly",
  70. "onAudioRouteChanged",
  71. "onCameraReady",
  72. "onCameraFocusAreaChanged",
  73. "onCameraExposureAreaChanged",
  74. "onAudioQuality",
  75. "onRtcStats",
  76. "onLastmileQuality",
  77. "onNetworkQuality",
  78. "onLocalVideoStats",
  79. "onRemoteVideoStats",
  80. "onRemoteAudioStats",
  81. "onLocalVideoStat",
  82. "onRemoteVideoStat",
  83. "onRemoteAudioTransportStats",
  84. "onRemoteVideoTransportStats",
  85. "onAudioMixingFinished",
  86. "onAudioEffectFinished",
  87. "onStreamPublished",
  88. "onStreamUnpublished",
  89. "onTranscodingUpdated",
  90. "onStreamInjectedStatus",
  91. "onStreamMessage",
  92. "onStreamMessageError",
  93. "onMediaEngineLoadSuccess",
  94. "onMediaEngineStartCallSuccess",
  95. ];
  96. for (let event of events) {
  97. const functor = eventScheduler[event];
  98. if (functor) {
  99. this.listeners.push(AgoraEventEmitter.addListener(event, msg => {
  100. functor(msg);
  101. }));
  102. }
  103. }
  104. }
  105. /**
  106. * remove emitter
  107. */
  108. static removeEmitter() {
  109. if (this.listeners && this.listeners.length > 0) {
  110. for (let listener of this.listeners) {
  111. listener.remove();
  112. this.listeners = [];
  113. }
  114. }
  115. }
  116. /**
  117. * enableLastmileTest
  118. * @return Promise
  119. */
  120. static enableLastmileTest() {
  121. return Agora.enableLastmileTest();
  122. }
  123. /**
  124. * disableLastmileTest
  125. * @return Promise
  126. */
  127. static disableLastmileTest() {
  128. return Agora.disableLastmileTest();
  129. }
  130. /**
  131. * leaveChannel
  132. * @return Promise
  133. */
  134. static leaveChannel() {
  135. return Agora.leaveChannel();
  136. }
  137. /**
  138. * destroy AgoraRtcEngine
  139. */
  140. static destroy() {
  141. Agora.destroy();
  142. }
  143. /**
  144. * setupLocalVideo
  145. * @param options: VideoOption
  146. */
  147. static setupLocalVideo(options) {
  148. Agora.setupLocalVideo(options);
  149. }
  150. /**
  151. * setupRemoteVideo
  152. * @param options: VideoOption
  153. */
  154. static setupRemoteVideo(options) {
  155. Agora.setupRemoteVideo(options);
  156. }
  157. /**
  158. * start AgoraRtcEngine preview
  159. */
  160. static startPreview() {
  161. Agora.startPreview();
  162. }
  163. /**
  164. * stop AgoraRtcEngine preview
  165. */
  166. static stopPreview() {
  167. Agora.stopPreview();
  168. }
  169. /**
  170. * start live trancoding
  171. * @param options LiveTranscoding
  172. */
  173. static setLiveTranscoding(options) {
  174. Agora.setLiveTranscoding(options);
  175. }
  176. /**
  177. * setLocalRenderMode
  178. * @param mode Number
  179. */
  180. static setLocalRenderMode(mode) {
  181. Agora.setLocalRenderMode(mode);
  182. }
  183. /**
  184. * setRemoteRenderMode
  185. * @param uid Number
  186. * @param mode Number
  187. */
  188. static setRemoteRenderMode(uid, mode) {
  189. Agora.setRemoteRenderMode(uid, mode);
  190. }
  191. /**
  192. * enableAudioVolumeIndication
  193. * @param interval Number
  194. * @param smooth Number
  195. */
  196. static enableAudioVolumeIndication(interval, smooth) {
  197. Agora.enableAudioVolumeIndication(interval, smooth);
  198. }
  199. /**
  200. * switch camera
  201. * @return Promise
  202. */
  203. static switchCamera() {
  204. return Agora.switchCamera();
  205. }
  206. static enableVideo() {
  207. Agora.enableVideo();
  208. }
  209. static disableVideo() {
  210. Agora.disableVideo();
  211. }
  212. /**
  213. * setEnableSpeakerphone
  214. * @param status Boolena
  215. */
  216. static setEnableSpeakerphone(status) {
  217. Agora.setEnableSpeakerphone(status);
  218. }
  219. /**
  220. * muteLocalAudioStream
  221. * @param status Boolena
  222. */
  223. static muteLocalAudioStream(status) {
  224. Agora.muteLocalAudioStream(status);
  225. }
  226. /**
  227. * muteRemoteAudioStream
  228. * @param uid Number
  229. * @param status Boolean
  230. */
  231. static muteRemoteAudioStream(uid, status) {
  232. Agora.muteRemoteAudioStream(uid, status);
  233. }
  234. /**
  235. * muteAllRemoteAudioStreams
  236. * @param status Boolean
  237. */
  238. static muteAllRemoteAudioStreams(status) {
  239. Agora.muteAllRemoteAudioStreams(status);
  240. }
  241. /**
  242. * setCameraTorchOn
  243. * @param status Boolean
  244. * @return Promise
  245. */
  246. static setCameraTorchOn(status) {
  247. return Agora.setCameraTorchOn(status);
  248. }
  249. /**
  250. * setCameraAutoFocusFaceModeEnabled
  251. * @param status Boolean
  252. * @return Promise
  253. */
  254. static setCameraAutoFocusFaceModeEnabled(status) {
  255. return Agora.setCameraAutoFocusFaceModeEnabled(status);
  256. }
  257. /**
  258. * setDefaultAudioRouteToSpeakerphone
  259. * @param status Boolean
  260. * @return Promise
  261. */
  262. static setDefaultAudioRouteToSpeakerphone(status) {
  263. Agora.setDefaultAudioRouteToSpeakerphone(status);
  264. }
  265. /**
  266. * muteLocalVideoStream
  267. * @param status Boolean
  268. */
  269. static muteLocalVideoStream(status) {
  270. Agora.muteLocalVideoStream(status);
  271. }
  272. /**
  273. * enableLocalVideo
  274. * @param status Boolean
  275. */
  276. static enableLocalVideo(status) {
  277. Agora.enableLocalVideo(status);
  278. }
  279. /**
  280. * muteAllRemoteVideoStreams
  281. * @param status Boolean
  282. */
  283. static muteAllRemoteVideoStreams(status) {
  284. Agora.muteAllRemoteVideoStreams(status);
  285. }
  286. /**
  287. * muteRemoteVideoStream
  288. * @param status Boolean
  289. */
  290. static muteRemoteVideoStream(uid, status) {
  291. Agora.muteRemoteVideoStream(uid, status);
  292. }
  293. /**
  294. * createDataStream
  295. * @param reliable Boolean
  296. * @param ordered Boolean
  297. * @return Promise
  298. */
  299. static createDataStream(reliable, ordered) {
  300. return Agora.createDataStream({ reliable, ordered });
  301. }
  302. /**
  303. * sendStreamMessage
  304. * @param reliable Boolean
  305. * @param ordered Boolean
  306. * @return Promise
  307. */
  308. static sendStreamMessage(streamId, data) {
  309. return Agora.sendStreamMessage(streamId, data);
  310. }
  311. /**
  312. * getSdkVersion
  313. * @param callback Function
  314. */
  315. static getSdkVersion(callback) {
  316. Agora.getSdkVersion().then(callback);
  317. }
  318. }
  319. exports.default = RtcEngine;
  320. ;
  321. //# sourceMappingURL=RtcEngine.native.js.map