@ion299/sdk-react-native 0.1.0-beta.5 → 0.1.0-beta.6

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 (40) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/android/src/main/java/com/chatplatform/sdk/ChatSdkAudioPlayerModule.kt +201 -0
  3. package/android/src/main/java/com/chatplatform/sdk/ChatSdkPackage.kt +1 -0
  4. package/ios/ChatSdkAudioPlayer.m +25 -0
  5. package/ios/ChatSdkAudioPlayer.swift +193 -0
  6. package/lib/commonjs/audio/audioController.js +145 -0
  7. package/lib/commonjs/audio/audioController.js.map +1 -0
  8. package/lib/commonjs/components/AudioMessage.js +198 -0
  9. package/lib/commonjs/components/AudioMessage.js.map +1 -0
  10. package/lib/commonjs/components/MessageBubble.js +9 -0
  11. package/lib/commonjs/components/MessageBubble.js.map +1 -1
  12. package/lib/commonjs/native/NativeChatSdkAudioPlayer.js +28 -0
  13. package/lib/commonjs/native/NativeChatSdkAudioPlayer.js.map +1 -0
  14. package/lib/module/audio/audioController.js +140 -0
  15. package/lib/module/audio/audioController.js.map +1 -0
  16. package/lib/module/components/AudioMessage.js +193 -0
  17. package/lib/module/components/AudioMessage.js.map +1 -0
  18. package/lib/module/components/MessageBubble.js +9 -0
  19. package/lib/module/components/MessageBubble.js.map +1 -1
  20. package/lib/module/native/NativeChatSdkAudioPlayer.js +23 -0
  21. package/lib/module/native/NativeChatSdkAudioPlayer.js.map +1 -0
  22. package/lib/typescript/commonjs/audio/audioController.d.ts +25 -0
  23. package/lib/typescript/commonjs/audio/audioController.d.ts.map +1 -0
  24. package/lib/typescript/commonjs/components/AudioMessage.d.ts +11 -0
  25. package/lib/typescript/commonjs/components/AudioMessage.d.ts.map +1 -0
  26. package/lib/typescript/commonjs/components/MessageBubble.d.ts.map +1 -1
  27. package/lib/typescript/commonjs/native/NativeChatSdkAudioPlayer.d.ts +20 -0
  28. package/lib/typescript/commonjs/native/NativeChatSdkAudioPlayer.d.ts.map +1 -0
  29. package/lib/typescript/module/audio/audioController.d.ts +25 -0
  30. package/lib/typescript/module/audio/audioController.d.ts.map +1 -0
  31. package/lib/typescript/module/components/AudioMessage.d.ts +11 -0
  32. package/lib/typescript/module/components/AudioMessage.d.ts.map +1 -0
  33. package/lib/typescript/module/components/MessageBubble.d.ts.map +1 -1
  34. package/lib/typescript/module/native/NativeChatSdkAudioPlayer.d.ts +20 -0
  35. package/lib/typescript/module/native/NativeChatSdkAudioPlayer.d.ts.map +1 -0
  36. package/package.json +1 -1
  37. package/src/audio/audioController.ts +144 -0
  38. package/src/components/AudioMessage.tsx +198 -0
  39. package/src/components/MessageBubble.tsx +6 -0
  40. package/src/native/NativeChatSdkAudioPlayer.ts +54 -0
@@ -0,0 +1,54 @@
1
+ import { NativeEventEmitter, NativeModules, TurboModuleRegistry } from 'react-native'
2
+ import type { EventSubscription, TurboModule } from 'react-native'
3
+
4
+ export type NativeAudioState =
5
+ | 'loading'
6
+ | 'playing'
7
+ | 'paused'
8
+ | 'ended'
9
+ | 'stopped'
10
+ | 'error'
11
+
12
+ export interface AudioStateEvent {
13
+ key: string
14
+ positionMillis: number
15
+ durationMillis: number
16
+ state: NativeAudioState
17
+ }
18
+
19
+ export interface Spec extends TurboModule {
20
+ play(key: string, url: string, headers: Record<string, string>): Promise<void>
21
+ pause(key: string): Promise<void>
22
+ seek(key: string, positionMillis: number): Promise<void>
23
+ stop(key: string): Promise<void>
24
+ addListener(eventName: string): void
25
+ removeListeners(count: number): void
26
+ }
27
+
28
+ const MODULE_NAME = 'ChatSdkAudioPlayer'
29
+
30
+ function loadModule(): Spec | null {
31
+ try {
32
+ return TurboModuleRegistry.get<Spec>(MODULE_NAME)
33
+ } catch {
34
+ return (NativeModules[MODULE_NAME] as Spec | undefined) ?? null
35
+ }
36
+ }
37
+
38
+ const moduleRef = loadModule()
39
+
40
+ export default moduleRef
41
+
42
+ let emitter: NativeEventEmitter | null = null
43
+
44
+ function getEmitter(): NativeEventEmitter | null {
45
+ if (!moduleRef) return null
46
+ if (!emitter) emitter = new NativeEventEmitter(moduleRef as unknown as never)
47
+ return emitter
48
+ }
49
+
50
+ export function onAudioState(
51
+ handler: (event: AudioStateEvent) => void,
52
+ ): EventSubscription | null {
53
+ return getEmitter()?.addListener('ChatSdkAudioState', handler) ?? null
54
+ }