Approaches that I have tried:
Approach 1:
Downloaded the
strophejs-1.3.4.zipfrom http://strophe.im/strophejs/Placed the unzipped folder i.e.,
strophejs-1.3.4insrc/assetsfolder in my angular8 project.In my
index.htmlfile have included
<!--// Strophe.js-->
<script src='assets/strophejs-1.3.4/src/strophe.js'></script>
I installed @types/strophe using the command :
npm install --save-dev @types/stropheThen in my component.ts file declare let Strophe: any;
By following these steps the compilation is sucessful, however on running, I am getting run time reference error: Reference Error: Strophe is not defined
Below is my component.ts file
import { Component, OnInit } from '@angular/core';
declare let Strophe: any;
@Component({
selector: 'app-oauth',
templateUrl: './oauth.component.html',
styleUrls: ['./oauth.component.scss']
})
export class OauthComponent implements OnInit {
constructor() { }
ngOnInit() {
const connection = new Strophe.Connection('http://localhost:5280/bosh');
// connection.rawInput = rawInput;
// connection.rawOutput = rawOutput;
connection.connect('user@localhost', 'password', this.onConnect);
}
onConnect(status) {
if (status == Strophe.Status.CONNECTING) {
console.log('Strophe is connecting.');
} else if (status == Strophe.Status.CONNFAIL) {
console.log('Strophe failed to connect.');
} else if (status == Strophe.Status.DISCONNECTING) {
console.log('Strophe is disconnecting.');
} else if (status == Strophe.Status.DISCONNECTED) {
console.log('Strophe is disconnected.');
} else if (status == Strophe.Status.CONNECTED) {
console.log('Strophe is connected.');
}
}
}
Approach 2:
Installed npm pkg strophejs (I was reluctant on using it, as it mentions it is depricated) using the command
npm i strophein https://www.npmjs.com/package/stropheThen in my component.ts file I am unable to import it. :(
P.S There is an error(
Exports and export assignments are not permitted in module augmentations.) shown in index.d.ts file of @types/strophe:
declare module "Strophe" {
export = Strophe;
^^^^^^
}
To Solve this issue I've referred the following:
Exports and export assignments are not permitted in module augmentations - I didn't understand how I can implement this in my scenario
Typescript error "An export assignment cannot be used in a module with other exported elements." while extending typescript definitions - Tried this but didn't work
Tried the fix given in this https://github.com/apexcharts/apexcharts.js/issues/577, but this too didn't work.
Using the Strophe npm package https://www.npmjs.com/package/strophe is deprecated, and is thus not recommended to use it. I figured out how to use the downloaded file from http://strophe.im/strophejs/
Steps are as follows:
Navigate to the downloaded folder.
Then in it run npm install This creates a dist folder in which two files and a folder is created.
Copy the
Strophe.umd.min.jsfile from the/dist/Strophe.umd.jsfolder and paste it in the /assets folder of your angular project.Add the path of this file in
angular.jsonfile.under the path mentioned by @canbax in his answer.