Feathers: My feathersjs client is working on ios but not working on android using react native

Created on 9 Jun 2019  路  5Comments  路  Source: feathersjs/feathers

it is showing timeout acceded 5000ms in android but working fine on ios in react native

my config file for react native

````import AsyncStorage from '@react-native-community/async-storage';
const io = require('socket.io-client');
const feathers = require('@feathersjs/feathers');
const socketio = require('@feathersjs/socketio-client');
const auth = require('@feathersjs/authentication-client');

const apiUrl = 'http://localhost:3030';

const client = feathers();

const socket = io(apiUrl, {
transports: ['websocket'],
forceNew: true
});

options = {
header: 'Authorization', // the default authorization header for REST
prefix: '', // if set will add a prefix to the header value. for example if prefix was 'JWT' then the header would be 'Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOi...'
path: '/authentication', // the server-side authentication service path
jwtStrategy: 'jwt', // the name of the JWT authentication strategy
entity: 'user', // the entity you are authenticating (ie. a users)
service: 'users', // the service to look up the entity
cookie: 'feathers-jwt', // the name of the cookie to parse the JWT from when cookies are enabled server side
storageKey: 'feathers-jwt', // the key to store the accessToken in localstorage or AsyncStorage on React Native
storage: AsyncStorage // Passing a WebStorage-compatible object to enable automatic storage on the client.
}

client.configure(auth(options))
client.configure(socketio(socket));

export default client;```

Most helpful comment

You can't use localhost. In Android you have to use the external server ip address that the emulator can reach.

All 5 comments

@daffl are you there? I need Help!! @daffl

For android i also have tried this...

```const io = require('socket.io-client');
const feathers = require('@feathersjs/feathers');
const socketio = require('@feathersjs/socketio-client');
const auth = require('@feathersjs/authentication-client');

const apiUrl = 'http://localhost:3030';

const client = feathers();

const socket = io(apiUrl, {
pingInterval: 10000,
pingTimeout: 50000,
transports: ['websocket'],
forceNew: true
});

options = {
header: 'Authorization', // the default authorization header for REST
prefix: '', // if set will add a prefix to the header value. for example if prefix was 'JWT' then the header would be 'Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOi...'
path: '/authentication', // the server-side authentication service path
jwtStrategy: 'jwt', // the name of the JWT authentication strategy
entity: 'user', // the entity you are authenticating (ie. a users)
service: 'users', // the service to look up the entity
cookie: 'feathers-jwt', // the name of the cookie to parse the JWT from when cookies are enabled server side
storageKey: 'feathers-jwt', // the key to store the accessToken in localstorage or AsyncStorage on React Native
storage: AsyncStorage // Passing a WebStorage-compatible object to enable automatic storage on the client.
}

client.configure(auth(options))
client.configure(socketio(socket));

export default client;

You can't use localhost. In Android you have to use the external server ip address that the emulator can reach.

@daffl is there anything that can i use to test on emulator?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jordanbtucker picture jordanbtucker  路  4Comments

arkenstan picture arkenstan  路  3Comments

perminder-klair picture perminder-klair  路  3Comments

rstegg picture rstegg  路  3Comments

Vincz picture Vincz  路  4Comments