Skip to content

[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:

  1. Obtain an instance through MxCpp. mxcad. getCooperate();
  2. Call interfaces such as' creatWork 'and' joinWork 'to enter collaboration;
  3. Register 'onEvent' to monitor collaboration status and call 'exitWork()' as needed to exit.

Example

ts
//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

NameType
mxcadMcObject

Methods

createWork

createWork(retCall?, sWorkData?, sUserId?, sUserData?): number

Create collaborative work

Parameters

NameType
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

NameTypeDescription
RetCall(works: any [])=>voidThe 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

NameTypeDescription
Initialize the parameter object with 'parameter''object'.

Returns

any


joinWork

joinWork(workId, retCall?, sUserId?, sUserData?): number

Create collaborative work

Parameters

NameType
workIdnumber
retCall?(iRet: number) => void
sUserId?string
sUserData?string

Returns

number


onEvent

onEvent(retCall): void

Register collaborative work event callback.

Parameters

NameTypeDescription
RetCall(eventName: string, iRet: number)=>voidEvent handling callback, receives event name and result code.

Returns

void