logo
In-app Chat
SDK Error Codes
On this page

Cancel Media Message Sending


Feature Overview

The ZIM SDK supports canceling messages containing local media files that are currently being sent. After a successful cancellation, the message status will change to "Failed to Send".

Note
  • Supported from version 2.22.0.
  • Only messages containing local media files of the following message types can be canceled: Multiple(10), Image(11), File(12), Audio(13), Video(14).

Cancel the Media Message Being Sent

When a user sends a message containing a local media file, due to the time required for file upload, the file upload can be terminated by calling cancelSendingMessage during this period.

Note

When a multi item messages containing both ordinary text and media files is canceled, the entire message (including ordinary text) will be canceled.

zim.on('messageSentStatusChanged', (zim: ZIM, data: ZIMEventOfMessageSentStatusChangedResult) => {
    // Message sent status changed
});
// User A sends a message, taking a single-chat file message as an example

const userID_A = "xxxx" ;    // User A's ID
const userID_B = "xxxx" ;    // User B's ID

const messageObj: ZIMFileMessage = { type: 12, fileLocalPath: file }
const config: ZIMMessageSendConfig = {
    priority: 1,    // Message priority, the value is 1 for low, 2 for medium, and 3 for high
}
const notification: ZIMMessageSendNotification = {
    onMessageAttached: (message: ZIMMessage) => {
        // todo: Loading
    },
    onMediaUploadingProgress: (message: ZIMMediaMessage, currentFileSize: number, totalFileSize: number) {
        // Cancel sending when the file is being uploaded
        zim.cancelSendingMessage(message, {} as ZIMSendingMessageCancelConfig)
            .then((res: ZIMMessageSentResult) => {
                // Operation successful
            })
            .catch((err: ZIMError) => {
                // Operation failed
            });
    }
}

zim.sendMessage(messageObj, userID_B, 0, config, notification)
    .then((res: ZIMMessageSentResult) => {
        // Sent successfully
    })
    .catch((err: ZIMError) => {
        // Failed to send
    });

Previous

Send and receive targeted messages in groups

Next

Call invitation (signaling)

On this page

Back to top