HarmonyOS Next Meeting Application: Multi-device Collaboration and Application Continuation
In the current digital office trend, efficient meeting collaboration has become particularly important. HarmonyOS Next offers powerful distributed capabilities, creating favorable conditions for developing a meeting application that supports multi-device collaboration and application continuation. This article will elaborate on how to develop such a meeting application based on HarmonyOS Next to enhance meeting collaboration efficiency.
Multi-terminal Collaborative Architecture Design of the Meeting Application
Core Functions
- Meeting Sharing: Allows participants to share meeting-related materials, files, presentations, etc., between different devices, enabling real-time information exchange.
- Seamless Device Switching: Supports users to freely switch the meeting process between different devices such as mobile phones and PCs, ensuring the continuity of the meeting as smoothly as operating on the same device.
- Real-time Content Synchronization: Ensures that all kinds of content in the meeting, such as meeting records, speech content, and file modifications, are updated in real-time on all participating devices, enabling participants to obtain consistent information.
- Collaborative Editing: Participants can edit meeting documents simultaneously, and the system automatically handles conflicts to achieve efficient team collaboration.
How to Use onContinue() + onNewWant() to Implement Application Continuation
In HarmonyOS Next, onContinue() and onNewWant() are the 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 progress time, the list of shared files, and unfinished speeches. onNewWant() receives and restores this data on the target device, allowing the meeting to continue on the new device.
Here 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 meeting state data
let meetingState = getMeetingState();
wantParam["meetingState"] = meetingState;
return AbilityConstant.OnContinueResult.AGREE;
}
}
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);
}
}
}
}
How to Design a Data Synchronization Mechanism to Ensure Meeting Content Consistency
To ensure the consistency of meeting content across different devices, we can use Distributed Data Objects. Distributed Data Objects can automatically handle data synchronization between different devices. When the data on one device changes, other devices will be updated in a timely manner.
For example, when creating a meeting record, you can use a Distributed Data Object:
import { DistributedDataObject } from '@ohos.data.distributedDataObject';
let meetingRecordDDO = DistributedDataObject.create('meetingRecord');
// Set meeting record data
meetingRecordDDO.set('content', 'This is the content of the meeting record');
// The data will be automatically synchronized to other devices
Achieving Seamless Meeting Switching and 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 Multiple Devices to Share Meeting Records
Create a Distributed Data Object to store meeting records, and all devices participating in the meeting can access and update these records. Here is a simple example:
import { DistributedDataObject } from '@ohos.data.distributedDataObject';
// Create a Distributed Data Object for meeting records
let meetingRecordDDO = DistributedDataObject.create('meetingRecord');
// Update the meeting record on a certain device
meetingRecordDDO.set('content', 'New content of the meeting record');
// Other devices can get the updated meeting record
let updatedContent = meetingRecordDDO.get('content');
Combining SystemPasteboard to Support Cross-device Copying and Pasting of Meeting Files
Using the SystemPasteboard can achieve cross-device copying and pasting of meeting files. For example, copy a meeting file on a mobile phone and then paste it on a PC.
import pasteboard from '@ohos.pasteboard';
import { BusinessError } from '@ohos.base';
// Copy a file to the clipboard on a 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 a file from the clipboard on a 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);
}
});
});
}
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 data volume and improve the transmission speed.
How to Ensure UI Adaptation on 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 comprehensive testing on different types of devices (mobile phones, tablets, PCs, etc.) to promptly discover and solve interface adaptation problems.
Permission Management: How to Prevent Sensitive Meeting Content 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 cracked.
- Permission Settings: Set different permissions for different participants, such as read-only and editable, to restrict access to and modification of sensitive content.
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)