@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.
- package/CHANGELOG.md +15 -0
- package/android/src/main/java/com/chatplatform/sdk/ChatSdkAudioPlayerModule.kt +201 -0
- package/android/src/main/java/com/chatplatform/sdk/ChatSdkPackage.kt +1 -0
- package/ios/ChatSdkAudioPlayer.m +25 -0
- package/ios/ChatSdkAudioPlayer.swift +193 -0
- package/lib/commonjs/audio/audioController.js +145 -0
- package/lib/commonjs/audio/audioController.js.map +1 -0
- package/lib/commonjs/components/AudioMessage.js +198 -0
- package/lib/commonjs/components/AudioMessage.js.map +1 -0
- package/lib/commonjs/components/MessageBubble.js +9 -0
- package/lib/commonjs/components/MessageBubble.js.map +1 -1
- package/lib/commonjs/native/NativeChatSdkAudioPlayer.js +28 -0
- package/lib/commonjs/native/NativeChatSdkAudioPlayer.js.map +1 -0
- package/lib/module/audio/audioController.js +140 -0
- package/lib/module/audio/audioController.js.map +1 -0
- package/lib/module/components/AudioMessage.js +193 -0
- package/lib/module/components/AudioMessage.js.map +1 -0
- package/lib/module/components/MessageBubble.js +9 -0
- package/lib/module/components/MessageBubble.js.map +1 -1
- package/lib/module/native/NativeChatSdkAudioPlayer.js +23 -0
- package/lib/module/native/NativeChatSdkAudioPlayer.js.map +1 -0
- package/lib/typescript/commonjs/audio/audioController.d.ts +25 -0
- package/lib/typescript/commonjs/audio/audioController.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/AudioMessage.d.ts +11 -0
- package/lib/typescript/commonjs/components/AudioMessage.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/MessageBubble.d.ts.map +1 -1
- package/lib/typescript/commonjs/native/NativeChatSdkAudioPlayer.d.ts +20 -0
- package/lib/typescript/commonjs/native/NativeChatSdkAudioPlayer.d.ts.map +1 -0
- package/lib/typescript/module/audio/audioController.d.ts +25 -0
- package/lib/typescript/module/audio/audioController.d.ts.map +1 -0
- package/lib/typescript/module/components/AudioMessage.d.ts +11 -0
- package/lib/typescript/module/components/AudioMessage.d.ts.map +1 -0
- package/lib/typescript/module/components/MessageBubble.d.ts.map +1 -1
- package/lib/typescript/module/native/NativeChatSdkAudioPlayer.d.ts +20 -0
- package/lib/typescript/module/native/NativeChatSdkAudioPlayer.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/audio/audioController.ts +144 -0
- package/src/components/AudioMessage.tsx +198 -0
- package/src/components/MessageBubble.tsx +6 -0
- 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
|
+
}
|