Skip to content

Commit

Permalink
feat(docs): improve eos connect changes docs
Browse files Browse the repository at this point in the history
  • Loading branch information
LeleDerGrasshalmi committed Jul 25, 2024
1 parent 774508c commit f549ca1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/managers/ChatManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@ import Base from '../Base';
import UserNotFoundError from '../exceptions/UserNotFoundError';
import type { ChatMessagePayload } from '../../resources/structs';

// private scope
const generateCustomCorrelationId = () => `EOS-${Date.now()}-${randomUUID()}`;

/**
* Represent's the client's chat manager (dm, party chat) via eos.
*/
class ChatManager extends Base {
private get namespace() {
/**
* Returns the chat namespace, this is the eos deployment id
*/
public get namespace() {
return this.client.config.eosDeploymentId;
}

/**
* Sends a private message to the specified user
* @param user the account id or displayname
* @param message the message object
* @returns the message id
*/
public async whisperUser(user: string, message: ChatMessagePayload) {
const accountId = await this.client.user.resolveId(user);

Expand All @@ -36,6 +49,13 @@ class ChatManager extends Base {
return correlationId;
}

/**
* Sends a message in the specified conversation (party chat)
* @param conversationId the conversation id, usually `p-[PARTYID]`
* @param message the message object
* @param allowedRecipients the account ids, that should receive the message
* @returns the message id
*/
public async sendMessageInConversation(conversationId: string, message: ChatMessagePayload, allowedRecipients: string[]) {
const correlationId = generateCustomCorrelationId();

Expand Down
9 changes: 8 additions & 1 deletion src/stomp/EOSConnect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { Client as StompClient, Versions } from '@stomp/stompjs';
import WebSocket, { type ErrorEvent } from 'ws';
import Base from '../Base';
Expand Down Expand Up @@ -50,6 +49,9 @@ class EOSConnect extends Base {
return this.stompConnectionId;
}

/**
* connect to the eos connect stomp server
*/
public async connect() {
if (!this.client.auth.sessions.has(AuthSessionStoreKey.FortniteEOS)) {
throw new AuthenticationMissingError(AuthSessionStoreKey.FortniteEOS);
Expand Down Expand Up @@ -123,6 +125,11 @@ class EOSConnect extends Base {
this.client.debug('[STOMP EOS Connect] Disconnected');
}

/**
* Sets up the subscription for the deployment
* @param connectionResolve connect promise resolve
* @param connectionReject connect promise reject
*/
private setupSubscription(connectionResolve: (value: unknown) => void, connectionReject: (reason?: unknown) => void) {
this.stompConnection!.subscribe(
`${this.client.config.eosDeploymentId}/account/${this.client.user.self!.id}`,
Expand Down
5 changes: 5 additions & 0 deletions src/xmpp/XMPP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ class XMPP extends Base {
* @param to The message receiver's JID
* @param content The message that will be sent
* @param type The message type (eg "chat" or "groupchat")
* @deprecated this is useless now, since chat messages are handeled via an rest api now see {@link Client#chat}
*/
public async sendMessage(to: string, content: string, type: Constants.MessageType = 'chat') {
return this.waitForSentMessage(this.connection!.sendMessage({
Expand All @@ -684,6 +685,7 @@ class XMPP extends Base {
* Wait until a message is sent
* @param id The message id
* @param timeout How long to wait for the message
* @deprecated this is useless now, since chat messages are handeled via an rest api now see {@link Client#chat}
*/
public waitForSentMessage(id: string, timeout = 1000) {
return new Promise<Stanzas.Message | undefined>((res) => {
Expand All @@ -710,6 +712,7 @@ class XMPP extends Base {
* Joins a multi user chat room (MUC)
* @param jid The room's JID
* @param nick The client's nickname
* @deprecated this is useless now, since chat messages are handeled via an rest api now see {@link Client#chat}
*/
public async joinMUC(jid: string, nick: string) {
return this.connection!.joinRoom(jid, nick);
Expand All @@ -719,6 +722,7 @@ class XMPP extends Base {
* Leaves a multi user chat room (MUC)
* @param jid The room's JID
* @param nick The client's nickname
* @deprecated this is useless now, since chat messages are handeled via an rest api now see {@link Client#chat}
*/
public async leaveMUC(jid: string, nick: string) {
return this.connection!.leaveRoom(jid, nick);
Expand All @@ -727,6 +731,7 @@ class XMPP extends Base {
/**
* Bans a member from a multi user chat room
* @param member The member that should be banned
* @deprecated this is useless now, since chat messages are handeled via an rest api now see {@link Client#chat}
*/
public async ban(jid: string, member: string) {
return this.connection!.ban(jid, `${member}@${Endpoints.EPIC_PROD_ENV}`);
Expand Down

0 comments on commit f549ca1

Please sign in to comment.