0

I want to use Strophe.js library in an angular 4 application to connect to XMPP server. I have connected to server successfully. But I am not able to send presence so user is not showing online.

Can anyone please tell how to use $pres, receivemessage callback etc in typescript?

I used this "npm install strophe.js" command to install strophe & import { Strophe } from 'strophe.js'; in my .ts file.

Thanks in advance.

1 Answers1

0

Strophe.js has a type definitions for TypeScript which you can install it via

npm install --save @types/strophe

then you can import the type via

import {Strophe} from 'strophe';

after that you have full access of its functionality.

Update

Another solution would be declaring a variable like this:

declare let strophe: any;
Abbas Amiri
  • 3,074
  • 1
  • 23
  • 23
  • I am getting this error after installing @types/strophe. Module not found: Error: Can't resolve 'strophe' in '/Lab/src/app' resolve 'strophe' in '/Lab/src/app' Parsed request is a module using description file: /Lab/package.json (relative path: ./src/app) Field 'browser' doesn't contain a valid alias configuration after using description file: /Lab/package.json (relative path: ./src/app) – Aditi Purohit Feb 05 '18 at 12:44
  • @AditiPurohit, I have altered the `index.d.ts` and it worked, but I think it wouldn't be appropriated for you. I recommend you using second method (declare let strophe: any). – Abbas Amiri Feb 05 '18 at 13:22