共享群组
将群组访问权限共享给其他用户,转移所有权,并管理共享请求。
备注
userInstance 和 group —— 参见管理群组。接受或拒绝共享请求时使用 ESPGroupSharingRequest。
本模块的功能
可以授予其他用户对一个或多个群组的访问权限,也可以转移所有权或撤销访问权限。用户级接口是 shareGroups 和 transferGroups,单个群组级接口是 group.share 和 group.transfer。
使用用户级 API 在一次请求中共享多个群组。当界面聚焦于单个群组时,使用群组级 API。
预期结果: 会创建共享请求;接收方接受后获得访问权限;所有者可撤销或转移。
常见工作流程
共享多个群组
const requestId = await userInstance.shareGroups({
username: "family@example.com",
groupIds: ["group_id_1", "group_id_2"],
});
转移多个群组
await userInstance.transferGroups({
toUserName: "new_owner@example.com",
groupIds: ["group_id_1"],
selfToSecondary: false,
});
共享单个群组
await group.share({
username: "guest@example.com",
makePrimary: false,
});
撤销访问权限
await group.removeSharingFor("former_user@example.com");
查看共享信息
const sharingInfo = await group.getSharingInfo({
groupId: group.id,
subGroups: true,
parentGroups: true,
metadata: true,
});
接受收到的请求
const { sharedRequests } = await userInstance.getReceivedGroupSharingRequests();
const request = sharedRequests.find((r) => r.id === requestId);
await request.accept();
拒绝或取消
await request.decline();
const { sharedRequests } = await userInstance.getIssuedGroupSharingRequests();
await sharedRequests[0].remove();
端到端流程
// 所有者发送
await userInstance.shareGroups({
username: "guest@example.com",
groupIds: [group.id],
});
// 访客接受
const { sharedRequests } = await userInstance.getReceivedGroupSharingRequests();
const pending = sharedRequests.find((r) => r.groupIds.includes(group.id));
await pending.accept();
错误处理
try {
await userInstance.shareGroups({ username, groupIds });
} catch (error) {
console.error("Group sharing failed:", error);
}
高级概念
请求生命周期
用户级与群组级
| API | 作用范围 |
|---|---|
shareGroups / transferGroups | 多个群组 |
group.share / group.transfer | 仅当前群组 |
最佳实践
- 在设置 UI 中显示已发送和已接收的待处理请求
- 转移前先确认——所有权变更属于重要操作
- 使用批量
shareGroups,一次性邀请用户加入多个房间 - 调用
getSharingInfo,显示当前有哪些用户拥有访问权限

