HTML5 audio conversion using NodeJS on Heroku - node.js

I have a HTML5 app that allows users to upload and play their audio files. The server is Node running on Heroku.
To allow cross-browser audio play, what I understand is that I have to at least maintain two formats of each audio file, let's say .mp3 and .ogg. So, I need to transcode the files automatically on the server side.
The problem is that Heroku does not run ffmpeg. I found this project that creates a custom buildpack for heroku that supports ffmpeg but it seems to be for Rails apps: https://github.com/dzello/ffmpeg-heroku.
I was thinking to run an external server for transcoding, which my nodejs app sends the file to, it does the transcoding, and reuploads the new file on my nodejs server. But I don't know how to set up such a server, and whether there is already a ready solution which does this kind of work?
So, here are my questions:
1- Is there a solution to run ffmpeg on heroku+nodejs?
2- How can I set up a transcoding server that communicates with my nodejs+heroku server?
Thanks!

Why do you need to run it on heroku? Just setup some virtual server, for example on Digital Ocean
And use a linux server to setup node. It's pretty easy and will run every package needed. It already has droplet with preconfigured node.js+mongodb stack

Related

Kurento webrtc video doesn't play from remote server

I've installed kurento media server locally using docker, and created a Node.js app to communicate with it.
I have two types of clients, presenter clients & viewer clients.
Everything works on the local environment using self signed SSL certificate, I can also connect from other devices on local network.
Now I want to make it work from AWS, I created CloudFormation stack using template file, from kurento installation guide, and deployed my Node.js server to a different EC2 instance.
The problem is that the video doesn't play on viewer clients.
The communication with Node.js app works the same as in local & sdpAnswer arrives.
My first guess was that it's a certificate error, so I linked my domain to CloudFlare, and used its SSL service.
But the video still doesn't play.
Also, I checked The TURN server, that the template created, it seems to be working:
All ports are currently open on both EC2 instances.
What am I missing here? And how could I troubleshoot it?
Thanks in advance :)
If anyone is interested, in my case I forgot to call:
webRtcPeer.addIceCandidate(candidate);
In my client side app, when candidates arrived from server.

running nodejs app inside go

I have a requirement. Is there a way to run nodejs apps inside golang? I need to wrap the nodejs app inside a golang application and in the end to result a golang binary that starts the nodejs server and then to be able to call nodejs rest endpoints. I need to encapsulate in the golang binary the entire nodejs application with nodem_odules, if necessarily the nodejs runtime.
Well, you could make a Go program that includes e.g. a zipped Node application that it extracts and starts but it will be very hard to do well - you will have huge binaries, delays in extracting files, potential portability problems etc. Usually when you want to call REST endpoints then you host your Node app on some server and you let the client app (the Go app in your example) to connect to that Node app to work correctly. Advantages are that it is much faster, the app is much smaller, you don't have portability issues with Node binaries and addons and you can quickly update your backend any time you want.
It will be a very bad idea to embed a nodejs app into your golang, for various reasons such as: size, security updates pushing, etc.
However, if you so strong feel that they should be together, you could easily create a docker container with these two (a golang server + a node app) and launch them via docker. You can set the entrypoint to a supervisord daemon so that your node server as well as the golang server can be brought up when your container is run.
If you are planning to deploy via kubernetes you can create two individual docker containers (one for the golang server, one for the node server) but deploy them always together as a pod too.
There are multiple projects to embed binary files and/or file system data into your Go application.
Look at 'Alternatives' section of project 'vfsgen':
https://github.com/shurcooL/vfsgen#alternatives

How to run ffmpeg command from the client side?

I am trying to make an online examination portal. When students start the exam, their webcam will start automatically and record the stream live and store in the server. Invigilators will either watch the students live or they can watch the saved live streams later.
After many research on various technologies I came across this link. It uses Node JS with websockets and ffmpeg. I ran the ffmpeg command and it streamed the live video successfully.
But the problem is, in order to live stream, the students have to have ffmpeg installed in their system and they should run the command directly from the terminal. So how can I change this? The students will live stream from their browser, because this is a web portal. If we put this command in a PHP script, then the command will run at the server side. But client side command should run in this case. How can I run command from client side?
Any suggestions will be helpful.

Amazon EC2 Ubuntu instance: Where should I upload the files to access them from the browser?

I've created an Amazon EC2 Ubuntu instance to test some nodeJS files and JS files.
I've managed to install NodeJS and MongoDB there, and I do have a publicIP.
Now, where should I upload the files in order to access the file from the browser? Something like myPublicIP/index.html
I've read here that I should use the /var/www/html directory, but I haven't found it when trying to locate using cd var/www/html.
Should I create that directory?
Nodejs is not a webserver -- unlike what you have with Apache or Nginx -- but there are several frameworks that implements the basis for webserver functionality, plus much more.
A simple and frequently used framework is express (which you install into your nodejs app by $npm install express --save)
The express guide has a number of different examples on handling requests, including how to use middleware for parsing urls, and you can simply write a simple webserver in a few lines.
You should also check out some of the extensive examples in the answers in this question as well: Using node.js as a simple web server
You only need /var/www/html when you are using Apache, which is not your case since you are using nodeJS.
You just need to upload your code to a folder in EC2 and then start it using
node file.js
If you do it that way however, the moment you close your terminal, all connections are lost and your node server stops listening for new incomming connections. Your EC2 instance also need to have rules in security groups to allow incoming traffic to the door you are listening.

Where can I host a node.js chat bot?

I know this isnt coding but i dont know where else to look.
So I've written a chat bot using node.js and the socket.io-client module. Basically it's just a program that auto responds to messages on a chat room also written with node.js. The problem I have is hosting it. I have hosted it on my raspberry pi which works perfectly but isn't ideal as I sometimes want my pi for other things and this bot runs 24/7.
So, I looked around for some free node.js hosting. I found c9.io, heroku and appfog but all of them expect you to host websites with node.js and so aren't setup for my needs. I need a single instance to be always running but these hosts constantly restart and terminate the program causing all sorts of problems for me which wouldn't really be an issue if it was just outputting a web page.
So, is there anywhere that is suitable for hosting a node.js app like mine?
Have Amazon host it for you. That's what I'm doing with one of my projects. Just create an instance, I used Ubuntu for my OS, then installed Node.js and was good to go.
My recommendation will be to host it on openshift
https://www.openshift.com/app/account/new
Heroku is also widely used but in their free tier your bot has to "sleep" 6 hours
https://www.heroku.com/

Resources