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

Change url in component #66

Open
NickHatBoecker opened this issue Jun 7, 2018 · 2 comments
Open

Change url in component #66

NickHatBoecker opened this issue Jun 7, 2018 · 2 comments

Comments

@NickHatBoecker
Copy link

NickHatBoecker commented Jun 7, 2018

Hey guys,

I want to implement a client application where a user can provide a server url.
So the socket url needs to be dynamically set.

At the moment I have to hardcode the url to app.module.ts:

import { SocketIoModule, SocketIoConfig } from 'ng-socket-io';
const config: SocketIoConfig = { url: 'http://xxx.xxx.x.x:PORT' };

but I need something like this (serverUrl is an input in home.html. connectToServer() is called on a button click):

export class HomePage {
    serverUrl: '';

    constructor(public navCtrl: NavController, private socket: Socket) {}

    connectToServer() {
        this.socket.connect(this.serverUrl);

        if (this.socket.ioSocket.connected) {
            this.navCtrl.push('DeckPage');
        }
    }
}

Can you guys provide any help?
Thanks in Advance!

Best regards
Nick

@pierresh
Copy link

Hello,

I also need to make the URL configurable, have you found a solution for this situation?

@zubinraja
Copy link

@Injectable()
export class Socket_Test extends Socket {

constructor() {
    super({ url: '<SOCKET_URL>', options: {"rememberUpgrade":true,
                                                "transports":["websocket","polling"],
                                                "secure":true,"rejectUnauthorized":true,
                                                "autoConnect":false,
                                                "query":"token=<TOKEN VALUE>"
                                              } });

    
}

init(token){
  this.ioSocket.query = {token:token};
}

}

call function
this.socket.init();
this.socket.connect();

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

3 participants