MobileChromeApps / cordova-plugin-chrome-apps-sockets-udp

BSD 3-Clause "New" or "Revised" License
80 stars 40 forks source link

iOS 14 UDP Sockets not working correctly #31

Closed jricardo1 closed 3 years ago

jricardo1 commented 3 years ago

I currently use this Cordova plugin with Ionic V4. After the release of iOS 14 there is a glitchy behavior where the plugin does not always work. I have learned that turning WIFI on and off will sometimes cause the plugin to start receiving data once again. I feel this is an iOS14 issue but I need to try to fix. I would like to know if there is anything I can do to solve this issue from the plugin point of view. I also have a reconnect mechanism where I will leave and close the socket in order to rejoin and this as well is not working correctly in iOS 14.

Versions

Cordova Version: 10.0.0 cordova-plugin-chrome-apps-common: 1.0.7 cordova-plugin-chrome-apps-iossocketscommon: 1.0.2 cordova-plugin-chrome-apps-sockets-udp: 1.3.0 Ionic Cli: 6.1.1

Source code


console.log('trying to create udp socket.');        
chrome.sockets.udp.create({}, function (socketInfo) {
            this.socketId = socketInfo.socketId;

            // this.socketId = this.socketId;
            console.log(this.socketId + ' bindip: ' + this.bindip + ' groupPort: ' + this.groupPort + ' groupIp: ' + this.groupIp);

            // Currently the discovery module use '239.0.0.123:55558' for multicast
            chrome.sockets.udp.bind(Number(this.socketId), String(this.bindip), parseInt(String(this.groupPort), 10), function (result) {
                console.log('Bind IF returns ' + result);
                if (result >= 0) {
                    console.log('Joining Group');
                    chrome.sockets.udp.joinGroup(this.socketId, this.groupIp, function (result1) {
                        console.log('Joining Group returns ' + result1);
                        if (result1 >= 0) {

                            chrome.sockets.udp.setMulticastLoopbackMode(this.socketId, true, function (result2) {
                                console.log('Loopback returns ' + result2);

                            }.bind(this));
                            chrome.sockets.udp.getInfo(this.socketId, function (info) {
                                console.log('Socket Info: paused ? ' + info.paused);
                                console.log('Socket Info: localAddress ' + info.localAddress);
                                console.log('Socket Info: localPort ' + info.localPort);

                            });
                            chrome.sockets.udp.getSockets(function (infoarr) {
                                infoarr.forEach(function (info) {
                                    console.log('Socket Info: Id ' + info.socketId);
                                    console.log('Socket Info: paused ? ' + info.paused);
                                    console.log('Socket Info: Persistense ? ' + info.persistent);
                                    console.log('Socket Info: localAddress ' + info.localAddress);
                                    console.log('Socket Info: localPort ' + info.localPort);
                                });
                            });
                            console.log('Setup OnReceive Listener');
                            chrome.sockets.udp.onReceive.addListener(this.receiveIncomingMulticastListener.bind(this));
                            console.log('Setup OnReceiveError Listener');
                            chrome.sockets.udp.onReceiveError.addListener(this.receiveErrorListener.bind(this));

                            // hold the events till 'start' is called
                            if (!doRecv) {
                                chrome.sockets.udp.setPaused(this.socketId, true);
                            } else {
                                this.start();
                            }
                        }
                    }.bind(this));
                }
            }.bind(this));
        }.bind(this));

XCODE Output:

2020-10-12 15:51:44.008119-0400 OEI[417:12700] trying to create udp socket.
2020-10-12 15:51:44.012282-0400 OEI[417:12700] 0 bindip: 0.0.0.0 groupPort: 55558 groupIp: 239.0.0.123
2020-10-12 15:51:44.015802-0400 OEI[417:12700] Bind IF returns 0
2020-10-12 15:51:44.016178-0400 OEI[417:12700] Joining Group
2020-10-12 15:51:44.028471-0400 OEI[417:12700] Joining Group returns 0
2020-10-12 15:51:44.032259-0400 OEI[417:12700] Setup OnReceive Listener
2020-10-12 15:51:44.033012-0400 OEI[417:12700] Setup OnReceiveError Listener
2020-10-12 15:51:44.039017-0400 OEI[417:12700] Loopback returns 0
2020-10-12 15:51:44.040270-0400 OEI[417:12700] Socket Info: paused ? false
2020-10-12 15:51:44.040992-0400 OEI[417:12700] Socket Info: localAddress 0.0.0.0
2020-10-12 15:51:44.041656-0400 OEI[417:12700] Socket Info: localPort 55558
2020-10-12 15:51:44.042574-0400 OEI[417:12700] Socket Info: Id 0
2020-10-12 15:51:44.043082-0400 OEI[417:12700] Socket Info: paused ? false
2020-10-12 15:51:44.043643-0400 OEI[417:12700] Socket Info: Persistense ? false
2020-10-12 15:51:44.044149-0400 OEI[417:12700] Socket Info: localAddress 0.0.0.0
2020-10-12 15:51:44.044695-0400 OEI[417:12700] Socket Info: localPort 55558