Strophe.js send($ pres($ pres())在打字稿Angular(版本5)中不起作用



我正在使用 strophe.js OpenFire XMPP 服务器连接。连接通过状态连接建立,但我无法将其发送到服务器。

这是我的plunker链接:plunker

在代码中,请参阅src/app.ts行号47

this.connection.send($pres());

问题在上述方法中。

请告诉我缺少什么或什么是不正确的?

谢谢

这就是我们解决问题的方式。当Strophe调用事件的手柄时,前面定义的所有变量都是不确定的。在这种情况下," this.connection"是未定义的。

我们首先定义了一个全局变量并将其设置在构造函数中。

var Strophethis;
export class StropheAccess {
private connection: any;
constructor () {
   Strophethis = this;
}

执行呼叫后,更新所需的变量。

onConnection (status): boolean {
   this.connection = StropheAccess.connection;

然后发送将起作用。

 this.connection.send($pres());

除了此更新外,我们还需要导入$ PRES和其他。

import { Strophe} from 'strophe';
import { $pres} from 'strophe';
import { $iq } from 'strophe';
import { $msg} from 'strophe';
import { $build } from 'strophe';

祝你好运。

最新更新