0.10.4 • Published 8 months ago

deskthing-client v0.10.4

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

DeskThing Client NPM

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.

Installation

To install the client, use the following command:

npm install deskthing-client

Usage

Initializing the DeskThing Client

To 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();

Sending Messages to the Server

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 });

Receiving Messages on the Server

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);
});

Example: Two-Way Communication

Here is a more complete example demonstrating two-way communication between the client and server:

Client Side

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);
});

Server Side

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' }
  });
});

Additional Information

For more detailed examples and intended implementations, please refer to the apps located at https://github.com/itsriprod/deskthing-apps

0.10.4

8 months ago

0.10.2

8 months ago

0.10.3

8 months ago

0.10.0

8 months ago

0.10.1

8 months ago

0.9.4

9 months ago

0.9.3

9 months ago

0.9.0

10 months ago

0.9.2

10 months ago

0.9.1

10 months ago

0.8.2

11 months ago

0.8.1

12 months ago

0.7.6

12 months ago

0.7.5

12 months ago

0.8.0

12 months ago

0.7.2

12 months ago