@100mslive/react-native-hms 0.8.4 → 0.9.0

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.
Files changed (82) hide show
  1. package/README.md +6 -6
  2. package/android/build.gradle +3 -1
  3. package/android/src/main/java/com/reactnativehmssdk/HmsDecoder.kt +27 -2
  4. package/android/src/main/java/com/reactnativehmssdk/HmsHelper.kt +25 -0
  5. package/android/src/main/java/com/reactnativehmssdk/HmsModule.kt +81 -4
  6. package/android/src/main/java/com/reactnativehmssdk/HmsSDK.kt +174 -84
  7. package/android/src/main/java/com/reactnativehmssdk/HmsScreenshareActivity.kt +66 -0
  8. package/android/src/main/java/com/reactnativehmssdk/HmsView.kt +28 -3
  9. package/android/src/main/java/com/reactnativehmssdk/HmssdkViewManager.kt +10 -1
  10. package/android/src/main/res/layout/hms_view.xml +19 -0
  11. package/ios/HmsDecoder.swift +58 -2
  12. package/ios/HmsHelper.swift +21 -0
  13. package/ios/HmsManager.m +4 -2
  14. package/ios/HmsManager.swift +16 -2
  15. package/ios/HmsSDK.swift +63 -11
  16. package/ios/HmsView.swift +22 -54
  17. package/lib/commonjs/classes/HMSEncoder.js +2 -1
  18. package/lib/commonjs/classes/HMSEncoder.js.map +1 -1
  19. package/lib/commonjs/classes/HMSHLSConfig.js +20 -0
  20. package/lib/commonjs/classes/HMSHLSConfig.js.map +1 -0
  21. package/lib/commonjs/classes/HMSHLSMeetingURLVariant.js +23 -0
  22. package/lib/commonjs/classes/HMSHLSMeetingURLVariant.js.map +1 -0
  23. package/lib/commonjs/classes/HMSHLSStreamingState.js +23 -0
  24. package/lib/commonjs/classes/HMSHLSStreamingState.js.map +1 -0
  25. package/lib/commonjs/classes/HMSHLSVariant.js +29 -0
  26. package/lib/commonjs/classes/HMSHLSVariant.js.map +1 -0
  27. package/lib/commonjs/classes/HMSLogger.js +27 -0
  28. package/lib/commonjs/classes/HMSLogger.js.map +1 -1
  29. package/lib/commonjs/classes/HMSRoom.js +3 -0
  30. package/lib/commonjs/classes/HMSRoom.js.map +1 -1
  31. package/lib/commonjs/classes/HMSRoomUpdate.js +6 -0
  32. package/lib/commonjs/classes/HMSRoomUpdate.js.map +1 -1
  33. package/lib/commonjs/classes/HMSSDK.js +203 -96
  34. package/lib/commonjs/classes/HMSSDK.js.map +1 -1
  35. package/lib/commonjs/classes/HmsView.js +26 -4
  36. package/lib/commonjs/classes/HmsView.js.map +1 -1
  37. package/lib/commonjs/index.js +56 -0
  38. package/lib/commonjs/index.js.map +1 -1
  39. package/lib/module/classes/HMSEncoder.js +2 -1
  40. package/lib/module/classes/HMSEncoder.js.map +1 -1
  41. package/lib/module/classes/HMSHLSConfig.js +11 -0
  42. package/lib/module/classes/HMSHLSConfig.js.map +1 -0
  43. package/lib/module/classes/HMSHLSMeetingURLVariant.js +14 -0
  44. package/lib/module/classes/HMSHLSMeetingURLVariant.js.map +1 -0
  45. package/lib/module/classes/HMSHLSStreamingState.js +14 -0
  46. package/lib/module/classes/HMSHLSStreamingState.js.map +1 -0
  47. package/lib/module/classes/HMSHLSVariant.js +20 -0
  48. package/lib/module/classes/HMSHLSVariant.js.map +1 -0
  49. package/lib/module/classes/HMSLogger.js +27 -0
  50. package/lib/module/classes/HMSLogger.js.map +1 -1
  51. package/lib/module/classes/HMSRoom.js +3 -0
  52. package/lib/module/classes/HMSRoom.js.map +1 -1
  53. package/lib/module/classes/HMSRoomUpdate.js +6 -0
  54. package/lib/module/classes/HMSRoomUpdate.js.map +1 -1
  55. package/lib/module/classes/HMSSDK.js +204 -97
  56. package/lib/module/classes/HMSSDK.js.map +1 -1
  57. package/lib/module/classes/HmsView.js +23 -4
  58. package/lib/module/classes/HmsView.js.map +1 -1
  59. package/lib/module/index.js +4 -0
  60. package/lib/module/index.js.map +1 -1
  61. package/lib/typescript/classes/HMSHLSConfig.d.ts +7 -0
  62. package/lib/typescript/classes/HMSHLSMeetingURLVariant.d.ts +8 -0
  63. package/lib/typescript/classes/HMSHLSStreamingState.d.ts +9 -0
  64. package/lib/typescript/classes/HMSHLSVariant.d.ts +12 -0
  65. package/lib/typescript/classes/HMSLogger.d.ts +2 -0
  66. package/lib/typescript/classes/HMSRoom.d.ts +3 -0
  67. package/lib/typescript/classes/HMSRoomUpdate.d.ts +7 -1
  68. package/lib/typescript/classes/HMSSDK.d.ts +16 -7
  69. package/lib/typescript/index.d.ts +4 -0
  70. package/package.json +1 -2
  71. package/react-native-hms.podspec +1 -1
  72. package/src/classes/HMSEncoder.ts +1 -0
  73. package/src/classes/HMSHLSConfig.ts +9 -0
  74. package/src/classes/HMSHLSMeetingURLVariant.ts +9 -0
  75. package/src/classes/HMSHLSStreamingState.ts +11 -0
  76. package/src/classes/HMSHLSVariant.ts +18 -0
  77. package/src/classes/HMSLogger.ts +14 -0
  78. package/src/classes/HMSRoom.ts +4 -0
  79. package/src/classes/HMSRoomUpdate.ts +6 -0
  80. package/src/classes/HMSSDK.tsx +95 -19
  81. package/src/classes/HmsView.tsx +32 -4
  82. package/src/index.ts +4 -0
@@ -10,6 +10,7 @@ export class HMSLogger {
10
10
  data: any;
11
11
  id: string;
12
12
  }[] = [];
13
+ private onLog?: Function;
13
14
 
14
15
  constructor(params?: { verbose: boolean; warning: boolean; error: boolean }) {
15
16
  if (params) {
@@ -22,6 +23,9 @@ export class HMSLogger {
22
23
  verbose(message: string, data: any) {
23
24
  if (this._verbose) {
24
25
  console.log(message, data);
26
+ if (this.onLog) {
27
+ this?.onLog({ message, data });
28
+ }
25
29
  }
26
30
  this.logs.push({ type: 'verbose', message, data, id: data?.id });
27
31
  }
@@ -29,6 +33,9 @@ export class HMSLogger {
29
33
  warn(message: string, data: any) {
30
34
  if (this._warning) {
31
35
  console.warn(message, data);
36
+ if (this.onLog) {
37
+ this?.onLog({ message, data });
38
+ }
32
39
  }
33
40
  this.logs.push({ type: 'warn', message, data, id: data?.id });
34
41
  }
@@ -36,6 +43,9 @@ export class HMSLogger {
36
43
  error(message: string, data: any) {
37
44
  if (this._error) {
38
45
  console.error(message, data);
46
+ if (this.onLog) {
47
+ this?.onLog({ message, data });
48
+ }
39
49
  }
40
50
  this.logs.push({ type: 'error', message, data, id: data?.id });
41
51
  }
@@ -44,6 +54,10 @@ export class HMSLogger {
44
54
  return this.logs;
45
55
  }
46
56
 
57
+ setLogListener(callback: Function) {
58
+ this.onLog = callback;
59
+ }
60
+
47
61
  updateLogLevel(level: HMSLogLevel, value: boolean) {
48
62
  switch (level) {
49
63
  case HMSLogLevel.VERBOSE: {
@@ -2,6 +2,7 @@ import type { HMSPeer } from './HMSPeer';
2
2
  import type { HMSRtmpStreamingState } from './HMSRtmpStreamingState';
3
3
  import type { HMSServerRecordingState } from './HMSServerRecordingState';
4
4
  import type { HMSBrowserRecordingState } from './HMSBrowserRecordingState';
5
+ import type { HMSHLSStreamingState } from './HMSHLSStreamingState';
5
6
 
6
7
  export class HMSRoom {
7
8
  id: string;
@@ -11,6 +12,7 @@ export class HMSRoom {
11
12
  browserRecordingState: HMSBrowserRecordingState;
12
13
  rtmpHMSRtmpStreamingState: HMSRtmpStreamingState;
13
14
  serverRecordingState: HMSServerRecordingState;
15
+ hlsStreamingState: HMSHLSStreamingState;
14
16
 
15
17
  constructor(params: {
16
18
  id: string;
@@ -20,6 +22,7 @@ export class HMSRoom {
20
22
  browserRecordingState: HMSBrowserRecordingState;
21
23
  rtmpHMSRtmpStreamingState: HMSRtmpStreamingState;
22
24
  serverRecordingState: HMSServerRecordingState;
25
+ hlsStreamingState: HMSHLSStreamingState;
23
26
  }) {
24
27
  this.id = params.id;
25
28
  this.name = params.name;
@@ -28,5 +31,6 @@ export class HMSRoom {
28
31
  this.browserRecordingState = params.browserRecordingState;
29
32
  this.rtmpHMSRtmpStreamingState = params.rtmpHMSRtmpStreamingState;
30
33
  this.serverRecordingState = params.serverRecordingState;
34
+ this.hlsStreamingState = params.hlsStreamingState;
31
35
  }
32
36
  }
@@ -1,4 +1,10 @@
1
1
  export enum HMSRoomUpdate {
2
2
  ROOM_MUTED = 'ROOM_MUTED',
3
3
  ROOM_UNMUTED = 'ROOM_UNMUTED',
4
+ ROOM_TYPE_CHANGED = 'ROOM_TYPE_CHANGED',
5
+ META_DATA_CHANGED = 'META_DATA_CHANGED',
6
+ SERVER_RECORDING_STATE_UPDATED = 'SERVER_RECORDING_STATE_UPDATED',
7
+ RTMP_STREAMING_STATE_UPDATED = 'RTMP_STREAMING_STATE_UPDATED',
8
+ BROWSER_RECORDING_STATE_UPDATED = 'BROWSER_RECORDING_STATE_UPDATED',
9
+ HLS_STREAMING_STATE_UPDATED = 'HLS_STREAMING_STATE_UPDATED',
4
10
  }
@@ -1,5 +1,11 @@
1
1
  import React from 'react';
2
- import { NativeEventEmitter, NativeModules, ViewStyle } from 'react-native';
2
+ import {
3
+ NativeEventEmitter,
4
+ NativeModules,
5
+ Platform,
6
+ ViewStyle,
7
+ AppState,
8
+ } from 'react-native';
3
9
  import { HMSUpdateListenerActions } from './HMSUpdateListenerActions';
4
10
  import type { HMSConfig } from './HMSConfig';
5
11
  import type { HMSLocalPeer } from './HMSLocalPeer';
@@ -17,6 +23,7 @@ import { HmsView as HMSViewComponent } from './HmsView';
17
23
  import { HMSVideoViewMode } from './HMSVideoViewMode';
18
24
  import type { HMSTrackSettings } from './HMSTrackSettings';
19
25
  import type { HMSRTMPConfig } from './HMSRTMPConfig';
26
+ import type { HMSHLSConfig } from './HMSHLSConfig';
20
27
 
21
28
  interface HmsComponentProps {
22
29
  trackId: string;
@@ -47,6 +54,7 @@ export class HMSSDK {
47
54
  knownRoles?: HMSRole[];
48
55
  id: string;
49
56
  private muteStatus: boolean | undefined;
57
+ appStateSubscription?: any;
50
58
 
51
59
  onPreviewDelegate?: any;
52
60
  onJoinDelegate?: any;
@@ -74,7 +82,7 @@ export class HMSSDK {
74
82
  * @returns
75
83
  * @memberof HMSSDK
76
84
  */
77
- static async build(params?: { trackSettings?: HMSTrackSettings }) {
85
+ static async build(params?: { trackSettings: HMSTrackSettings }) {
78
86
  let id = await HmsManager.build(params?.trackSettings || {});
79
87
  HmsSdk = new HMSSDK(id);
80
88
  HmsSdk.attachPreviewListener();
@@ -235,6 +243,7 @@ export class HMSSDK {
235
243
  */
236
244
  join = async (config: HMSConfig) => {
237
245
  logger?.verbose('#Function join', { config, id: this.id });
246
+ this.addAppStateListener();
238
247
  await HmsManager.join({ ...config, id: this.id });
239
248
  };
240
249
 
@@ -279,10 +288,11 @@ export class HMSSDK {
279
288
  this.remotePeers = undefined;
280
289
  this.room = undefined;
281
290
  this.knownRoles = undefined;
291
+ this?.appStateSubscription?.remove();
282
292
  return op;
283
293
  };
284
294
 
285
- sendBroadcastMessage = async (message: string, type?: string) => {
295
+ sendBroadcastMessage = async (message: string, type: string = 'chat') => {
286
296
  logger?.verbose('#Function sendBroadcastMessage', {
287
297
  message,
288
298
  type: type || null,
@@ -298,7 +308,7 @@ export class HMSSDK {
298
308
  sendGroupMessage = async (
299
309
  message: string,
300
310
  roles: HMSRole[],
301
- type?: string
311
+ type: string = 'chat'
302
312
  ) => {
303
313
  logger?.verbose('#Function sendGroupMessage', {
304
314
  message,
@@ -316,18 +326,18 @@ export class HMSSDK {
316
326
 
317
327
  sendDirectMessage = async (
318
328
  message: string,
319
- peerId: string,
320
- type?: string
329
+ peer: HMSPeer,
330
+ type: string = 'chat'
321
331
  ) => {
322
332
  logger?.verbose('#Function sendDirectMessage', {
323
333
  message,
324
- peerId,
334
+ peerId: peer.peerID,
325
335
  id: this.id,
326
336
  type: type || null,
327
337
  });
328
338
  return await HmsManager.sendDirectMessage({
329
339
  message,
330
- peerId,
340
+ peerId: peer.peerID,
331
341
  id: this.id,
332
342
  type: type || null,
333
343
  });
@@ -354,6 +364,19 @@ export class HMSSDK {
354
364
  return op;
355
365
  };
356
366
 
367
+ startHLSStreaming = async (data: HMSHLSConfig) => {
368
+ logger?.verbose('#Function startHLSStreaming', {
369
+ ...data,
370
+ id: this.id,
371
+ });
372
+ return await HmsManager.startHLSStreaming({ ...data, id: this.id });
373
+ };
374
+
375
+ stopHLSStreaming = async () => {
376
+ logger?.verbose('#Function stopHLSStreaming', {});
377
+ return await HmsManager.stopHLSStreaming({ id: this.id });
378
+ };
379
+
357
380
  changeRole = async (peer: HMSPeer, role: HMSRole, force: boolean = false) => {
358
381
  const data = {
359
382
  peerId: peer?.peerID,
@@ -380,12 +403,16 @@ export class HMSSDK {
380
403
  return await HmsManager.changeTrackState(data);
381
404
  };
382
405
 
383
- changeTrackStateRoles = async (
384
- type: HMSTrackType,
406
+ changeTrackStateForRoles = async (
385
407
  mute: boolean,
386
- source: string,
387
- roles: Array<HMSRole>
408
+ type?: HMSTrackType,
409
+ source?: string,
410
+ roles?: Array<HMSRole>
388
411
  ) => {
412
+ let roleNames = null;
413
+ if (roles) {
414
+ roleNames = HMSHelper.getRoleNames(roles);
415
+ }
389
416
  logger?.verbose('#Function changeTrackStateRoles', {
390
417
  source,
391
418
  mute,
@@ -397,17 +424,21 @@ export class HMSSDK {
397
424
  source,
398
425
  mute,
399
426
  type,
400
- roles: HMSHelper.getRoleNames(roles),
427
+ roles: roleNames,
401
428
  id: this.id,
402
429
  };
403
430
 
404
- return await HmsManager.changeTrackStateRoles(data);
431
+ return await HmsManager.changeTrackStateForRoles(data);
405
432
  };
406
433
 
407
- removePeer = async (peerId: string, reason: string) => {
408
- logger?.verbose('#Function removePeer', { peerId, reason, id: this.id });
434
+ removePeer = async (peer: HMSPeer, reason: string) => {
435
+ logger?.verbose('#Function removePeer', {
436
+ peerId: peer.peerID,
437
+ reason,
438
+ id: this.id,
439
+ });
409
440
  const data = {
410
- peerId,
441
+ peerId: peer.peerID,
411
442
  reason,
412
443
  id: this.id,
413
444
  };
@@ -415,7 +446,7 @@ export class HMSSDK {
415
446
  return await HmsManager.removePeer(data);
416
447
  };
417
448
 
418
- endRoom = async (lock: boolean, reason: string) => {
449
+ endRoom = async (reason: string, lock: boolean = false) => {
419
450
  logger?.verbose('#Function endRoom', { lock, reason, id: this.id });
420
451
  const data = {
421
452
  lock,
@@ -459,7 +490,52 @@ export class HMSSDK {
459
490
  trackId: track.trackId,
460
491
  volume,
461
492
  });
462
- return;
493
+ };
494
+
495
+ resetVolume = () => {
496
+ logger?.verbose('#Function resetVolume', { id: this.id });
497
+ if (Platform.OS === 'android') HmsManager.resetVolume({ id: this.id });
498
+ };
499
+
500
+ addAppStateListener = () => {
501
+ logger?.verbose('#Function addAppStateListener', { id: this.id });
502
+ this.appStateSubscription = AppState.addEventListener(
503
+ 'change',
504
+ (nextAppState) => {
505
+ if (nextAppState === 'active' && Platform.OS === 'android') {
506
+ this.resetVolume();
507
+ }
508
+ }
509
+ );
510
+ };
511
+
512
+ startScreenshare = () => {
513
+ logger?.verbose('#Function startScreenshare', { id: this.id });
514
+ if (Platform.OS === 'android') {
515
+ HmsManager.startScreenshare({ id: this.id });
516
+ } else {
517
+ console.log('API currently not avaialble for iOS');
518
+ }
519
+ };
520
+
521
+ isScreenShared = async () => {
522
+ logger?.verbose('#Function isScreenShared', { id: this.id });
523
+ if (Platform.OS === 'android') {
524
+ return await HmsManager.isScreenShared({ id: this.id });
525
+ } else {
526
+ console.log('API currently not avaialble for iOS');
527
+ return 'API currently not avaialble for iOS';
528
+ }
529
+ };
530
+
531
+ stopScreenshare = async () => {
532
+ logger?.verbose('#Function stopScreenshare', { id: this.id });
533
+ if (Platform.OS === 'android') {
534
+ return await HmsManager.stopScreenshare({ id: this.id });
535
+ } else {
536
+ console.log('API currently not avaialble for iOS');
537
+ return 'API currently not avaialble for iOS';
538
+ }
463
539
  };
464
540
 
465
541
  /**
@@ -1,6 +1,7 @@
1
- import React from 'react';
2
- import { requireNativeComponent, ViewStyle } from 'react-native';
1
+ import React, { useState, useEffect } from 'react';
2
+ import { requireNativeComponent, StyleSheet, ViewStyle } from 'react-native';
3
3
  import { HMSVideoViewMode } from '../classes/HMSVideoViewMode';
4
+
4
5
  interface HmsViewProps {
5
6
  data: {
6
7
  trackId: string;
@@ -10,6 +11,7 @@ interface HmsViewProps {
10
11
  };
11
12
  scaleType: HMSVideoViewMode;
12
13
  style: ViewStyle;
14
+ onChange: Function;
13
15
  }
14
16
 
15
17
  const HmsViewComponent = requireNativeComponent<HmsViewProps>('HmsView');
@@ -29,8 +31,9 @@ export const HmsView = ({
29
31
  style,
30
32
  id,
31
33
  mirror,
32
- scaleType = HMSVideoViewMode.ASPECT_FIT,
34
+ scaleType = HMSVideoViewMode.ASPECT_FILL,
33
35
  }: HmsComponentProps) => {
36
+ const [tempVal, setTempVal] = useState(0);
34
37
  const data = {
35
38
  trackId,
36
39
  sink,
@@ -38,5 +41,30 @@ export const HmsView = ({
38
41
  mirror: mirror || false,
39
42
  };
40
43
 
41
- return <HmsViewComponent data={data} style={style} scaleType={scaleType} />;
44
+ const onChange = (values: any) => {
45
+ console.log(values, 'values');
46
+ setTimeout(() => {
47
+ setTempVal(1);
48
+ }, 2000);
49
+ };
50
+
51
+ useEffect(() => {
52
+ setTempVal(0);
53
+ }, [tempVal]);
54
+
55
+ return (
56
+ <HmsViewComponent
57
+ onChange={onChange}
58
+ data={data}
59
+ style={tempVal === 0 ? style : temporaryStyles.customStyle}
60
+ scaleType={scaleType}
61
+ />
62
+ );
42
63
  };
64
+
65
+ const temporaryStyles = StyleSheet.create({
66
+ customStyle: {
67
+ width: '100%',
68
+ height: '50%',
69
+ },
70
+ });
package/src/index.ts CHANGED
@@ -46,6 +46,10 @@ export * from './classes/HMSRtmpStreamingState';
46
46
  export * from './classes/HMSServerRecordingState';
47
47
  export * from './classes/HMSBrowserRecordingState';
48
48
  export * from './classes/HMSRTMPConfig';
49
+ export * from './classes/HMSHLSConfig';
50
+ export * from './classes/HMSHLSMeetingURLVariant';
51
+ export * from './classes/HMSHLSVariant';
52
+ export * from './classes/HMSHLSStreamingState';
49
53
  export * from './classes/HMSVideoResolution';
50
54
 
51
55
  import { HMSSDK as HmsManager } from './classes/HMSSDK';