xmppjs / xmpp.js

XMPP for JavaScript
ISC License
2.18k stars 372 forks source link

Unable to connect to xmpp service #896

Closed abelshare closed 3 years ago

abelshare commented 3 years ago

look this

const { client, xml } = require('@xmpp/client')
const debug = require('@xmpp/debug')

export default (context, inject) => {
  const xmpp = client({
    boshURL: 'https://gogo.so:7443/http-bind/',
    username: 'lxh@gogo.so',
    password: '123456'
  })

  debug(xmpp, true)

  xmpp.on('error', (err) => {
    console.error(err)
  })

  xmpp.on('offline', () => {
    console.log('offline')
  })

  xmpp.on('stanza', async (stanza) => {
    if (stanza.is('message')) {
      await xmpp.send(xml('presence', { type: 'unavailable' }))
      await xmpp.stop()
    }
  })

  xmpp.on('online', async (address) => {
    // Makes itself available
    await xmpp.send(xml('presence'))

    // Sends a chat message to itself
    const message = xml(
      'message',
      { type: 'chat', to: address },
      xml('body', {}, 'hello world')
    )
    await xmpp.send(message)
  })

  xmpp.start().catch((err) => {
    console.error(err)
  })
}

result No compatible connection method found.

But I can connect normally with strophe.js like this

import Strophe from 'strophe.js'

const conn = new Strophe.Connection('https://gogo.so:7443/http-bind/');
conn.connect(lxh@gogo.so,  '123456', function (status) {
    if (status === Strophe.Status.CONNECTED) {
    } else if (status === Strophe.Status.DISCONNECTED) {
    }
  });

why ?? please help me

sonnyp commented 3 years ago

xmpp.js does not support the HTTP transport method.

See https://github.com/xmppjs/xmpp.js/tree/master/packages/client#transports

abelshare commented 3 years ago

thanks

sonnyp commented 3 years ago

https://github.com/xmppjs/xmpp.js/issues/561