Rails Signalling Server - ruby-on-rails

I am creating an app with Ruby on Rails (4.2). I want to add a WebRTC functionality to it so that two users can choose to videochat with each other. I'd appreciate if you can help with:
What are some of the options to create a signalling server with Rails (I have no Node.js experience)?
Any video tutorial or sample code for creating a simple signalling server with Rails (and even better for using WebRTC)?
Thanks.

There is no need for you to implement a signalling server. Run an existing one independent of your rails app.
E.g. if you're using SIP have a look at Kamailio or Asterisk. Or in your case something like Signalmaster might be easier.
The signalling "part" of your application will be independent of your rails application.
Except for the client-code which will probably run inside the same page (javascript environment) in your browser.

Related

How to get Rails and all requirements running to use React?

Iam a novice in rails and trying to write my first React frontend. I have read enough to know that there are different methods to use React with rails. I decided to split frontend and backend, and use rails in API mode. I cannot find good sources explaining what I need on my server to get rails and react going, and why. I read so far about npm, node.js, Heroku and so on, but i lack the knowledge to decide what to pick and i dont understand the interactions yet.
Does someone know a good tutorial, some sources or keywords to point me to a direction?
If you want to use Rails just in API mode with React on frontend then you can separate those apps completely.
I.e. use Rails/Puma server for API and have a separate server (Nginx/Apache/Node.js) to serve the frontend React app and other static assets.
For using react as your client-side application and rails for the server-side you need two different applications. As Rails is MVC I suggest you use just ruby and Sinatra server.
In this situation be careful about the cross-origin errors you have to enable it while using two agents.
Take a look at this.

How to use Rails as DDP server with Meteor.js client

We have a Rails app that acts HTTP API only. On the client side, Ember.js is currently used. We are not overly impressed by Ember and really like the approach Meteor.js takes. So we'd like to exchange the client side with Meteor.js and communicate with the Rails server via websockets that speak the Data Distribution Protocol (DDP), so we can keep using the models, mailers and controllers in Rails. Implementing server side of DDP should be easy.
However, we're unsure how to make Rails talk websockets. We found Reel, which seems to make it easy to accept websocket requests in a standalone environment. Reel seems great as we'd like to implement the DDP on top of the Celluloid stack anyway. But what about running Reel in the Rails environment? Would we need "rails runner" for that? And we'd like to keep using the existing controllers to dispatch incoming requests (like, to add/change/remove resources). Is that even possible without having the request coming through Rack?
Any input is appreciated.
It's a bit late, but I've implemented DDP in Ruby, you can check it out here:
https://github.com/d-snp/ruby-ddp-server
It includes an implementation of EJSON as well. It's built on top of celluloid-websocket, and can be ran simply as a rack app.
I've made an integration with RethinkDB that can be used as a reference to build your own collections implementation.
https://github.com/d-snp/ruby-ddp-server-rethinkdb
I've also made a sample chat application that can be found here:
https://github.com/d-snp/celluloid-rethinkdb-chat
It's something that I have been longing to do as well, to integrate old "legacy" Rails code. Here is the best way I have found:
Since you would not be using any of Rails router/controller/views, but just the ability to read data and push it to the client, I recommend you use Rails to create JSON apis to the database, and deploy the code, then in Meteor you can consume the data via the http package, this would happen on the server at a regular interval and populate the MongoDB with the normalized data you need, then it would serve the browser client.
I am working on such an application that will keep a normalized version of the data in Mongo, and a relational version of the data in mySql (through Rails) this way I can preserve the legacy Rails functionality that I dont want to rewrite in JS, and get the benefit of Meteor for the one page that I need it most.

Is there a good way to share code beween a Rails App and an API?

We have a Rails App and a Sinatra API with separate codebases. They need to work together with the same database.
We can create a record using the API, and then display a page for that record using the Rails app. When creating the record using the API, there are many other records that need to be created at the same time. This all happens fine on the Rails app.
Here's the problem: What is the best way to test that when the API creates the record, all the other records are created and the page renders properly on the Rails app?
I am writing a test in the Rails app for this. Since the API is separate from the Rails app, I can create a mock. But the mock needs to do everything the API would do, so it is not really a mock.
Is it possible (or practical) to include in the Rails app the API file that contains the call to create the record?
Or is there a better way to test for this?
Well, you have two web applications. That is, two applications that expose a (more or less) public interface on the Net and that respond to HTTP calls.
Why do not use a HTTP client to invoke all of the two servers and perform a complete test (a "workflow test", if you like)?
You can probably use any existing web testing tool for this, or write a test script with any language.
No, it is not possible to include in the Rails app a file from the API.
They are hosted on different servers. Even if I got it working on my local machine, it would not work in production.
EDIT: Actually, this is not true. If the file only needs to be shared for testing, then it will only run on the local machine (unless there is some kind of CI system). So the production environment doesn't matter. Only the testing (CI) environments matter.

Communication between Rails apps

I have built two rails apps that need to communicate and send files between each other. For example one rails app would send a request to view a table in the other apps' database. The other app would then render json of that table and send it back. I would also like one app to send a text file stored in its public directory to the other app's public directory.
I have never done anything like this so I don't even know where to begin. Any help would be appreciated. Thanks!
You requirement is common for almost all the web apps irrespective of rails, Communicating with each other is required by most modern web apps. But there is a small understanding that you need to get hold on,
Web sites should not directly access each others internal data (such as tables), (even if they are build by the same language (in this case Rails) by the same developer),
That is where the web-services comes in to play, So you should expose your data through web services so that not only rails application can consume that, but also any app that knows how to consume a web service will get benefit.
Coming back to your question with Rails, rails supports REST web services out of the box, So do some googling about web services, REST web services with rails
HTH
As a starting point, look at ActiveResource.
Railscast
docs
Message queuing systems such as RabbitMQ may be used to communicate things internally between different apps such as a "mailer" app and a main "hub" application.
Alternatively, you can use a shared connection to something like redis stick things onto a "queue" in one app and read them for processing from the other.
In recent Rails versions, it is rather easy to develop API only applications. In the Rails core master, there was even a special application type for these apps briefly (until it got yanked again). But it is still available as a plugin and probably one day becomes actually part of Rails core again. See http://blog.wyeworks.com/2012/4/20/rails-for-api-applications-rails-api-released for more information.
To actually develop and maintain the API of the backend service and make sure both backend and frontend have the same understanding of the resources, you can use ROAR which is great way to build great APIs.
Generally, you should fully define your backend application with an API. Trying to be clever and to skip some of the design steps will only bring you headaches in the long run...
Check out Morpheus. It lets you create RESTful services and use familiar ActiveRecord syntax in the client.

Ruby on rails and Node.js

I am wondering how to integrate node.js on a rails app (for learning purpose).
Based on Michael Hartl tutorial (http://railstutorial.org/) I realized a basic twitter clone with rails and want to get user microposts in real-time without the use of comet or juggernaut. (the application is hosted on heroku)
For the moment, I only see example with node.js frameworks (http://howtonode.org/grasshopper-shoutbox) but nothing merged with a ruby on rails app.
I would be very thankful if someone knows a good tutorial or give me some points to start in order to accomplish this.
Thanks!
As Shripad said, I'd consider trying to build your app with Node by itself. Geddy will feel familiar (getting started anyway) if you have experience with Rails. Note: I do not have experience on a real world app with Geddy, but it is the best Rails-like framework I've seen so far. For persistence you can use SQLite, PostgreSQL or CouchDB, just like you would with Rails. I thought about how to communicate between a Rails app and Node without any intermediary. In our work project we're using Redis as an intermediary between Rails and Node. Rails publishes messages to Redis, Node pulls messages from Redis. I could not find a good way or example projects to avoid the middle communication layer on a personal project, so I went with the same setup. The good news is Node Redis modules are written and once you get everything installed, it is easy to test out pushing messages back and forth.
If you are looking at creating real-time apps then go with node.js (high concurrency) alone. You really cannot integrate node.js into a rails app. You can however have a node server setup on another port with an api and websockets configured and then have your rails app communicate with that server. It is PITA to do that kind of setup. You rather build the entire web app in node itself. However, if you want anything rails specific that does not use juggernaut then i would suggest http://www.pusherapp.com.
Its extremely easy to setup server push using Pusher.
It already did. Not really NodeJs but a framework built on top if it. Yada, yada, yada... check this out: https://github.com/1602/express-on-railway
**Run node along side your rails server**
If you want to intergrate your Rails app with Node you could use the node-rails gem
Node Rails will enable you to run a Node server along side your Rails application and have the two share authentication NodeRails assumes you are using Devise for your authentication. Node-Rails uses [redis gem][2] , so you will need to have that installed.
Learn more about using npm packages on Rails.

Resources