Как мне использовать strophe.jingle? - PullRequest
0 голосов
/ 29 мая 2019

Мне было поручено настроить веб-приложение p2p voip с использованием существующей серверной части xmpp / ejabberd. Проблема, с которой я столкнулся, заключается в том, что я вообще не знаю, как пользоваться библиотекой. Я посмотрел на muc и ​​jingle-interop-demo и просто не понимаю, как мне это реализовать.

Я пытался импортировать библиотеку и добавить ее в соединение strophe, однако она не работает. Я импортировал библиотеку, как и для strophejs-plugings, и все они работали нормально.

import { Strophe, $iq, $pres, $msg } from 'strophe.js';
import 'strophejs-plugins/roster/strophe.roster';
import 'strophe.jingle/strophe.jingle.js';

const conn = new Strophe.Connection(xmppurl);
// setupRTC function is within the strophe.jingle library
var RTC = setupRTC(); // error setupRTC is undefined
var RTCPeerconnection = RTC.peerconnection; 
conn.jingle.pc_constraints = RTC.pc_constraints;


onConnect(status, err) {
        if (status === Strophe.Status.CONNECTING) {
            store.dispatch(connectXMPP('connecting'));
            status = 'connecting';
        } else if (status === Strophe.Status.CONNFAIL) {
            store.dispatch(connectXMPP('connection failed'));
            status = 'connection failed';
        } else if (status === Strophe.Status.AUTHFAIL) {
            store.dispatch(connectXMPP('auth failed'));
            status = 'auth failed';
        } else if (status === Strophe.Status.DISCONNECTING) {
            store.dispatch(connectXMPP('disconnecting'));
            status = 'disconnecting';
        } else if (status === Strophe.Status.DISCONNECTED) {
            store.dispatch(connectXMPP('disconnected'));
            status = 'disconnected';
            this.login();
        } else if (status === Strophe.Status.CONNECTED) {
            store.dispatch(connectXMPP('connected'));
            store.dispatch(fetchContacts());
            // api.sayHello();
            status = 'connected';
            // getUserMediaWithConstraints(['audio', 'video']);
            // conn.jingle.getStunAndTurnCredentials();
            conn.addHandler(this.onPresence, null, 'presence');
            conn.addHandler(this.onMessage, null, 'message', null, null, null);
            conn.addHandler(this.handlePong, null, 'iq', null, 'ping1');
            // pass connection to roster plugin
            conn.roster.init(conn);
            this.getRoster();
            this.sendPing();
        } else if (err) {
            store.dispatch(connectXMPP(`error: ${err}`));
            console.log(`err: ${err}`);
        }
}

...