0

I am new to react-native and working on a project in react-native. I integrated socket using following code.

 this.socket = socketIO.connect(global.socketUrl, {
            jsonp: false,
            reconnection: true,
            reconnectionDelay: 1000,
            reconnectionDelayMax: 5000,
            reconnectionAttempts: Infinity
        });

Further I created instance of SocketManager class in my component using below code.

Obj= new SocketManger()

This code is working fine in debug build, but we are getting the following error

TypeError: Cannot read property 'initialize' of undefined\n at new Socket

TIA

We also followed answer mention at Here but not getting any accurate result. with this code we are getting below error. enter image description here

Jyot
  • 540
  • 5
  • 17

1 Answers1

0

After doing a lot of research i found my mistake. global variables doesn't work in IOS (Release Build). The issue was because of this global variable. So i changed my code to

this.socket = socketIO.connect('url', {
            jsonp: false,
            reconnection: true,
            reconnectionDelay: 1000,
            reconnectionDelayMax: 5000,
            reconnectionAttempts: Infinity
        });

Now its working perfectly both in Android as well as IOS

Jyot
  • 540
  • 5
  • 17