agora-appbuilder-core 4.0.0-beta.33 → 4.0.0-beta.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agora-appbuilder-core",
3
- "version": "4.0.0-beta.33",
3
+ "version": "4.0.0-beta.35",
4
4
  "description": "React Native template for RTE app builder",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -29,6 +29,10 @@ import type RtcEngine from '../../bridge/rtc/webNg/';
29
29
  import ColorContext from './ColorContext';
30
30
  import {SdkApiContext} from './SdkApiContext';
31
31
  import SDKEvents from '../utils/SdkEvents';
32
+ import {getOS} from '../utils/common';
33
+ import LocalEventEmitter, {
34
+ LocalEventsEnum,
35
+ } from '../rtm-events-api/LocalEvents';
32
36
 
33
37
  const log = (...args: any[]) => {
34
38
  console.log('[DeviceConfigure] ', ...args);
@@ -334,14 +338,16 @@ const DeviceConfigure: React.FC<Props> = (props: any) => {
334
338
 
335
339
  useEffect(() => {
336
340
  // Notify updated state every 20s
337
- let count = 0;
338
- const interval = setInterval(() => {
339
- count = count + 1;
340
- refreshDeviceList(count % 10 !== 0);
341
- }, 2000);
342
- return () => {
343
- clearInterval(interval);
344
- };
341
+ if (getOS() !== 'macos') {
342
+ let count = 0;
343
+ const interval = setInterval(() => {
344
+ count = count + 1;
345
+ refreshDeviceList(count % 10 !== 0);
346
+ }, 2000);
347
+ return () => {
348
+ clearInterval(interval);
349
+ };
350
+ }
345
351
  }, []);
346
352
 
347
353
  useEffect(() => {
@@ -565,7 +571,10 @@ const DeviceConfigure: React.FC<Props> = (props: any) => {
565
571
  // Port this to useEffectEvent(https://beta.reactjs.org/reference/react/useEffectEvent) when
566
572
  // released
567
573
  useEffect(() => {
568
- AgoraRTC.onMicrophoneChanged = commonOnChangedEvent;
574
+ AgoraRTC.onMicrophoneChanged = data => {
575
+ LocalEventEmitter.emit(LocalEventsEnum.MIC_CHANGED);
576
+ commonOnChangedEvent(data);
577
+ };
569
578
  return () => {
570
579
  AgoraRTC.onMicrophoneChanged = null;
571
580
  };
@@ -3,6 +3,7 @@ export enum LocalEventsEnum {
3
3
  ACTIVE_SPEAKER = 'ACTIVE_SPEAKER',
4
4
  WHITEBOARD_ON = 'WHITEBOARD_ON',
5
5
  WHITEBOARD_OFF = 'WHITEBOARD_OFF',
6
+ MIC_CHANGED = 'MIC_CHANGED',
6
7
  }
7
8
  const LocalEventEmitter = new EventEmitter();
8
9
  export default LocalEventEmitter;
@@ -25,7 +25,7 @@ const LayoutIconButton = (props: LayoutIconButtonInterface) => {
25
25
  const [isHoveredOnModal, setIsHoveredOnModal] = useState(false);
26
26
  const isMobileView = isMobileUA();
27
27
  const {isOnActionSheet} = useActionSheet();
28
- const showLabel = $config.ICON_TEXT || isOnActionSheet ? true : false;
28
+ const showLabel = $config.ICON_TEXT ? true : false;
29
29
  const setIsHovered = (hovered: boolean) => {
30
30
  if (layoutBtnRef && layoutBtnRef.current) {
31
31
  layoutBtnRef?.current?.measure((_fx, _fy, _w, h, _px, _py) => {
@@ -46,7 +46,7 @@ const LayoutIconButton = (props: LayoutIconButtonInterface) => {
46
46
  const changeLayout = useChangeDefaultLayout();
47
47
  const {currentLayout, setLayout} = useLayout();
48
48
 
49
- const layout = layouts.findIndex((item) => item.name === currentLayout);
49
+ const layout = layouts.findIndex(item => item.name === currentLayout);
50
50
  const renderLayoutIcon = (showDropdown?: boolean) => {
51
51
  let onPress = () => {};
52
52
  let renderContent = [];
@@ -116,7 +116,7 @@ const LayoutIconButton = (props: LayoutIconButtonInterface) => {
116
116
  containerStyle={{
117
117
  opacity: !activeUids || activeUids.length === 0 ? 0.6 : 1,
118
118
  }}
119
- setRef={(ref) => {
119
+ setRef={ref => {
120
120
  layoutBtnRef.current = ref;
121
121
  }}
122
122
  key={'defaultLayoutIconWithName'}
@@ -260,6 +260,28 @@ const CustomToolbarSort = (a, b) =>
260
260
  (a.hasOwnProperty('order') ? a.order : 999999) -
261
261
  (b.hasOwnProperty('order') ? b.order : 999999);
262
262
 
263
+ function getOS() {
264
+ let userAgent = window.navigator.userAgent.toLowerCase(),
265
+ macosPlatforms = /(macintosh|macintel|macppc|mac68k|macos)/i,
266
+ windowsPlatforms = /(win32|win64|windows|wince)/i,
267
+ iosPlatforms = /(iphone|ipad|ipod)/i,
268
+ os = null;
269
+
270
+ if (macosPlatforms.test(userAgent)) {
271
+ os = 'macos';
272
+ } else if (iosPlatforms.test(userAgent)) {
273
+ os = 'ios';
274
+ } else if (windowsPlatforms.test(userAgent)) {
275
+ os = 'windows';
276
+ } else if (/android/.test(userAgent)) {
277
+ os = 'android';
278
+ } else if (!os && /linux/.test(userAgent)) {
279
+ os = 'linux';
280
+ }
281
+
282
+ return os;
283
+ }
284
+
263
285
  export {
264
286
  useIsDesktop,
265
287
  useIsSmall,
@@ -284,4 +306,5 @@ export {
284
306
  debounceFn,
285
307
  capitalizeFirstLetter,
286
308
  CustomToolbarSort,
309
+ getOS,
287
310
  };
@@ -1,6 +1,10 @@
1
1
  import {useLocalUserInfo} from 'customization-api';
2
2
  import hark from 'hark';
3
3
  import {useEffect, useRef, useState} from 'react';
4
+ import {useAsyncEffect} from './useAsyncEffect';
5
+ import LocalEventEmitter, {
6
+ LocalEventsEnum,
7
+ } from '../rtm-events-api/LocalEvents';
4
8
 
5
9
  const useIsLocalUserSpeaking = () => {
6
10
  const log: (arg1: string, ...args: any[]) => void = (arg1, ...args) => {
@@ -34,48 +38,48 @@ const useIsLocalUserSpeaking = () => {
34
38
  }
35
39
  };
36
40
 
37
- const listenForSpeaker = () => {
41
+ useEffect(() => {
42
+ LocalEventEmitter.on(LocalEventsEnum.MIC_CHANGED, () => {
43
+ listenForSpeaker();
44
+ });
45
+ }, []);
46
+
47
+ const listenForSpeaker = async () => {
38
48
  try {
39
49
  if (speechRef.current) {
40
50
  speechRef.current?.stop && speechRef.current?.stop();
41
51
  }
52
+ if (audioTrackRef?.current) {
53
+ audioTrackRef.current?.length && audioTrackRef.current[0].stop();
54
+ }
42
55
  } catch (error) {
43
56
  log(' Error on stopping the hark', error);
44
57
  }
45
-
46
58
  try {
47
59
  //detect local user speaking or not
48
- navigator.mediaDevices
49
- .getUserMedia({
50
- audio: true,
51
- })
52
- .then(audioStream => {
53
- audioTrackRef.current = audioStream.getAudioTracks();
54
- speechRef.current = null;
55
- speechRef.current = hark(audioStream, {
56
- interval: 100,
57
- });
58
- speechRef.current.on('speaking', speakingCallBack);
59
- speechRef.current.on('stopped_speaking', stoppedSpeakingCallBack);
60
- });
60
+ const audioStream = await navigator.mediaDevices.getUserMedia({
61
+ audio: true,
62
+ });
63
+ audioTrackRef.current = audioStream.getAudioTracks();
64
+ speechRef.current = null;
65
+ speechRef.current = hark(audioStream, {
66
+ interval: 100,
67
+ });
68
+ speechRef.current.on('speaking', speakingCallBack);
69
+ speechRef.current.on('stopped_speaking', stoppedSpeakingCallBack);
61
70
  } catch (error) {
62
71
  log(' Error on starting the hark', error);
63
72
  }
64
73
  };
65
74
 
66
- useEffect(() => {
75
+ useAsyncEffect(async () => {
67
76
  if ($config.ACTIVE_SPEAKER) {
68
- navigator.mediaDevices.ondevicechange = () => {
69
- log(' ondevicechange called');
70
- listenForSpeaker();
71
- };
72
- listenForSpeaker();
77
+ await listenForSpeaker();
73
78
  return () => {
74
79
  speechRef.current && speechRef.current.stop();
75
80
  audioTrackRef.current &&
76
81
  audioTrackRef.current?.length &&
77
82
  audioTrackRef.current[0].stop();
78
- navigator.mediaDevices.ondevicechange = () => {};
79
83
  };
80
84
  }
81
85
  }, []);