@hsaadawy/ngx-chat
Version:
154 lines (153 loc) • 5.67 kB
TypeScript
import { JID } from '@xmpp/jid';
import { BehaviorSubject, Subject } from 'rxjs';
import { ContactMetadata } from '../../../../core/contact';
import { Message } from '../../../../core/message';
import { DateMessagesGroup } from '../../../../core/message-store';
import { Recipient } from '../../../../core/recipient';
import { IqResponseStanza, Stanza } from '../../../../core/stanza';
import { LogService } from '../../../log.service';
import { XmppChatAdapter } from '../xmpp-chat-adapter.service';
import { AbstractXmppPlugin } from './abstract-xmpp-plugin';
import { ServiceDiscoveryPlugin } from './service-discovery.plugin';
/**
* see:
* https://xmpp.org/extensions/xep-0045.html#terms-rooms
*/
export interface RoomCreationOptions {
name?: string;
roomId: string;
/**
* A room that can be found by any user through normal means such as searching and service discovery
*/
public: boolean;
/**
* for true:
* A room that a user cannot enter without being on the member list.
* for false:
* A room that non-banned entities are allowed to enter without being on the member list.
*/
membersOnly: boolean;
/**
* for true:
* A room in which an occupant's full JID is exposed to all other occupants,
* although the occupant can request any desired room nickname.
* for false:
* A room in which an occupant's full JID can be discovered by room admins only.
*/
nonAnonymous: boolean;
/**
* for true:
* A room that is not destroyed if the last occupant exits.
* for false:
* A room that is destroyed if the last occupant exits.
*/
persistentRoom: boolean;
/**
* Optional name for the room, if no provided room will be only identified by its jid
*/
nick?: string;
/**
* allow ejabberd MucSub subscriptions.
* Room occupants are allowed to subscribe to message notifications being archived while they were offline
*/
allowSubscription?: boolean;
}
export interface RoomMessage extends Message {
from: JID;
}
export interface Occupant {
roomJid: JID;
realJid?: JID;
metadata: ContactMetadata;
}
export interface RoomMetadata {
[key: string]: any;
}
export declare class Room {
readonly recipientType = "room";
readonly roomJid: JID;
occupantJid: JID;
name: string;
nick: string;
avatar: string;
metadata: RoomMetadata;
private messageStore;
get jidBare(): JID;
constructor(occupantJid: JID, logService: LogService, name?: string | undefined);
get messages$(): Subject<RoomMessage>;
get messages(): RoomMessage[];
get dateMessagesGroups(): DateMessagesGroup<RoomMessage>[];
get oldestMessage(): RoomMessage;
get mostRecentMessage(): RoomMessage;
get mostRecentMessageReceived(): RoomMessage;
get mostRecentMessageSent(): RoomMessage;
addMessage(message: RoomMessage): void;
equalsBareJid(other: Recipient | JID): boolean;
}
export declare enum Affiliation {
none = 0,
member = 1,
admin = 2,
owner = 3,
outcast = 4
}
export interface MemberListItem {
jid: string;
affiliation: Affiliation;
nick?: string;
}
export interface RoomSummary {
jid: string;
name: string;
}
/**
* The MultiUserChatPlugin tries to provide the necessary functionality for a multi-user text chat,
* whereby multiple XMPP users can exchange messages in the context of a room or channel, similar to Internet Relay Chat (IRC).
* For more details see:
* @see https://xmpp.org/extensions/xep-0045.html
*/
export declare class MultiUserChatPlugin extends AbstractXmppPlugin {
private readonly xmppChatAdapter;
private readonly logService;
private readonly serviceDiscoveryPlugin;
readonly rooms$: BehaviorSubject<Room[]>;
readonly message$: Subject<Room>;
private readonly roomJoinResponseHandlers;
constructor(xmppChatAdapter: XmppChatAdapter, logService: LogService, serviceDiscoveryPlugin: ServiceDiscoveryPlugin);
onOffline(): void;
handleStanza(stanza: Stanza, archiveDelayElement?: Stanza): boolean;
private isRoomPresenceStanza;
private handleRoomPresenceStanza;
/**
* Resolves if room could be configured as requested, rejects if room did exist or server did not accept configuration.
*/
createRoom(request: RoomCreationOptions): Promise<Room>;
destroyRoom(roomJid: JID): Promise<IqResponseStanza<'result'>>;
private joinRoomInternal;
joinRoom(occupantJid: JID): Promise<Room>;
queryAllRooms(): Promise<RoomSummary[]>;
private extractRoomSummariesFromResponse;
private extractResultSetFromResponse;
/**
* Get all members of a MUC-Room with their affiliation to the room using the rooms fullJid
* @param fullRoomJid fullJid of the room as string
*/
queryMemberList(fullRoomJid: string): Promise<MemberListItem[]>;
private reverseMapAffiliation;
modifyMemberList(roomJid: string, jid: string, affiliation: Affiliation, nick?: string): Promise<IqResponseStanza>;
sendMessage(room: Room, body: string, thread?: string): Promise<void>;
private configurationToElements;
private extractDefaultConfiguration;
private applyRoomCreationRequestOptions;
private isRoomMessageStanza;
private handleRoomMessageStanza;
getRoomByJid(jid: JID): Room | undefined;
ban(): void;
invite(): void;
join(): void;
kick(): void;
nick(): void;
part(): void;
leave(): void;
topic(): void;
}