Nahtuh client is a javascript library to use nahtuh API to develop real time collaboration application.
- Getting Started
- API Documentation
<!-- index.html -->
<script src="https://cdn.nahtuh.com/libraries/nahtuhclient.js"></script>
<script>
const { nahtuhClient, identityManager } = window.NahtuhClient;
</script>
npm i nahtuh-client
import { nahtuhClient, identityManager } from 'nahtuh-client';
Start websocket connection
// use this only when autoStart is set to false
let response = await nahtuhClient.start();
Stop websocket connection
// use this only when autoStart is set to false
let response = await nahtuhClient.stop();
let response = await nahtuhClient.createEvent(participantName, autoStart);
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 |
Name | Type | Description |
---|---|---|
eventInfo | EventInfo | |
participant | Participant | |
participantToken | ParticipantToken |
let response = await nahtuhClient.join(eventId, participantName, autoStart);
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 |
Name | Type | Description |
---|---|---|
eventInfo | EventInfo | |
participant | Participant | |
participantToken | ParticipantToken |
let response = await nahtuhClient.leaveEvent(autoStop);
Name | Nullable | Type | Description |
---|---|---|---|
autoStop | Yes | Boolean | Auto Disconnect web socket when value is true |
Get all participants in the current event
let response = await nahtuhClient.getParticipantList();
Name | Type | Description |
---|---|---|
List |
Get current participant info
let response = await nahtuhClient.getCurrentParticipant();
Name | Type | Description |
---|---|---|
Participant |
Create or join existing group
let response = await nahtuhClient.joinGroup(participantId, groupName);
Name | Nullable | Type | Description |
---|---|---|---|
participantId | No | String | |
groupName | No | String |
let response = await nahtuhClient.leaveGroup(participantId, groupName);
Name | Nullable | Type | Description |
---|---|---|---|
participantId | No | String | |
groupName | No | String |
Get all group members
let response = await nahtuhClient.getGroupMember(groupName);
Name | Nullable | Type | Description |
---|---|---|---|
groupName | No | String |
Name | Type | Description |
---|---|---|
List |
Host configuration is a configuration only the event's host can access. It can be useful to implement host rejoin functionality.
await nahtuhClient.setHostConfiguration(config);
Name | Nullable | Type | Description |
---|---|---|---|
config | No | object | any configuration you want to save |
var response = await nahtuhClient.getHostConfiguration();
Name | Type | Description |
---|---|---|
object | configuration saved by the host |
Send message to all event participants
let response = await nahtuhClient.broadcast(message);
Name | Nullable | Type | Description |
---|---|---|---|
message | No | String |
Send message to a specific user
let response = await nahtuhClient.sendToUser(participantId, message);
Name | Nullable | Type | Description |
---|---|---|---|
participantId | No | String | |
message | No | String |
Send message to all participant in a specific group
let response = await nahtuhClient.sendToGroup(groupName, message);
Name | Nullable | Type | Description |
---|---|---|---|
groupName | No | String | |
message | No | String |
Call back function when new participant join to an event
nahtuhClient.onParticipantJoined = (data) => {}
Name | Type | Description |
---|---|---|
Participant |
call back function when new participant leave an event
nahtuhClient.onParticipantLeave = (data) => {}
Name | Type | Description |
---|---|---|
Participant |
call back function when new message received
nahtuhClient.onIncomingMessage = (data) => {}
Name | Type | Description |
---|---|---|
Message |
call back function when participant join to a group
nahtuhClient.onGroupMemberJoined = (data) => {}
Name | Type | Description |
---|---|---|
groupName | String | |
participantId | String | |
participantName | String |
call back function when participant left a group
nahtuhClient.onGroupMemberLeft = (data) => {}
Name | Type | Description |
---|---|---|
groupName | String | |
participantId | String | |
participantName | String |
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 |
Name | Type | Description |
---|---|---|
avatarUrl | String | |
connected | Boolean | connection status of the websocket |
isHost | Boolean | |
participantId | String | |
participantName | String |
Name | Type | Description |
---|---|---|
username | String | |
accessToken | String | Token used to access nahtuh API |
refreshToken | String | Token used to refresh accessToken |
Name | Type | Description |
---|---|---|
participantId | String | |
participantName | String |
Name | Type | Description |
---|---|---|
method | String | BM = Broadcast Message, PM=Private Message, GM = Group Message |
content | String | |
senderId | String | ParticipantId of the sender |