我如何使用strophe.jingle?

时间:2019-05-29 13:54:03

标签: javascript xmpp webrtc strophe.js jingle

我的任务是使用现有的服务器端xmpp / ejabberd设置p2p voip Web应用程序。我面临的问题是我根本不知道如何使用该库。我已经看过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}`);
        }
}

0 个答案:

没有答案