Untitled

šŸ“°Getting Started | ā­**Updates |** šŸ“ Guides | šŸ”¢ API | ā“FAQ

Guides Overview

Enklu Multiplayer SDK for Node.Js

Every experience developed onĀ Enklu CloudĀ is backed by a powerful mutliplayer service, Mycelium. The goal of this SDK is to provide external applications and devices with session-based access to experiences via Mycelium. With this SDK, you can send and receive messages to Enklu Cloud from your own servers, IoT devices, custom applications, and whatever else you can imagine.

Should I use this SDK?

Enklu Cloud's behavior scripting can be used to create multiplayer experiences, as documentedĀ here.

This SDK is designed for users who have specific use cases that require multiplayer code to be running externally from user devices.

Installing

In the future, an NPM module will be available. Currently, it can be cloned directly fromĀ GitHub.

Getting Started

AnĀ Enklu CloudĀ account is required to use this SDK. Once you have an account set up, you can generate a token for the authoring API.

curl -X POST '<https://cloud.enklu.com:10001/v1/email/signin>' \\
     -H 'Content-Type: application/json' \\
     -d '{"email":"[email protected]","password":"12345"}'
Copy

TheĀ tokenĀ value received in a successful response can then be used to generate a multiplayer token. Each token is associated with a specific experience, so an experience Id is required as well. You can find the app id for an experience on the "My Experiences" modal or in the Inspector panel when the root element of an experience is selected in theĀ Enklu CloudĀ web editor.

curl -X POST '<https://cloud.enklu.com:10001/v1/app/${your-app-id}/token>' \\
     -H 'Authorization: Bearer ${your-jwt-token}' \\
     -H 'Content-Type: application/json' \\
     -d '{}'
Copy

A successful respnse will contain a Json Web Token that can be used in the SDK. Now you can start sending messages.

const {Mycelium} = require('enklu-node-sdk');

const JWT = process.env.JWT;
const mycelium =new Mycelium();

let isLoggedIn = false;

mycelium.on('message', (msg) => {
  console.log(`received ${msg.event} event`);
if (msg.event === 'LoginResponse') {
    isLoggedIn = true;
  }

if (isLoggedIn) {
    mycelium.broadcast('ping', 'hello from the sdk');
  }
});

mycelium.on('connect', () => {
  console.log('connected to mycelium!');
  mycelium.login(JWT);
});

mycelium.connect();

Copy

API Reference

A more comprehensive API reference is available onĀ GitHub.

Next: Installing Enklu Embedded

Sidebar Table of Contents


Untitled

Copyright Ā© 2021 Enklu, Inc.