Skip to main content

createSoundMessageByFile

Feature Introduction

Description

Create audio message.

Note

Supported only on the web platform.

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 NameParameter TypeMandatoryDescription
soundPathstringYesAbsolute file path, pass an empty string if not available.
durationnumberYesRecording duration.
uuidstringYesUnique file ID.
sourceUrlstringYesRecording download URL. When manually uploading the file and sending it via sendMessageNotOss, you need to provide the remote url, otherwise, use an empty string.
dataSizestringYesFile size.
soundTypestringYesFile type, usually the file extension.
fileFileYesFile object.

Return Result

Parameter NameParameter TypeDescription
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 { getSDK } from '@openim/client-sdk';
// const IMSDK = getSDK();

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
});