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

I am trying to connect my react-native application with openfire server which is running locally in my pc but could not get connected. #112

Open
muhazzib opened this issue Jan 16, 2019 · 1 comment

Comments

@muhazzib
Copy link

muhazzib commented Jan 16, 2019

I am trying to connect my react-native application with openfire server which is running locally in my pc but could not get connected.
here is my xmpp configuration file.

import XMPP from 'react-native-xmpp';
// const DOMAIN = "192.168.100.20:5222";
const SCHEMA = "ios";

const DOMAIN = "appbakerz-18";

class XmppStore {

    constructor() {
        XMPP.on('loginError', this.onLoginError);
        XMPP.on('error', this.onError);
        XMPP.on('disconnect', this.onDisconnect);
        XMPP.on('login', this.onLogin);
        XMPP.on('message', this.onReceiveMessage);

        // XMPP.trustHosts(['192.168.100.22', '192.168.100.22', '192.168.100.22']);
        
        // default values
        this.local = 'rntestuser1';
        this.remote = 'rntestuser2';
    }

    _userForName(name) {
        return name + '@' + DOMAIN + "/" + SCHEMA;
    }

    sendMessage(message) {
        if (!this.remote || !this.remote.trim()) {
            console.error("No remote username is defined");
        }
        if (!message || !message.trim()) {
            return false;
        }
        // add to list of messages
        this.conversation.unshift({ own: true, text: message.trim() });
        // empty sent message
        this.error = null;
        // send to XMPP server
        XMPP.message(message.trim(), this._userForName(this.remote))
    }

    onReceiveMessage({ from, body }) {
        console.log("onReceiveMessage")
        // extract username from XMPP UID
        if (!from || !body) {
            return;
        }
        var name = from.match(/^([^@]*)@/)[1];
        this.conversation.unshift({ own: false, text: body });
    }

    onLoginError() {
        this.loading = false;
        this.conversation.replace([]);
        this.loginError = "Cannot authenticate, please use correct local username";
    }

    onError(message) {
        this.error = message;
    }

    onDisconnect(message) {
        this.logged = false;
        this.loginError = message;
    }

    onLogin() {
        console.log("LOGGED!");
        this.conversation.replace([]);
        this.loading = false;
        this.loginError = null;
        this.logged = true;
    }

    login({ local, remote }) {
        console.log('------')
        this.local = local;
        // this.remote = remote;
        if (!local || !local.trim()) {
            this.loginError = "Local username should not be empty";
        }
        // else if (!remote || !remote.trim()){
        //     this.loginError = "Remote username should not be empty";
        // } else if (local==remote){
        //     this.loginError = "Local username should not be the same as remote username";
        // } 
        else {
            this.loginError = null;

            // try to login to test domain with the same password as username
            try{
                console.log(this._userForName(this.local))
                XMPP.connect(this._userForName(this.local),this.local);
                console.log(XMPP.isLogged,'islog');
            }
            catch(err){
                console.log('err')
            }
            this.loading = true;
        }
    }

    disconnect() {
        XMPP.disconnect();
    }

}

export default new XmppStore();
@AkmalElahi
Copy link

Hi, did you find any solution for this?

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