createSoundMessageByFile
Feature Introduction
Description
Create audio message.
Note
Supported only on the web platform.
- Browser/Electron/MiniProgram
Function Prototype
IMSDK.createSoundMessageByFile({
uuid: string;
soundPath: string;
sourceUrl: string;
dataSize: number;
duration: number;
soundType: string;
file: File;
}, operationID?: string): Promise<WsResponse<MessageItem>>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
soundPath | string | Yes | Absolute file path, pass an empty string if not available. |
duration | number | Yes | Recording duration. |
uuid | string | Yes | Unique file ID. |
sourceUrl | string | Yes | Recording download URL. When manually uploading the file and sending it via sendMessageNotOss, you need to provide the remote url, otherwise, use an empty string. |
dataSize | string | Yes | File size. |
soundType | string | Yes | File type, usually the file extension. |
file | File | Yes | File object. |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<WsResponse<MessageItem>> | Success callback |
Promise.catch() | Promise<WsResponse> | Failure callback |
Code Example
import { getSDK } from '@openim/wasm-client-sdk';
const IMSDK = getSDK();
// use in electron with ffi
// import { getWithRenderProcess } from '@openim/electron-client-sdk/lib/render';
// const { instance: IMSDK } = getWithRenderProcess();
// use in mini program
// import { OpenIMSDK } from 'open-im-sdk';
// const IMSDK = new OpenIMSDK();
IMSDK.createSoundMessageByFile({
soundPath: soundFile.path,
duration: 6,
uuid: 'uuid',
sourceUrl: '',
dataSize: soundFile.size,
soundType: soundFile.type,
file: soundFile,
})
.then(({ data }) => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});