Chips Casino

The following pages contain information on all the technical details of the chips framework and its services. We use a websocket transport for communication between server and client.

Getting Started

yarn add @chipsgg/openservice-ws-client
// ES5
const WebSocket = require("ws");
const Client = require("@chipsgg/openservice-ws-client");

//ES6 - browser
//websockets must be supported in browser
import Client from "@chipsgg/openservice-ws-client";

const channels = ["public", "private", "auth", "community"];

Client(WebSocket, { channels }).then(async ({ state, actions }) => {
  // do somthing

  await actions
    .public("echo", { message: "hello world!" })
    .then(console.log)
    .catch(console.error);

  await actions.community("on", { topic: "chats", path: ["public"] });

  state.on("community.chats.public", console.log);
});

Walkthrough

To interact with the Chips.gg SDK in JavaScript, follow these steps:

1. Install the SDK:

yarn add @chipsgg/openservice-ws-client

2. Set Up the WebSocket Client: Import the necessary modules and establish a connection using the WebSocket protocol.

Here’s an example:

• Channels: Specify the channels to subscribe to, such as 'public', 'private', 'auth', and 'community'.

• Actions: Perform actions like sending an echo message or subscribing to a community chat topic.

• State Events: Listen for events on the subscribed channels and handle them accordingly.

// Import the WebSocket library and the Chips.gg client
const WebSocket = require("ws");
const Client = require("@chipsgg/openservice-ws-client");

// Define the channels you want to subscribe to
const channels = ["public", "private", "auth", "community"];

// Initialize the client
Client(WebSocket, { channels })
  .then(async ({ state, actions }) => {
    // Example action: Echo a message
    try {
      const response = await actions.public("echo", {
        message: "hello world!",
      });
      console.log(response);
    } catch (error) {
      console.error(error);
    }

    // Subscribe to a community chat topic
    try {
      await actions.community("on", { topic: "chats", path: ["public"] });
      state.on("community.chats.public", console.log);
    } catch (error) {
      console.error(error);
    }
  })
  .catch(console.error);

3. Handle Actions and Events: Utilize the actions object to perform various operations provided by the SDK. For instance, to publish a chat message:

// Publish a chat message to the public channel
try {
  const chatResponse = await actions.community("publishChatMessage", {
    room: "public",
    message: "Hello, Chips.gg community!",
  });
  console.log(chatResponse);
} catch (error) {
  console.error(error);
}

// Listen for new chat messages in the public room
state.on("community.chats.public", (chatMessage) => {
  console.log("New chat message:", chatMessage);
});