Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

This page shows you how to use custom commands to communicate between the web client and the CeeCloudServer using the already established WebSocket.

Client

Add this code in the client (this.m_socket is the web socket which you pass to the constructor of cee.ug.RemoteModel):

    this.m_socket.on("CustomDataResponse", (data:any) => {
        console.log(`Response from client: ${JSON.stringify(data, null, 2)}`)
    });

    this.m_socket.emit("GetCustomData", {command: "getInfo", data: "partId:123"});

 Server

In the CeeCloudServer, add this to the main.js file, before the serverInstance.start(); line:

serverInstance.addCustomPacketHandler("GetCustomData", (packetData, callback) => {

    console.log(`packetData: incomingPacketName:${packetData.incomingPacketName}, 
              incomingData: ${JSON.stringify(packetData.incomingData, null, 2)},
              modelKey: ${packetData.modelKey}, fullModelFileName: ${packetData.fullModelFileName}`);

    const customData = { myValue: 123, myString: "ABC" };
    callback("CustomDataResponse", customData);
});

Running the example 

Executing the code above in the client gives the following output:

Client side

Response from client: {
 "myValue": 123,
 "myString": "ABC"
}

Server side

packetData: incomingPacketName:GetCustomData, incomingData: {
  "command": "getInfo",
  "data": "partId:123"
}, 
                 modelKey: Poppet_Valve.vtfx, fullModelFileName: Poppet_Valve.vtfx
  • No labels