Giter Club home page Giter Club logo

nahtuh's Introduction

Nahtuh Client

Nahtuh client is a javascript library to use nahtuh API to develop real time collaboration application.

Contents

Getting Started

CDN

<!-- index.html -->
<script src="https://cdn.nahtuh.com/libraries/nahtuhclient.js"></script>
<script>
  const { nahtuhClient, identityManager } = window.NahtuhClient;
</script>

NPM

npm i nahtuh-client
import { nahtuhClient, identityManager } from 'nahtuh-client';

API Documentation

Connection API

Start Connection

Start websocket connection

// use this only when autoStart is set to false
let response = await nahtuhClient.start();

Stop Connection

Stop websocket connection

// use this only when autoStart is set to false
let response = await nahtuhClient.stop();

Event Management API

Create Event

let response = await nahtuhClient.createEvent(participantName, autoStart);
Parameters
Name Nullable Type Description
participantName No String nickname you want to use in the event
autoStart Yes Boolean Auto Connect web socket when value is true
Response
Name Type Description
eventInfo EventInfo
participant Participant
participantToken ParticipantToken

Join Event

let response = await nahtuhClient.join(eventId, participantName, autoStart);
Parameters
Name Nullable Type Description
eventId No String Unique Id of the event you want to join to
participantName No String nickname you want to use in the event
autoStart Yes Boolean Auto Connect web socket when value is true
Response
Name Type Description
eventInfo EventInfo
participant Participant
participantToken ParticipantToken

Leave Event

let response = await nahtuhClient.leaveEvent(autoStop);
Parameters
Name Nullable Type Description
autoStop Yes Boolean Auto Disconnect web socket when value is true

Get Participant List

Get all participants in the current event

let response = await nahtuhClient.getParticipantList();
Response
Name Type Description
List

Get Current Participant

Get current participant info

let response = await nahtuhClient.getCurrentParticipant();
Response
Name Type Description
Participant

Group Management API

Join Group

Create or join existing group

let response = await nahtuhClient.joinGroup(participantId, groupName);
Parameters
Name Nullable Type Description
participantId No String
groupName No String

Leave Group

let response = await nahtuhClient.leaveGroup(participantId, groupName);
Parameters
Name Nullable Type Description
participantId No String
groupName No String

Get Group Member

Get all group members

let response = await nahtuhClient.getGroupMember(groupName);
Parameters
Name Nullable Type Description
groupName No String
Response
Name Type Description
List

Host Configuration API

Host configuration is a configuration only the event's host can access. It can be useful to implement host rejoin functionality.

Set Host Configuration

await nahtuhClient.setHostConfiguration(config);
Parameters
Name Nullable Type Description
config No object any configuration you want to save

Get Host Configuration

var response = await nahtuhClient.getHostConfiguration();
Response
Name Type Description
object configuration saved by the host

Messaging API

Broadcast

Send message to all event participants

let response = await nahtuhClient.broadcast(message);
Parameters
Name Nullable Type Description
message No String

Send To User

Send message to a specific user

let response = await nahtuhClient.sendToUser(participantId, message);
Parameters
Name Nullable Type Description
participantId No String
message No String

Send To Group

Send message to all participant in a specific group

let response = await nahtuhClient.sendToGroup(groupName, message);
Parameters
Name Nullable Type Description
groupName No String
message No String

Event Handlers

On Participant Joined

Call back function when new participant join to an event

nahtuhClient.onParticipantJoined = (data) => {}
Data
Name Type Description
Participant

On Participant Leave

call back function when new participant leave an event

nahtuhClient.onParticipantLeave = (data) => {}
Data
Name Type Description
Participant

On Incoming Message

call back function when new message received

nahtuhClient.onIncomingMessage = (data) => {}
Data
Name Type Description
Message

On Group Member Joined

call back function when participant join to a group

nahtuhClient.onGroupMemberJoined = (data) => {}
Data
Name Type Description
groupName String
participantId String
participantName String

On Group Member Left

call back function when participant left a group

nahtuhClient.onGroupMemberLeft = (data) => {}
Data
Name Type Description
groupName String
participantId String
participantName String

Types

EventInfo

Name Type Description
activityId String Unique Id used by the activity created an activity is submitted to nahtuh
activitySetId String
createdDate String Timestamp of the event creation
eventId String Unique Id for the newly created event
invitationUrl String

Participant

Name Type Description
avatarUrl String
connected Boolean connection status of the websocket
isHost Boolean
participantId String
participantName String

ParticipantToken

Name Type Description
username String
accessToken String Token used to access nahtuh API
refreshToken String Token used to refresh accessToken

GroupMember

Name Type Description
participantId String
participantName String

Message

Name Type Description
method String BM = Broadcast Message, PM=Private Message, GM = Group Message
content String
senderId String ParticipantId of the sender

nahtuh's People

Contributors

drakemd avatar mabudiman avatar mdarud avatar ndriyo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.