Connect Android to Nodejs - android

I am trying to connect nodejs backend and android frontend. I use nodejs to write api with port 3000 and I use android to call the server side api but it always fails to connect to the server, what should I do now. Help me please!!!!!!
This is Client(Android)
package com.hieunguyen.souq.utils;
public class Constant {
public static String LOCALHOST = "http://localhost:3000/";
public static String PRODUCT = "product";
public static String ORDER = "order";
public static final int PICK_IMAGE = 88;
public static final int GALLERY_REQUEST = 100;
public static final int READ_EXTERNAL_STORAGE_CODE = 200;
public static final int CAMERA_REQUEST = 300;
public static final int CAMERA_PERMISSION_CODE = 400;
public static String PRODUCT_ID = "ProductId";
public static String CATEGORY = "Category";
public static String EMAIL = "email";
public static String OTP = "otp";
public static String PRODUCTID = "Product_id";
public static String KEYWORD = "keyword";
}
This is Server(Nodejs)
const express = require('express')
const bodyParser = require('body-parser')
require('dotenv').config();
const app = express()
app.use('/storage_user', express.static('storage_user'));
app.use('/storage_product', express.static('storage_product'));
app.use('/storage_poster', express.static('storage_poster'));
const userRouter = require('./api/routes/users')
const productRouter = require('./api/routes/products')
const favoriteRouter = require('./api/routes/favorites')
const cartRouter = require('./api/routes/carts')
const historyRouter = require('./api/routes/history')
const reviewRouter = require('./api/routes/review')
const posterRouter = require('./api/routes/posters')
const addressRouter = require('./api/routes/address')
const orderRouter = require('./api/routes/orders')
const port = 3000
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use('/users', userRouter)
app.use('/products', productRouter)
app.use('/favorites', favoriteRouter)
app.use('/carts', cartRouter)
app.use('/history', historyRouter)
app.use('/review', reviewRouter)
app.use('/posters', posterRouter)
app.use('/address', addressRouter)
app.use('/orders', orderRouter)
app.listen(port, () => console.log("Server đã khởi động!"))
When I run server and test on postman is ok(Localhost:3000/)
But when I run on client it's always error failed to connect to localhost:3000/ in server :((((. I don't know how to fix that!!!!. Please help me!!!! Sorry my English not good

There are 2 things I think may have occurred.
First of all, localhost is currently running on your local computer, you need to config port forwarding on your router in order to be accessible in your local network.
Secondly, you may want to enable CORS because your front end and back end is not hosting on the same domain.

Related

What are some examples of MediaController commands?

Checking out the MediaController documentation, I noticed that there is a function called sendCommand(...), which requires three parameters:
command: String;
args: Bundle;
cb: ResultReceiver.
But examples of how to use that method are nowhere to be found.
What are the available MediaController#sendCommand(...) default commands and acceptable argument keys and values types?
For example, checking PlaybackState documentation, we can find a constant called ACTION_PLAY_FROM_MEDIA_ID which description is as follows:
Indicates this session supports the play from media id command
This leads us to think that MediaController#sendCommand(...) is able to change a MediaSession's current media by sending it the media ID. How can we do it?
It's known that Google Play Music App's MediaController shares its Media Queue through MediaController#getQueue function.
You can find Commands constants in MediaControllerCompat.
They actually are:
public static final String COMMAND_GET_EXTRA_BINDER =
"android.support.v4.media.session.command.GET_EXTRA_BINDER";
public static final String COMMAND_ADD_QUEUE_ITEM =
"android.support.v4.media.session.command.ADD_QUEUE_ITEM";
public static final String COMMAND_ADD_QUEUE_ITEM_AT =
"android.support.v4.media.session.command.ADD_QUEUE_ITEM_AT";
public static final String COMMAND_REMOVE_QUEUE_ITEM =
"android.support.v4.media.session.command.REMOVE_QUEUE_ITEM";
public static final String COMMAND_REMOVE_QUEUE_ITEM_AT =
"android.support.v4.media.session.command.REMOVE_QUEUE_ITEM_AT";
public static final String COMMAND_ARGUMENT_MEDIA_DESCRIPTION =
"android.support.v4.media.session.command.ARGUMENT_MEDIA_DESCRIPTION";
public static final String COMMAND_ARGUMENT_INDEX =
"android.support.v4.media.session.command.ARGUMENT_INDEX";
For some basic usage samples u can check out its methods, like:
#Override
public void removeQueueItem(MediaDescriptionCompat description) {
long flags = getFlags();
if ((flags & MediaSessionCompat.FLAG_HANDLES_QUEUE_COMMANDS) == 0) {
throw new UnsupportedOperationException(
"This session doesn't support queue management operations");
}
Bundle params = new Bundle();
params.putParcelable(COMMAND_ARGUMENT_MEDIA_DESCRIPTION, description);
sendCommand(COMMAND_REMOVE_QUEUE_ITEM, params, null);
}

Android WebRTC - create 1-N calls

I have a project https://github.com/njovy/AppRTCDemo. This project works 1 -1 calls. I modified the PeerConnectionClient.class:
private static final PeerConnectionClient instance = new PeerConnectionClient();
// private final PCObserver pcObserver = new PCObserver();
private final PCObserver[] pcObservers = new PCObserver[MAX_CONNECTIONS];
// private final SDPObserver sdpObserver = new SDPObserver();
private final SDPObserver[] sdpObservers = new SDPObserver[MAX_CONNECTIONS];
private final LooperExecutor executor;
private static final int MAX_CONNECTIONS = 3;
private PeerConnectionFactory factory;
private PeerConnection[] peerConnections = new PeerConnection[MAX_CONNECTIONS];
PeerConnectionFactory.Options options = null;
private VideoSource videoSource;
private boolean videoCallEnabled;
private boolean audioCallEnabled;
private boolean preferIsac;
private boolean preferH264;
private boolean videoSourceStopped;
private boolean isError;
private Timer statsTimer;
private VideoRenderer.Callbacks localRender;
private VideoRenderer.Callbacks[] remoteRenders;
private SignalingParameters signalingParameters;
private MediaConstraints pcConstraints;
private MediaConstraints videoConstraints;
private MediaConstraints audioConstraints;
private MediaConstraints sdpMediaConstraints;
private PeerConnectionParameters peerConnectionParameters;
// Queued remote ICE candidates are consumed only after both local and
// remote descriptions are set. Similarly local ICE candidates are sent to
// remote peer after both local and remote description are set.
private LinkedList<IceCandidate>[] queuedRemoteCandidateLists = new LinkedList[MAX_CONNECTIONS];
private PeerConnectionEvents events;
private boolean[] isConnectionInitiator = new boolean[MAX_CONNECTIONS];
private SessionDescription[] localSdps = new SessionDescription[MAX_CONNECTIONS]; // either offer or answer SDP
private MediaStream mediaStream;
private int numberOfCameras;
private VideoCapturerAndroid videoCapturer;
// enableVideo is set to true if video should be rendered and sent.
private boolean renderVideo;
private VideoTrack localVideoTrack;
private VideoTrack[] remoteVideoTracks = new VideoTrack[MAX_CONNECTIONS];
as here https://pastebin.com/c0YCHS6g. My Activity for call: https://pastebin.com/8RVwVZRq
Android WebRTC - create 1-N calls, what is the value of N here?
If N > 4 you need to use a media relay servers(SFU/SVC) servers, otherwise mobile will die !!
For N remote participants, WebRTC will do N times encoding (it will eat CPU & battery N times) and to relay stream to N participants it will consume N times bandwidth (you can't imagine it in 3G/4G).
Choose a media server based on your use case from Janus/Jitsi/Kurento/Licode/red5/switchrtc/wowza and many more.
If N <= 4:
you need to refactor peerConnectionClinet into two parts.
1. Singleton Factory: Main peerConnectionFactory & MediaStream/MediaTracks
2. PC Instances: create a peerConnection from the Singleton Factory and add the same stream to all the instances. This pc instance is responsible for offer/answer/candidates exchange for each endpoint.

quickblox android sdk unauthorized error

I download the chat sample from quickblox and follow all the steps at http://quickblox.com/developers/5_Mins_Guide iam geting unauthorized error
i spending days for it for simple open groupchat feature in my app
please could some one help me.
splashActivity.java is
private static final String APP_ID = <my id>;
private static final String AUTH_KEY = <auth key>;
private static final String AUTH_SECRET = <secret key>;
//
private static final String USER_LOGIN = "vamsi";
private static final String USER_PASSWORD = "******";
You need to go to the QuickBlox Admin Panel, go to the users section and add a new user with the credentials that you will be using first.

How to apply to a standard audio player?

I need to be when you press the buttons in the usual android I could switch to music in my standard audio player for android while the music is playing. How can you interact with a standard audio player for android?
Music player is not standard thing on Android and vendors can come with different app than others (i.e. Sony is good exapmple). Controlling media app can be doable but final effect depends on what app is really installed (and used, as user can have more than one). You may be able to control some, but other may remain immune to your attempts. You can try this code - will work for Google Music for example):
public static final String SERVICECMD = "com.android.music.musicservicecommand";
public static final String CMDNAME = "command";
public static final String CMDSTOP = "stop";
AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
if(mAudioManager.isMusicActive()) {
Intent i = new Intent(SERVICECMD);
i.putExtra(CMDNAME , CMDSTOP );
YourApplicationClass.this.sendBroadcast(i);
}
other commands are
public static final String CMDTOGGLEPAUSE = "togglepause";
public static final String CMDPAUSE = "pause";
public static final String CMDPREVIOUS = "previous";
public static final String CMDNEXT = "next";
Commands are taken from android/music/MediaPlaybackService.java

How to connect an Android Chat Application to Openfire server

I am trying to connect an Android chat app in Eclipse to my own Openfire server. The code I am using is from the Samsung developers site (http://developer.samsung.com/android/technical-docs/Building-a-Chat-Application) and I am having difficulty in connecting the app to my server.
The problem comes from declaring the connections:
public static final String HOST = "talk.google.com";
public static final int PORT = 5222;
public static final String SERVICE = "gmail.com";
public static final String USERNAME = "userid#gmail.com";
public static final String PASSWORD = "password";
This is the example provided by the site, but I am unsure of what the fields should contain if I am using my own openfire server, as opposed to the example above. If someone could give an example of what I should do to connect to my own server, I would really appreciate it.
Thank you for your time.

Categories

Resources