Skip to content

RN + socket.io - Failed to set the 'responseType' property on 'XMLHttpRequest' #13991

@deanvaessen

Description

@deanvaessen

Description

Explain what you did, what you expected to happen, and what actually happens.

Good morning,

I am having an issue combining React Native with socket.io. I do hope I am in the right place here, but considering I am using the same code on React Native and React while only encountering issues in RN, I figured it was worth a shot. It's a bit of an odd issue, and I've tried looking online but I'm having trouble figuring this out. Other people seem to be able to work with socket.io + RN, so I'm a bit stumped.

I am trying to connect to a backend server through socket.io but it seems that as soon as I try to do this, React Native complains to me:
"Failed to set the 'responseType' property on 'XMLHttpRequest': The response type cannot be set after the request has been sent."

I am not actually creating an XMLHttpRequest myself (yet I think with React Native the socket connection might fall back to XMLHttp? I read something about this).

Additionally out of curiosity, if I have a server with socket.io running (I do), could I use React Native's own implementation of sockets to connect to it? Is this compatible?

Here is a stack trace:
Http://imgur.com/a/NKa7V

Reproduction Steps and Sample Code

Here is a snippet of what I am currently using:

/**
* { Dependencies }
*/
	var config = require('./../../../../../package.json').config;
	const PORT = config.backEndExternalPort;
	const BASECONNECTION = config.domain;

	// Vendor functions
		// Socket.IO
		import io from 'socket.io-client';
		//import io from 'socket.io-client/socket.io';
		const socket = io.connect(`${BASECONNECTION}:${PORT}`);

		import { setWhisper, setAnnouncement, connectLobby, updateSessionDetails, startGame, startRound, finishRound, finishGame } from '../../actions/actions'

/**
* { App }
*/

const index = (function() {

	const init = function(view) {

	  socket.on('connectLobby', (data) => {
	  	console.log('Lobby connected!');
	  	console.log(data);

	  	view.props.dispatch(connectLobby(data));
	  });

Additional Information

  • React Native version: "0.44.0"
  • Platform: Android
  • Development Operating System: Windows
  • Dev tools: Android Dev Studio, everything configured with versions as per the "Getting started" guide for RN.
    ( "socket.io-client": "^2.0.1" )

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions