Skip to content
forked from eComindo/Nahtuh

Nahtuh repository for activity client

Notifications You must be signed in to change notification settings

mabudiman/Nahtuh

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Nahtuh repository for activity client

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%