Network Service Discovery (mDNS) on react-native/Expo - javascript

I have an IOT device ruining a mDNS responder, is there a way to find the device through a react-native/Expo app?
I have found a react-native library (react-native-zeroconf). However, it requires react-native-link which expo does not support.
I have also found a pure Java Script library (multicast-dns). However, I'm not sure whether it is possible to port that to react-native/Expo.
Should I detach and use native modules? I'm keeping that as a last resort for now.

The first one you can do with expo but you will need to detach.
The second will not work at all because it assumes the node API which does not exist in ReactNative.

Related

There is a mode to run a nodejs backend on android?

I will try to explain better, I made a NodeJS backend with integrated react UI that call localhost for local API/function integrated in NodeJS. Is there a way to make a porting of this solution to an APK? For now the only way to make NodeJS works on android is manually or with obsolete library like Androidjs
Yes we can use Node.js using Termux however it is not quite recommended to run a backend server on Android.
There is an Library. You can check nodejs-mobile. If you want Node.js in root process can you check Magisk Node.js
The right answer after some research is the comment of Norman Breau
"Android is kind of a closed system. Unless you root your device, normal app processes don't have direct access to many OS/system APIs. This I suspect would be a problem even if you could compile Node and natively link it against your app."

Cordova web server with configurable responses

Is there any way to set up a local web server in a Cordova application such that I can control the responses via Javascript? I'm currently developing a custom plugin that communicates with a remote system via HTTP. I'd like to be able to run integration tests on this that are written in the Javascript code of a Cordova application, so I can easily test them in all supported platforms (Android, iOS, and ideally in the browser too... although the latter seems a little unlikely to be possible), but this means I need to be able to set up mock API responses from javascript code ... which will require the presence of a mock server that the plugin can communicate with.
I'm familiar with this plugin, but it can only respond using files in the local system -- I want to be able to generate responses and capture sent POST data in a Javascript callback. Is there any existing way of doing this?
Having searched extensively, I came to the conclusion that no such plugin exists.
I have therefore started an implementation of such a plugin myself: the initial version is now available on NPM and GitHub, with a sample project available in the github repository.
Android support is currently functioning, and I intended to start on iOS support in the next few days.
(Updated to add: unfortunately the project I was working on was cancelled, so have not had time supported by my employer to finish the iOS version, and as I don't have a mac personally so can't work on this on my own time, this seems unlikely to happen in the near future, but if anyone else needs it, it should be relatively simple to add the iOS version)

Do I need to check for localStorage support when using Electron

I have started making desktop apps with Electron.I need to save some configuration into localStorage.I am using the latest version of Electron and I know that localStorage is supported.
Due to my previous experiences with my website I know that I have to check for localStorage support before doing something.
Do I need to do the same in Electron apps?
No you don't - Electron is based on Chromium which has LocalStorage support for a very long time now.
Side note
In Electron, you can also read/write actual files using the file system which might be a better alternative for storing config files.
Since Chromium is not sandboxed when running in the way Electron runs it, you could also read/write actual text files just as you would in Node.js - This question explores those alternatives - or just go straight to using electron-config

Making a node.js application a PEER with WebRTC

So, I have a web app that generates large buffers of color information that I want to send to a node application running on another machine in my local network. Web Sockets doesn't seem to be fast enough for me. I was looking to use UDP and it seems WebRTC is the only way to do that from a browser. The caveat, it seems, is WebRTC is only PEER to PEER (browser to browser). I figured, I could use node webkit to emulate being my other "PEER". In my node app I could handle the "signaling" and have it set itself up in a RTCPeerConnection to my web app. Therefore, I could send my data from my web app to my node app (local network). For some context, I have one computer running native software to drive a light fixture and I want to use a web app to control the lights.
To boil the question down, how can I make a RTCPeerConnection from a browser to a node webkit app?
Any help would greatly appreciated.
Thank you!
-Jake
Node-RTCPeerConnection is an attempt (current WIP) to create a spec compliant implementation of RTCPeerConnection for Node.js entirely in JavaScript with no native C or C++ code. This enables browser-peers to speak to non-browser (Node.js) peers.
But you can not use it for production yet.
Then we also have wrtc (node-webrtc) that provides a native module for NodeJS that supports a subset of standards-compliant WebRTC features. Specifically, the PeerConnection and DataChannel APIs.
Too many people are having problems with wrtc. Since it has to download lots of source and build it only to find out that it fails after a long while on certain platforms. Unfortunately it doesn't come with any prebuilt packages described in this issue
You can use either the google implementation of webrtc or a more recent implementation (by Ericsson) called openWebrtc. The developers of openWebRTC are very proud of running their implementation on various pieces of hardware like raspberry pi and iOS devices.
The one that worked best for me was electron-webrtc (which in turn uses electron-prebuilt) for better compatibility. It creates a hidden Electron process (which is based on Chromium, so WebRTC support is great!) and communicates with that process to enable WebRTC in Node.js. This adds a lot of overhead.
It is intended for use with RTCDataChannels, so the MediaStream API is not supported.
Other resources:
https://github.com/webrtcftw/goals/issues/1
Update 2019
Currently, the best and easiest way to solve this problem is to use webrtc module. Check samples for inspiration. This module does what you were looking for, implemented with N-API and using Canvas module to compose new video from the client stream. Hopefully this will help those who face this problem in the future.

How to detect desktop idle time from an Electron app?

I need my Electron app to respond to the user becoming idle (no mouse or keyboard inputs to any program on the OS) for a certain amount of time.
How can I trigger a function based on such idle time data?
You can always detect idle times on Linux by using XScreenServer, GetLastInputInfo on Windows and CGEventSourceSecondsSinceLastEventType on Mac
I've published desktop-idle using these API's, you can check the source code https://github.com/bithavoc/node-desktop-idle
UPDATE:
Electron 3 users can use the power monitor API to achieve the same goal: https://electronjs.org/docs/api/power-monitor
Some people have written node libraries that hook into the native platform code for OSX, Windows, and Linux to accomplish this.
I ended up using this library to accomplish the same thing in my electron app:
https://github.com/paulcbetts/node-system-idle-time
It's published on npm as #paulcbetts/system-idle-time
I tested it on OSX and it seemed to work fine there.
I did originally get a "module version mismatch expected 50 got 46" error, but running this command cleared it up:
npm rebuild --runtime=electron --target=1.4.3 --disturl=https://atom.io/download/atom-shell --abi=49
Replace target with whatever version of electron you're using.
Since electron uses node, you should checkout RobotJS. These things are platform specific so it does need some other dependancies but you can monitor mouse/keyboard and see if it's changed, or control it (hence the name).
Look at Electron Power monitor API's and use
powerMonitor.getSystemIdleTime()

Categories

Resources