vukoye / xmpp_dart

Lightweight XMPP client library written in Dart
Apache License 2.0
83 stars 64 forks source link

Add Web-platform support; #65

Closed TatankaConCube closed 2 years ago

TatankaConCube commented 2 years ago

@vukoye could you please review the PR and merge it to the dev branch and publish it as a new dev version to the pub.dev repository. I tried to save old logic but added some separated logic for working with WEB. I checked my changes on Android, iOS, macOS, and Web, and everywhere it works well.

eldhomt commented 2 years ago

I tried with the merged commit on Web and it is throwing the following error:

[log] <?xml version='1.0'?>
      <stream:stream xmlns='jabber…r.org/streams'
      to='10.1.100.148'
      xml:lang='en'
      >
[log] D/[Connection]: Handle connection done
[log] D/[Connection]: State: XmppConnectionState.ForcefullyClosed
[log] D/[ReconnectionManager]: Connection forcefully closed!
Error: WebSocketChannelException: WebSocket connection failed.
    at Object.createErrorWithStack (http://localhost:50310/dart_sdk.js:5388:12)
    at Object._rethrow (http://localhost:50310/dart_sdk.js:40987:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:50310/dart_sdk.js:40981:13)
    at Object._microtaskLoop (http://localhost:50310/dart_sdk.js:40808:13)
    at _startMicrotaskLoop (http://localhost:50310/dart_sdk.js:40814:13)
    at http://localhost:50310/dart_sdk.js:36279:9

It is working fine in Android, iOS, Windows and MacOS.

TatankaConCube commented 2 years ago

@eldhomt which port do you use for WebSocket connection, by default this lib uses 5222, but for web, we use a separated port, in our case, it is 5291

eldhomt commented 2 years ago

@TatankaConCube I tried with 5222 and 7070. But both the ports throws the same error. xmpp.XmppAccountSettings(userAtDomain, jid.local, jid.domain, password, 5222, resource: 'MyApp');

Note: I am using Openfire server.

eldhomt commented 2 years ago

@TatankaConCube After further debugging I could find that the library is taking only the default port 5222 even if you provide a separate port. [ Note: I tested a different port with React Native and React, which is working fine. I tried the same port with flutter and its not even working in mobile.]

TatankaConCube commented 2 years ago

@eldhomt how do you set a separate port? in our project we set via:

xmpp.XmppAccountSettings account = xmpp.XmppAccountSettings(userJid, jid.local, jid.domain, cubeUser.password!, kIsWeb ? 5291 : 5222, resource: resource);

_connection = xmpp.Connection.getInstance(account);

and it works well for us

eldhomt commented 2 years ago

@TatankaConCube I am using the same implementation as above. But it doesn't work.

[log] D/[Connection]: State: XmppConnectionState.SocketOpening
[XmppWebSocketHtml][connect] host: 10.1.100.148, port: 7070
[log] D/[Connection]: State: XmppConnectionState.SocketOpened
[log] ---Xmpp Sending:---
[log] <?xml version='1.0'?>
      <stream:stream xmlns='jabber…r.org/streams'
      to='10.1.100.148'
      xml:lang='en'
      >
[log] D/[Connection]: Handle connection done
[log] D/[Connection]: State: XmppConnectionState.ForcefullyClosed
[log] D/[ReconnectionManager]: Connection forcefully closed!
[log] D/[ReconnectionManager]: TimeOut is: 2000 reconnection counter 0
Error: WebSocketChannelException: WebSocket connection failed.
    at Object.createErrorWithStack (http://localhost:57012/dart_sdk.js:5388:12)
    at Object._rethrow (http://localhost:57012/dart_sdk.js:40987:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:57012/dart_sdk.js:40981:13)
    at Object._microtaskLoop (http://localhost:57012/dart_sdk.js:40808:13)
    at _startMicrotaskLoop (http://localhost:57012/dart_sdk.js:40814:13)
    at http://localhost:57012/dart_sdk.js:36279:9
Restarted application in 34,533ms.
Pushkar952 commented 2 years ago

@TatankaConCube getting the same error as mentioned by @eldhomt . Any work around yet?

eldhomt commented 2 years ago

No work around yet.