The DeskThing-App is one of two required modules needed to make your own DeskThing App. It serves as a communication layer between your webpage and the rest of the client.
To install the client, use the following command:
npm install deskthing-clientTo use the DeskThing client in your application, you need to import it and get an instance:
import DeskThing from 'deskthing-client';
const deskThing = DeskThing.getInstance();You can send messages to the server using the send method. For example, to send a JSON object to the server:
deskThing.send({ type: 'set', payload: examplePayload });On the server side, you need to import the DeskThing server module and listen for events:
import DeskThing from 'deskthing-server';
const deskThing = DeskThing.getInstance();
deskThing.on('set', (socketData) => {
console.log(socketData.payload);
});Here is a more complete example demonstrating two-way communication between the client and server:
import DeskThing from 'deskthing-client';
const deskThing = DeskThing.getInstance();
// Sending a message to the server
deskThing.send({ type: 'set', payload: { key: 'value' } });
// Listening for a response from the server
deskThing.on('response', (data) => {
console.log('Received response from server:', data);
});import DeskThing from 'deskthing-server';
const deskThing = DeskThing.getInstance();
// Listening for a 'set' message from the client
deskThing.on('set', (socketData) => {
console.log('Received payload:', socketData.payload);
// Sending a response back to the client
deskThing.sendDataToClient(socketData.socketId, {
type: 'response',
payload: { message: 'Data received successfully' }
});
});For more detailed examples and intended implementations, please refer to the apps located at https://github.com/itsriprod/deskthing-apps