123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- import { getLogger } from '@jitsi/logger';
- import $ from 'jquery';
- import { $iq, type Connection } from 'strophe.js';
-
- import ConnectionPlugin from './ConnectionPlugin';
-
- const logger = getLogger('modules/xmpp/strophe.rayo');
-
- const RAYO_XMLNS = 'urn:xmpp:rayo:1';
-
- /**
- *
- */
- export default class RayoConnectionPlugin extends ConnectionPlugin {
- private callResource: string | null = null;
-
- /**
- *
- * @param connection
- */
- init(connection: Connection): void {
- super.init(connection);
-
- connection.addHandler(
- this.onRayo.bind(this),
- RAYO_XMLNS,
- 'iq',
- 'set',
- null,
- null
- );
- }
-
- /**
- *
- * @param iq
- */
- onRayo(iq: any): any {
- logger.info('Rayo IQ', iq);
- }
-
- /* eslint-disable max-params */
-
- /**
- *
- * @param to
- * @param from
- * @param roomName
- * @param roomPass
- * @param focusMucJid
- */
- dial(
- to: string,
- from: string,
- roomName: string,
- roomPass: string,
- focusMucJid: string
- ): Promise<void> {
- return new Promise((resolve, reject) => {
- if (!focusMucJid) {
- reject(new Error('Internal error!'));
-
- return;
- }
- const req = $iq({
- type: 'set',
- to: focusMucJid,
- });
-
- req.c('dial', {
- xmlns: RAYO_XMLNS,
- to,
- from,
- });
- req.c('header', {
- name: 'JvbRoomName',
- value: roomName,
- }).up();
-
- if (roomPass?.length) {
- req.c('header', {
- name: 'JvbRoomPassword',
- value: roomPass,
- }).up();
- }
-
- (this.connection as Connection).sendIQ(
- req,
- result => {
- logger.info('Dial result ', result);
-
- // eslint-disable-next-line newline-per-chained-call
- const resource = $(result).find('ref').attr('uri');
-
- this.callResource = resource.substr('xmpp:'.length);
- logger.info(`Received call resource: ${this.callResource}`);
- resolve();
- },
- error => {
- logger.info('Dial error ', error);
- reject(error);
- }
- );
- });
- }
-
- /* eslint-enable max-params */
-
- /**
- *
- */
- hangup(): Promise<void> {
- return new Promise((resolve, reject) => {
- if (!this.callResource) {
- reject(new Error('No call in progress'));
- logger.warn('No call in progress');
-
- return;
- }
-
- const req = $iq({
- type: 'set',
- to: this.callResource,
- });
-
- req.c('hangup', {
- xmlns: RAYO_XMLNS,
- });
-
- (this.connection as Connection).sendIQ(
- req,
- result => {
- logger.info('Hangup result ', result);
- this.callResource = null;
- resolve();
- },
- error => {
- logger.info('Hangup error ', error);
- this.callResource = null;
- reject(new Error('Hangup error '));
- }
- );
- });
- }
- }
|