Is it possible to run FFmpeg or some similar library on client-side? - requirejs

I am currently trying to run ffmpeg through fluent-ffmpeg (from node_modules) on the client-side, in a video player application that uses RequireJS. I've looked at https://requirejs.org/docs/node.html#2, however this concerns the modules that run on the server side. Is there an option to import/require fluent-ffmpeg or similar library into RequireJS project to run on client side?
This is not working:
var FfmpegCommand = require('fluent-ffmpeg');
var command = new FfmpegCommand();
Is there an option to import/require fluent-ffmpeg or similar library into RequireJS project to run on client side?

Kagami/ffmpeg.js and videoconverter.js are javascript modules that can be used on the client side via Web Worker.

Related

How typescript requier Nodejs module?

i read many similar question
this is the workaround i am trying now
for example to mysql module in Nodejs
1.
cmd enter:
npm install typescript
npm install mysql
typescript write:
import * as ms from "mysql";
// i see some people write " import ms = require("mysql"); ", but i get the error
then i check console window in chrome devtool
i see error " Uncaught ReferenceError: exports is not defined "
and this error seems to stop script from keep running.
TypeScript will, by default, transpile to JavasScript files using the CommonJS module format which browsers do not support.
You can configure it to use ECMAScript modules (which are supported by browsers).
However, the mysql module depends on APIs that are available in Node.js but not in web browsers so you cannot use it in a web browser.
You could write a web service (e.g. using Express hosted by Node.js) which accesses the database and then interact with it from the browser using forms, Ajax or Web Sockets.

fs.existsSync is not a function error when requiring grpc through create-react-app

We are trying to get gRPC to work with React (actually we were trying to get it to work with React-Native but gave up on that for now).
Using plain node.js things are pretty straight forward if you follow this example.
We started by using create-react-app but when we started the app, we got the following error:
existsSync is not a function
That was casued by this bit in pre-binding.js belonging to the node-pre-gyp package located in grpc:
var existsSync = require('fs').existsSync || require('path').existsSync;
My understanding is that something goes on with Webpack (or some other process run by create-react-app) that goes and returns and empty object instead of require('fs').
Any ideas of how to get this to work without having to give up on the wonders of create-react-app?
To test it out you can just follow these 2 easy steps:
create-react-app test-app
add import grpc from 'grpc'; in the App.js file
Basically, from what I understand now, you are not really supposed to use gRPC + Protobuf directly from any frontend but rather it is more common to use the grpc node package on node.js server-side code and then communicate with the browser-side code using Express.
The server-side code on node.js then communicates using grpc with the microservices.
We are testing out the use of Firebase Functions to communicate securely with the frontend and Firebase Functions communicate with the Go microservices using grpc.

Can we use node core module or other node module in React Js using bundling tool Webpack?

I try to use node core module fs in reactjs.
const fs = require('fs');
but it is throwing error: "can't find module fs". can we use node core module or other module in front end side(react js) using webpack. if yes then how can we achieve this and if we can't, then is there any way to use node module in front end side ?
Using a node module in the front end can make sense, but in the case of fs it doesn't. The file system of the client computer is not exposed to the code running on a website.
This is enforced for evident security reasons. You cannot circumvent this barrier magically using a node module on the client side.
The short answer here is : no, you can't.

Compile HttpServer from Dart to JS for NodeJS

Is there some way to create http server on Dart that will be compiled to JS for Node JS?
If I try to use default server
HttpServer.bind(new InternetAddress("127.0.0.1"), 8081);
and then compile this code via dart2js I'll get error when node started
Unsupported operation: InternetAddress
You can't use dart:io when you want to build to JS because dart:io won't be available where the build output runs.
dart:io forwards to operating system calls and dart2js doesn't have any ability to translate such calls to JS (actually Node.js because JS itself doesn't provide any way at all)
You might need something like https://github.com/luizmineo/node-webkit.dart to use a custom implementation that translates to quivalent Node.js calls.

Require socket.io-client from installed socket.io package

According to the socket.io-client readme there's a way to access this module from an installed socket.io package. Something similar is stated on the site. However the only way I've managed to 'require' socket.io-client is by using the arguably hacky:
require('socket.io/node_modules/socket.io-client')
What's the quote-unquote correct way of requiring this package?
Background info: I have a nodejs module that's running a socket.io server (hence I have socket.io installed), but I'd also like to run a client so that i can connect to some other server. The normal way of doing this would be to just npm install socket.io-client and then require that package. But since socket.io-client is a dependency of socket.io, i'd like to access it through this other package.
OK, here's a new answer now that I understand you want to do initiate socket.io connections from your node server.
On this page in the socket.io doc, it shows that you can do this:
var ioClient = require('socket.io-client');
to get access to the client-side socket.io functionality from your server. I have not tried it myself.
There's also a piece of server-side client code example here: https://www.npmjs.com/package/socket.io-client.
Node.JS (server-side usage)
Add socket.io-client to your package.json and then:
var socket = require('socket.io-client')('http://localhost');
socket.on('connect', function(){});
socket.on('event', function(data){});
socket.on('disconnect', function(){});

Resources