我正在尝试使用React JS登录我的XMPP服务器。
我是一个新的反应,所以不知道我做错了什么,请看看你是否可以在这里帮助我。
import './App.css';
var BOSH_SERVICE = 'ws://chat.example.com:7070/ws';
var connection = null;
const Strophe = require("strophe.js").Strophe;
console.log("Strophe is " , Strophe);
Strophe.LogLevel = 0;
connection = new Strophe.Connection(BOSH_SERVICE, { 'keepalive': true });
connection.connect("rajan@example.com","jagruti", onConnect);
console.log("New Connection is " , connection);
function App() {
return (
<div className="App">
<p>Strophe React Example</p>
</div>
);
}
function onConnect(status) {
if (status == Strophe.Status.CONNECTING) {
console.log('Synergy is connecting.');
} else if (status == Strophe.Status.CONNFAIL) {
console.log('Synergy failed to connect.');
} else if (status == Strophe.Status.DISCONNECTING) {
console.log('Synergy is disconnecting.');
} else if (status == Strophe.Status.DISCONNECTED) {
console.log('Synergy is disconnected.');
} else if (status == Strophe.Status.CONNECTED) {
console.log('Synergy is connected.');
// set presence
connection.addHandler(onMessage, null, 'message', null, null, null);
connection.send($pres().tree());
connection.addHandler(onPresence, null, "presence");
connection.sendIQ($iq({ type: "get" }).c("query", { xmlns: Strophe.NS.ROSTER }).tree(), onRoster);
}
} 然而,在编译过程中,我一直收到这个错误:
src/App.js
Line 39:23: '$pres' is not defined no-undef
Line 40:29: 'onPresence' is not defined no-undef
Line 41:25: '$iq' is not defined no-undef发布于 2021-09-08 13:17:58
您还需要导入这些内容。
import { Strophe, $pres, $iq, onPresence } from 'strophe.js'https://stackoverflow.com/questions/68996513
复制相似问题