olofd / react-native-signalr

Use SignalR with React Native
150 stars 61 forks source link

Set hubProxy to variable #27

Closed brunobraun closed 7 years ago

brunobraun commented 7 years ago

Hello,

is it possible to set a HubProxy to a variable and access its methods? For example:

conectarChat()  {
    const connection = signalr.hubConnection(url);
    connection.logging = true;

    const proxy = connection.createHubProxy('chatHub');

    this.proxy_signalr = proxy;

    // ... connection start and other stuff
}
componentDidMount() {
 this.conectarChat();

 this.proxy_signalr.on('msgRecebida', (id_enviou, id_recebeu, mensagem) => {
      //some function
 });
}

If the .on method is within conectarChat() function it works perfectly.

Thanks, Bruno

brunobraun commented 7 years ago

This works for the .invoke method: this.proxy_signalr = connection.createHubProxy('chatHub');

I changed my logic to let the .on methods access signalr proxy inside the main method and solved my problem.