首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Strophe与React JS集成

将Strophe与React JS集成
EN

Stack Overflow用户
提问于 2021-08-31 09:49:38
回答 1查看 50关注 0票数 1

我正在尝试使用React JS登录我的XMPP服务器。

我是一个新的反应,所以不知道我做错了什么,请看看你是否可以在这里帮助我。

代码语言:javascript
复制
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);
  }
} 

然而,在编译过程中,我一直收到这个错误:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-08 13:17:58

您还需要导入这些内容。

代码语言:javascript
复制
import  { Strophe, $pres, $iq, onPresence } from 'strophe.js'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68996513

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档