DEV Community

SameX
SameX

Posted on

Meeting Application in HarmonyOS Next - Multi-device Collaboration and Application Continuation

In the current trend of digital office work, efficient meeting collaboration has become particularly important. HarmonyOS Next provides powerful distributed capabilities, creating favorable conditions for developing a meeting application that supports multi-device collaboration and application continuation. This article will elaborate in detail on how to develop such a meeting application based on HarmonyOS Next to enhance the efficiency of meeting collaboration.

Design of the Multi-terminal Collaboration Architecture for the Meeting Application

Core Functions

  1. Meeting Sharing: Allow participants to share meeting-related materials, files, presentation documents, etc. among different devices, enabling real-time information exchange.
  2. Seamless Device Switching: Support users to freely switch the meeting process between different devices such as mobile phones and PCs, ensuring the continuity of the meeting and providing a smooth operation experience as if on the same device.
  3. Real-time Content Synchronization: Ensure that various contents in the meeting, such as meeting minutes, speech contents, and file modifications, are updated in real-time on all participating devices, enabling participants to obtain consistent information.
  4. Collaborative Editing: Participants can edit the meeting documents simultaneously, and the system automatically handles conflicts to achieve efficient team collaboration.

How to Implement Application Continuation Using onContinue() + onNewWant()

In HarmonyOS Next, onContinue() and onNewWant() are key interfaces for implementing application continuation. onContinue() is used to save the current state and data of the meeting on the source device, such as the meeting duration, the list of shared files, and unfinished speeches. onNewWant(), on the other hand, receives and restores this data on the target device, allowing the meeting to continue on the new device.

The following is a simple example code for onContinue():

import { AbilityConstant, UIAbility } from '@kit.AbilityKit';

export default class MeetingAbility extends UIAbility {
    onContinue(wantParam: Record<string, Object>) {
        // Save the meeting state data
        let meetingState = getMeetingState(); 
        wantParam["meetingState"] = meetingState;
        return AbilityConstant.OnContinueResult.AGREE;
    }
}
Enter fullscreen mode Exit fullscreen mode

Restore the data in onNewWant() on the target device:

import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';

export default class MeetingAbility extends UIAbility {
    onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        if (launchParam.launchReason === AbilityConstant.LaunchReason.CONTINUATION) {
            let meetingState = want.parameters?.meetingState;
            if (meetingState) {
                restoreMeetingState(meetingState); 
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

How to Design a Data Synchronization Mechanism to Ensure the Consistency of Meeting Contents

To ensure the consistency of meeting contents among different devices, we can use Distributed Data Objects. Distributed Data Objects can automatically handle the synchronization of data among different devices. When the data on one device changes, other devices will be updated in a timely manner.

For example, when creating meeting minutes, a distributed data object can be used:

import { DistributedDataObject } from '@ohos.data.distributedDataObject';

let meetingRecordDDO = DistributedDataObject.create('meetingRecord');
// Set the meeting minutes data
meetingRecordDDO.set('content', 'This is the content of the meeting minutes');
// The data will be automatically synchronized to other devices
Enter fullscreen mode Exit fullscreen mode

Achieving Seamless Meeting Switching & Sharing Documents

Using onContinue() to Migrate the Meeting from a Mobile Phone to a PC

When a user needs to migrate the meeting from a mobile phone to a PC, call the onContinue() method to save the meeting state. On the PC side, receive and restore the meeting state through onNewWant() to achieve seamless switching. The specific code is as shown in the above examples of onContinue() and onNewWant().

Using distributedDataObject.create() to Enable Multi-device Sharing of Meeting Minutes

By creating a distributed data object to store the meeting minutes, all devices participating in the meeting can access and update these minutes. The following is a simple example:

import { DistributedDataObject } from '@ohos.data.distributedDataObject';

// Create a distributed data object for the meeting minutes
let meetingRecordDDO = DistributedDataObject.create('meetingRecord');

// Update the meeting minutes on a certain device
meetingRecordDDO.set('content', 'New content of the meeting minutes');

// Other devices can obtain the updated meeting minutes
let updatedContent = meetingRecordDDO.get('content');
Enter fullscreen mode Exit fullscreen mode

Combining SystemPasteboard to Support Cross-device Copying and Pasting of Meeting Files

Using the SystemPasteboard can achieve the copying and pasting of meeting files among different devices. For example, copy a meeting file on a mobile phone and then paste the file on a PC.

import pasteboard from '@ohos.pasteboard';
import { BusinessError } from '@ohos.base';

// Copy the file to the clipboard on the mobile phone
export async function copyFileToClipboard(fileData: Uint8Array): Promise<void> {
    let pasteData: pasteboard.PasteData = pasteboard.createData('application/octet-stream', fileData);
    let systemPasteBoard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
    await systemPasteBoard.setData(pasteData).catch((err: BusinessError) => {
        console.error(`Failed to set pastedata. Code: ${err.code}, message: ${err.message}`);
    });
}

// Get the file from the clipboard on the PC
export async function getFileFromClipboard(): Promise<Uint8Array | null> {
    let systemPasteBoard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
    return new Promise((resolve, reject) => {
        systemPasteBoard.getData((err: BusinessError, data: pasteboard.PasteData) => {
            if (err) {
                console.error(`Failed to get pastedata. Code: ${err.code}, message: ${err.message}`);
                resolve(null);
            } else {
                let fileData = data.getPrimaryData();
                resolve(fileData);
            }
        });
    });
}
Enter fullscreen mode Exit fullscreen mode

Optimizing the Experience: Smoothness + Compatibility + Security

Optimizing the Data Synchronization Method to Reduce Latency during Meeting Migration

To reduce the data synchronization latency during meeting migration, the following strategies can be adopted:

  • Data Prefetching: When the user shows a tendency to switch devices (such as opening the meeting application on the target device), prefetch some necessary data from the source device in advance.
  • Optimizing Network Transmission: Select appropriate network protocols and transmission methods, and give priority to using high-speed and stable network connections, such as Wi-Fi.
  • Data Compression: Compress the data before transmission to reduce the amount of data and improve the transmission speed.

How to Ensure UI Adaptation for Different Devices and Avoid Interface Misalignment

  • Responsive Design: Use the responsive layout features of HarmonyOS Next to automatically adjust the size and position of interface elements according to the screen size and resolution of the device.
  • Multi-device Testing: During the development process, conduct thorough testing on different types of devices (mobile phones, tablets, PCs, etc.) to promptly identify and resolve interface adaptation issues.

Permission Management: How to Prevent Sensitive Meeting Contents from Being Accessed on Unauthorized Devices

  • Device Authentication: When a device accesses the meeting, authenticate the device to ensure that only authorized devices can participate in the meeting.
  • Data Encryption: Encrypt sensitive data in the meeting so that even if the data is intercepted during transmission or storage, it cannot be decrypted.
  • Permission Settings: Set different permissions for different participants, such as read-only, editable, etc., to restrict access to and modification of sensitive contents.

Through the above architecture design, function implementation, and optimization strategies, we can develop an efficient, stable, and secure meeting application that supports multi-device collaboration and application continuation, providing users with a high-quality meeting collaboration experience.

Top comments (0)