Tuesday, 14 March 2017

Video Chat app on Heroku using Peer js and Node js

I'm following this tutorial on https://www.sitepoint.com/webrtc-video-chat-application-peerjs/ to make a video chat app using peer js, node js and trying to host this on HEROKU I have managed to get the client side working (using express) but don't have any idea how the server side will work

The client side server.js for static files:

var express = require('express');
var app = express();

//setting port
var port = process.env.PORT || 8080

app.use(express.static(__dirname));

//routes
app.get("/",function(req, res){

res.render("index");

})

app.listen(port,function(){

console.log("app running")
})  

above code is working fine and I can see my index.html via heroku

Other server i.e peer-server.js to get peer information:

var PeerServer = require('peer').PeerServer;
var server = PeerServer({port: 9000, path: '/peerjs'});

I don't have any idea on how to run this code on heroku and get data on script.js

script.js:

$(function(){

  var messages = [];
  var peer_id, name, conn;
  var messages_template = Handlebars.compile($('#messages-template').html());

  var peer = new Peer({
    host: 'localhost',
    port: 9000,
   path: '/peerjs',
    /* debug: 3,
    config: {'iceServers': [
    { url: 'stun:stun1.l.google.com:19302' },
    { url: 'turn:numb.viagenie.ca',
      credential: 'muazkh', username: 'webrtc@live.com' }
    ]}*/
  });

  peer.on('open', function(){
    $('#id').text(peer.id);
  });

They (sitepoint) have step by step guidance on how to deploy it on a local server but not on heroku or something similar

Any help will be greatly appreciated



via Ravi Sharma

No comments:

Post a Comment