[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/MxCooperate
Class: MxCooperate
2d.MxCooperate
MxCooperate provides encapsulation of MxCAD's collaborative work functionality.
Description
This class supports creating collaboration sessions, querying collaboration lists, joining/exiting collaborations, initializing collaboration server parameters, and monitoring collaboration status changes. It is suitable for real-time collaboration among multiple people, remote sharing of drawings, collaborative editing, and network synchronization scenarios. Summary of usage:
- Obtain an instance through
MxCpp. mxcad. getCooperate(); - Call interfaces such as' creatWork 'and' joinWork 'to enter collaboration;
- Register 'onEvent' to monitor collaboration status and call 'exitWork()' as needed to exit.
Example
//Create collaborative work and monitor events
import { MxCpp } from "mxcad";
function Mx_Cooperate_OnEvent(){
let cooperate = MxCpp.mxcad.getCooperate();
cooperate.onEvent((eventName: string, iRet: number)=>{
if(eventName == "cooperate_joinWork_complete"){
if(iRet == 0){
console.log("cooperate_joinWork_complete");
}
else{
console.log("cooperate_joinWork_complete return failed,error code:" + iRet);
}
}
else if(eventName == "cooperate_work_network_disconnection"){
console.log("cooperate_work_network_disconnection");
}
})
}
function Mx_Cooperate_Create() {
let cooperate = MxCpp.mxcad.getCooperate();
let workName = "TestWork";
let userId = "54134";
let userData = "TestData";
cooperate.createWork((workid:number) => {
if (workid > 0) {
console.log("create cooperate ok,work name:" + workName + ",id:" + workid);
}
else {
let lErrorCode = -workid;
console.log("create cooperate failed,error code:" + lErrorCode);
if(lErrorCode == 4){
console.log("create cooperate Has been created");
}
}
},workName,userId,userData);
Mx_Cooperate_OnEvent();
}Table of contents
Constructors
Methods
Constructors
constructor
• new MxCooperate(mxcad)
Parameters
| Name | Type |
|---|---|
mxcad | McObject |
Methods
createWork
▸ createWork(retCall?, sWorkData?, sUserId?, sUserData?): number
Create collaborative work
Parameters
| Name | Type |
|---|---|
retCall? | (wrokId: number) => void |
sWorkData? | string |
sUserId? | string |
sUserData? | string |
Returns
number
exitWork
▸ exitWork(): number
Exit the current collaborative work.
Returns
number
Operation result code.
getStatus
▸ getStatus(): number
Get the current status of collaborative work.
Returns
number
Collaborative state coding.
getWorks
▸ getWorks(retCall): number
Retrieve the list of currently collaborating tasks.
Parameters
| Name | Type | Description |
|---|---|---|
| RetCall | (works: any [])=>void | The callback function returns the current collaborative work list. |
Returns
number
Request result code.
init
▸ init(param): any
Initialize the server parameters for collaborative work.
For example: {serverless addresses:“ http://localhost:3091 " }
Parameters
| Name | Type | Description |
|---|---|---|
| Initialize the parameter object with 'parameter' | 'object'. |
Returns
any
joinWork
▸ joinWork(workId, retCall?, sUserId?, sUserData?): number
Create collaborative work
Parameters
| Name | Type |
|---|---|
workId | number |
retCall? | (iRet: number) => void |
sUserId? | string |
sUserData? | string |
Returns
number
onEvent
▸ onEvent(retCall): void
Register collaborative work event callback.
Parameters
| Name | Type | Description |
|---|---|---|
| RetCall | (eventName: string, iRet: number)=>void | Event handling callback, receives event name and result code. |
Returns
void
