React Native bridge: send data continuously from native to JS? - react-native

I have read a bunch of resources online but didn't see any similar use case. I need to send data from native (Android) to JS continuously, with the data being small sized string.
Would this (from RN tutorial)
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(eventName, data)
be the best way to do it? What if we need the message to be sent very frequently? Like every 100ms? Is there any other way to do it with better performance? How frequent can it go?
Thank you!

In react-native your javascript app is running on a different thread than you native application. I don't thinks there is a better way for sending data between the two threads than EventEmitter.
In the source code of libraries sending data frequently, EventEmitter is always used (example: react-native-sensors).

Related

Background event in react native application

I was wondering if there’s anything that could trigger an event in the background in react-native.
I’ve created my project with CRNA(I cannot use native code until I detach from expo and thus cannot have the android or ios folders.)
In my case, I need the data to be sent to firestore database at a particular time.
can anyone help me with this?
thanks in advance
You would need a native module to do this as expo does not support background events at this time.
Could your requirements be solved with a server function? Or do you need to send data on the device, such as latitude/longitude? The only alternative I can think of is sending the data ahead of time to a server and then have that server send the message to firestore at a particular time.
Could use a bit more information, but this is possible if use redux with redux saga, and dispatch an action from your container component whenever you need to set the data on firestore. Your saga should handle the setting of the data.

Background task for reading accelerometer data

I have a React Native application and I am reading accelerometer data each 20ms using the react-native-sensor-manager package.
I start the listener and log it into Reactotron each time it reads data, each 20ms
SensorManager.startAccelerometer(20)
DeviceEventEmitter.addListener('Accelerometer', function (data) {
console.tron.warn(data)
})
It works well if I leave the application in foreground, and even in background, but if I lock the phone it stops reading data. It also stops if I kill the app from the task manager.
How can I achieve to read data even in background?
You would have to tap into creating background processes in order to do anything of that nature.
react-native-background-task is probably the easiest way to do that...however, you will not be able to get updated data at such a fast pace as there are numerous limitations, for obvious reasons, to using background tasks.

Prevent MobileFirst Platform from presenting adapter response in Native iOS App

Overtime I request something from an Adapter of MobileFirst Platform 7, I see the response on the log window on a Native iOS App.
This is consuming memory, blocking the execution of the App and annoying me :)
Is there any way yo block this ? If I want to see the response, I can use NSLog.
Thanks.
AFAIK the ability to not display responses does not exists.
Feel free to submit feature requests, though...
Besides, is it really the display of the data and not the fact that you return probably a lot of data, thus it takes it longer to arrive before it finally gets printed?

Wcf sent notification to website

I am using .net4. I have created a web app which is doing polling every 30sec.
I have a wcf service which writes to database the desired data which comming from android clients.
The polling that the web site do every 30sec is based upon data from android.
As optimization instead of polling i was thinking something like "google cloud messaging". I mead that the ideal implementation should be :
Android push data to my db.
Instantly when data inserted ok to my db, send "something" in order website ask database
for data
My app is finished, is working with out problems so far.
The question:
Is there any way to implement the ideal implementation above?
I have tried singalr and comet. But i have not find something that i could implement in my situation.
I will appreciate any help.
Finally i have found solution to my problem. I follow this example.
I used SingalR (which is great lib).

How to implement a timer in a XPCOM component?

I'm creating a GStreamer application based on XULRunner. To achieve this created an XPCOM component that makes some of the GStreamer functionality available in a XUL application. However, GStreamer normally makes use of a message loop (GMainLoop) which enables one to receive bus messages. Because XULRunner already has its own message loop I can't create a GMainLoop. So I need another way of getting those messages. One way is to use the gst_bus_poll call. I would need to call it frequently to prevent the message queue from being flooded. So I'm thinking that a timer is the correct solution here.
To make a long story short: how do I create a timer in an XPCOM component?
Take a look at nsITimer.
And you might be interested in the code in this bug about implementing a GStreamer backend for <video>.