Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global not defined #27

Closed
zlyfer opened this issue Mar 9, 2020 · 13 comments
Closed

global not defined #27

zlyfer opened this issue Mar 9, 2020 · 13 comments

Comments

@zlyfer
Copy link

zlyfer commented Mar 9, 2020

Hello, I tried to get ngx-chat to work using Ionic 5 & Angular 8 but after importing like described in the README I get following error:
Uncaught ReferenceError: global is not defined (index.js:43) at Object../node_modules/buffer/index.js (index.js:43) at __webpack_require__ (bootstrap:84) at Object../node_modules/safe-buffer/index.js (index.js:2) at __webpack_require__ (bootstrap:84) at Object../node_modules/hash-base/index.js (index.js:2) at __webpack_require__ (bootstrap:84) at Object../node_modules/md5.js/index.js (index.js:3) at __webpack_require__ (bootstrap:84) at Object../node_modules/create-hash/browser.js (browser.js:3) at __webpack_require__ (bootstrap:84)
I am working on a mobile app, which is why I use Ionic. Can someone help me resolve this issue?
Angular CLI; 9.0.2
Node: 10.16.3
OS: Windows x64 (Deploying on Android)
Angular: ~8.1.2
Ionic Angular: ^4.11.10

@trampi
Copy link
Contributor

trampi commented Mar 9, 2020

Hi!
You probably forgot to add global to window in the polyfills.ts.
See the "Installation and usage" section in the readme

/***************************************************************************************************
 * APPLICATION IMPORTS
 */
(window as any).global = window;

We aren't officially supporting Ionic. Feel free to reopen the issue if this does not solve your issue.

@trampi trampi closed this as completed Mar 9, 2020
@zlyfer
Copy link
Author

zlyfer commented Mar 9, 2020

Hey,
Wow thanks for the quick reply. I added the line and the same error didn't show up again.
However now I get following error:

util.js:103 Uncaught ReferenceError: Buffer is not defined
    at Object../node_modules/core-util-is/lib/util.js (util.js:103)
    at __webpack_require__ (bootstrap:84)
    at Object../node_modules/readable-stream/lib/_stream_readable.js (_stream_readable.js:67)
    at __webpack_require__ (bootstrap:84)
    at Object../node_modules/readable-stream/readable-browser.js (readable-browser.js:1)
    at __webpack_require__ (bootstrap:84)
    at Object../node_modules/stream-browserify/index.js (index.js:28)
    at __webpack_require__ (bootstrap:84)
    at Object../node_modules/hash-base/index.js (index.js:3)
    at __webpack_require__ (bootstrap:84)

Not sure if this is error shows up because of Ionic or if this is a NYPA situation; I am not extremely experienced in XMPP.

@trampi
Copy link
Contributor

trampi commented Mar 9, 2020

I've reopened the issue and will take a look at using ngx-chat in ionic tomorrow.

@trampi trampi reopened this Mar 9, 2020
@trampi
Copy link
Contributor

trampi commented Mar 10, 2020

@zlyfer
Could reproduce your issue, it is solved by using @xmpp/client@0.9.x.
Install it via

npm install --save @xmpp/client@~0.9.0

in your root directory.
You should also install @angular/animations for your angular version if you haven't yet.

@zlyfer
Copy link
Author

zlyfer commented Mar 11, 2020

Thank you this worked like a charm!
However there are a couple of things that I don't get yet:

  1. The XMPP Server I want to connect is OpenFire and for the login I tried "wss://jabber.MYDOMAIN.de/7443" as service with domain being "MYDOMAIN.de" and it kept reconnecting because of connection refused. Now I am using "wss://jabber.MYDOMAIN.de/5223" as service and "MYDOMAIN.de" as domain and it doesn't reconnect because of connection refused - instead of that the last message is just:
    ChatService: status update = connecting 'wss://jabber.MYDOMAIN.de:5223'
    I don't know if that means that I am logged in already.
  2. I use the tag <ngx-chat></ngx-chat> in a seperate page which then just shows an empty space (with a generic template text) and when I try to swipe from right to left I get following error:
Uncaught TypeError: Failed to set the 'currentTime' property on 'Animation': The provided double value is non-finite.
    at animation-af478fe9.js:578
    at Array.forEach (<anonymous>)
    at setAnimationStep (animation-af478fe9.js:577)
    at Object.progressEnd (animation-af478fe9.js:677)
    at animation-af478fe9.js:666
    at Array.forEach (<anonymous>)
    at Object.progressEnd (animation-af478fe9.js:665)
    at Menu.onEnd (ion-menu_4-md.entry.js:320)
    at onEnd (ion-menu_4-md.entry.js:112)
    at pointerUp (index-624eea58.js:530

I have NoopAnimationsModule in app.module but import NgxChatModule in the seperate chat.module and I also tried BrowserAnimationsModule which didn't fix the error.

I also don't know if this still on topic of the issue and apologize if it's not.

Edit: I also get the warning:
ChatService: username should not contain domain, only local part, this can lead to errors!
but the provided username doesn'T contain the domain.

@trampi trampi added awaiting feedback Waiting for feedback from the issue creator and removed awaiting feedback Waiting for feedback from the issue creator labels Mar 11, 2020
@trampi
Copy link
Contributor

trampi commented Mar 11, 2020

Hi zlyfer, no need to apologize, everythings fine 😄

  1. The XMPP Server I want to connect is OpenFire

ngx-chat is at this moment not compatible with OpenFire, see #16.
However, it should not be much work and I am working on this right now, will get back on you later.

  1. I use the tag in a seperate page which then just shows an empty space (with a generic template text) and when I try to swipe from right to left I get following error:

Please include ngx-chat in your app module like this:

imports: [
// ...
    NgxChatModule.forRoot()
// ...
]

Would it be possible to provide a screenshot? The stack trace looks ionic specific, but I am not quite sure.

  1. ChatService: username should not contain domain, only local part, this can lead to errors!

When calling login() you should just pass the local part, e.g. like this:

chatService.logIn({
            domain: 'example.com',
            service: 'wss://jabber.example.com:5280/websocket',
            password: 'password',
            username: 'zlyfer', // not zlyfer@example.com
});

Will get back on you later.

@zlyfer
Copy link
Author

zlyfer commented Mar 11, 2020

@trampi
Here is a screenshot of both error messages:
image
Indeed, seems like it has nothing to do with ngx-chat.

ngx-chat is at this moment not compatible with OpenFire, see #16.
However, it should not be much work and I am working on this right now, will get back on you later.

Well OpenFire is my only option.

When calling login() you should just pass the local part, e.g. like this:

chatService.logIn({
            domain: 'example.com',
            service: 'wss://jabber.example.com:5280/websocket',
            password: 'password',
            username: 'zlyfer', // not zlyfer@example.com
});

The username I use is not even similar to the domain nor service. Maybe that's a bug?

Thanks for the help so far.

@trampi
Copy link
Contributor

trampi commented Mar 11, 2020

@zlyfer

Well OpenFire is my only option.

No problem, I am pretty confident that this will work really soon.

The username I use is not even similar to the domain nor service. Maybe that's a bug?

Indeed. If your username does not contain '@' this can be ignored. Fixed the condition for the next release.

@zlyfer
Copy link
Author

zlyfer commented Mar 11, 2020

@trampi
I see, thank you for your efforts. Unfortunately I have to use a different solution which is not made for Angular in order to progress with the project but I would be glad to switch to ngx-chat again when OpenFire is supported.
Thank you, again.

@trampi
Copy link
Contributor

trampi commented Mar 11, 2020

Got the fix locally working, will test it out tomorrow morning and release it if everything works :-)

@trampi
Copy link
Contributor

trampi commented Mar 12, 2020

We've release 0.9.0 (which requires angular 9). It should be possible to backport the fixes to the angular 8 version of ngx-chat. Reopen this issue if you need it.

All the best!
trampi

@trampi trampi closed this as completed Mar 12, 2020
@zlyfer
Copy link
Author

zlyfer commented Mar 13, 2020

Hey,
So I updated to Angular 9 and ngx-chat 0.9.0 and it compiled successfully. However after a period of time trying to connect the handshake failes and it tries again.

pazznetwork-ngx-chat.js:2137:
ChatService: state changed to: disconnected
pazznetwork-ngx-chat.js:2137:
ChatService: status update = connecting "wss://example.com:5223"

Socket.js:17:
WebSocket connection to 'wss://example.com:5223/' failed: WebSocket opening handshake timed out
pazznetwork-ngx-chat.js:2127:
ChatService: chat service error => Error: WebSocket ECONNERROR wss://example.com:5223 Error: WebSocket ECONNERROR wss://example.com:5223
    at WebSocket.listeners.error (Socket.js:33)
    at ZoneDelegate.invokeTask (zone-evergreen.js:400)
    at Zone.runTask (zone-evergreen.js:168)
    at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:481)
    at invokeTask (zone-evergreen.js:1596)
    at WebSocket.globalZoneAwareCallback (zone-evergreen.js:1622)

core.js:5882:
ERROR Error: Uncaught (in promise): Error: WebSocket ECONNERROR wss://example.com:5223
Error: WebSocket ECONNERROR wss://example.com:5223
    at WebSocket.listeners.error (Socket.js:33)
    at ZoneDelegate.invokeTask (zone-evergreen.js:400)
    at Zone.runTask (zone-evergreen.js:168)
    at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:481)
    at invokeTask (zone-evergreen.js:1596)
    at WebSocket.globalZoneAwareCallback (zone-evergreen.js:1622)
    at resolvePromise (zone-evergreen.js:793)
    at zone-evergreen.js:707
    at rejected (tslib.es6.js:72)
    at ZoneDelegate.invoke (zone-evergreen.js:365)
    at Object.onInvoke (core.js:41277)
    at ZoneDelegate.invoke (zone-evergreen.js:364)
    at Zone.run (zone-evergreen.js:124)
    at zone-evergreen.js:851
    at ZoneDelegate.invokeTask (zone-evergreen.js:400)
    at Object.onInvokeTask (core.js:41255)

pazznetwork-ngx-chat.js:2137:
ChatService: status update = disconnect {"clean":false,"event":{"isTrusted":true}}
pazznetwork-ngx-chat.js:2137:
ChatService: state changed to: disconnected

(Original domain name replaced with example.com)
I am still investigating if this a problem on my side.

@trampi
Copy link
Contributor

trampi commented Mar 16, 2020

Strange. You could try to use https://pazznetwork.github.io/ngx-chat-ghpages/ for diagnosis, open the network packet inspector and check the traffic.
If the websocket can really not be established (as the error implies), then you are probably using the wrong service endpoint, probably the one for BOSH.

For the openfire default configuration you can try:

wss://example.com:7443/ws/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants