0

I am using Strophe.js to connect with Openfire XMPP server. Connection got established with status CONNECTED but I am not able to send presence to server i.e user is not showing online on Openfire console.

Here is my plunker link : Plunker

In the code please refer src/app.ts line no.47

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

Problem is in above method.

Please tell what I am missing or what is incorrect?

Thanks

Pooja Pradhan
  • 83
  • 1
  • 7

1 Answers1

1

This is how we fixed the issue. When Strophe calls the Handles for the events all of the variables defined previously are undefined. In this case "this.connection" is undefined.

We first defined a global variable and set it in the constructor.

var Strophethis;

export class StropheAccess {

private connection: any;

constructor () {
   Strophethis = this;
}

When the Call Backs are executed, update the needed variables.

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

Then the Send will work.

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

In addition to this update we also needed to import the $pres and others.

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

Good Luck.