triniwiz / nativescript-socketio

Socket.IO for nativescript
Apache License 2.0
71 stars 31 forks source link

Doesn't work with the latest socket.io server npm package (forced to downgrade) - Nativescript Vue #100

Closed saibbyweb closed 3 years ago

saibbyweb commented 3 years ago

I am using Nativescript-Vue and this plugin is unable to connect to the socket.io server created with latest npm socket.io package (^3.0.4). However, If I downgrade the server package to (^2.1.1) as present in your demo, it works.

Which platform(s) does your issue occur on?

iOS and Android Emulators

Please, provide the following version numbers that your issue occurs with:

"dependencies": {
    "@babel/plugin-proposal-decorators": "^7.12.1",
    "@nativescript/core": "~7.0.12",
    "@nativescript/firebase": "^11.0.0",
    "@nativescript/geolocation": "^7.0.0",
    "@vue/devtools": "^5.3.3",
    "axios": "^0.21.0",
    "color": "^3.1.3",
    "decode-google-map-polyline": "^1.0.1",
    "nativescript-android-utils": "^1.0.2",
    "nativescript-audio": "^6.1.0",
    "nativescript-couchbase-plugin": "^0.9.6",
    "nativescript-google-maps-sdk": "^2.9.1",
    "nativescript-permissions": "^1.3.11",
    "nativescript-socketio": "^3.3.1",
    "nativescript-toasty": "^3.0.0-alpha.2",
    "nativescript-vue": "^2.8.1",
    "nativescript-vue-devtools": "^1.4.0",
    "node-geometry-library": "^1.2.3",
    "vuex": "^3.5.1"
  },
  "devDependencies": {
    "@babel/core": "^7.11.6",
    "@babel/preset-env": "^7.11.5",
    "@nativescript/android": "7.0.0",
    "@nativescript/ios": "7.0.1",
    "@nativescript/webpack": "^3.0.4",
    "babel-loader": "^8.1.0",
    "nativescript-vue-template-compiler": "^2.8.1",
    "nativescript-worker-loader": "~0.12.1",
    "sass": "^1.26.10",
    "vue-loader": "^15.9.3"
  }

Please, tell us how to recreate the issue in as much detail as possible.

Create a socket.io server with Node and Express using the latest socket.io package:

import express from "express";
const app = express();

var http = require('http').createServer(app);
var io = require('socket.io')(http);

io.on('connection', (socket) => {
  console.log('a user connected');
});

http.listen(3001, () => {
  console.log('listening on *:3001');
});

In Nativescript-Vue:

import { SocketIO } from 'nativescript-socketio';
const server = 'http://192.168.29.72:3001';
let socketIO = new SocketIO(server, {});
socketIO.connect();

This exact code WORKS when the old (more than 3 years old) socket-io npm package is used to create the server but DOESN'T WORK when the latest socket-io npm package is used to create the server.

triniwiz commented 3 years ago

So I found Does not yet support Socket:IO v3.x, use v2.x instead! here

saibbyweb commented 3 years ago

Thank you for pointing out. Just tested on 2.3.0 (1 year old) , it's working. Will stick to that for now.

saibbyweb commented 3 years ago

@triniwiz I believe it would be great if you can put this information regarding server compatibility on the readme of this repo. It will save hours of googling for new devs.

triniwiz commented 3 years ago

Done: https://github.com/triniwiz/nativescript-socketio/commit/e11441de40f173f54ee0f89449d1b812558a7225

saibbyweb commented 3 years ago

Sorry for stretching this issue, but In my limited testing, the latest v3+ socket.io server package didn't work on iOS as well. :|

triniwiz commented 3 years ago

Updated: https://github.com/triniwiz/nativescript-socketio/commit/625cc969e940c6c4db39cc5a0939423de0266402