peer.id not getting created

350 views
Skip to first unread message

Aishwarya Chaturvedi

unread,
Jul 18, 2017, 9:05:04 AM7/18/17
to PeerJS
I am doing a video chat app, in which I am creating a peer object in index.html.
Below is the code

<!DOCTYPE html>
<html>
 
<head>
   
<meta charset="utf-8">
   
<title>GeekChat</title>
   
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js' type='text/javascript'></script>
   
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
   
<script src='https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.14/peer.js' type='text/javascript'></script>
   
<script src='https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.14/peer.min.js' type='text/javascript'></script>
 
</head>
 
<body>
   
<div id='app'>


   
</div>
   
<script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js'></script>
   
<script src='/io-square/io-square-browser.js'></script>
   
<script>
      window
.socket = io.connect()
      window
.peer = new Peer({host: 'peerjs-server.herokuapp.com', secure: true, port: 443})
   
</script>
   
<script src='bundle.js'></script>
 
</body>
</html>
and I am accessing peer.id at some other point in the app. the whole peer object with 7 properties gets created, but the id doesn't get created.

At later point when I access window.peer.id on the browser developer tools, I am able to access it.

Can anybody please let me know when does the peer id actually gets created

fugee ohu

unread,
Apr 17, 2018, 2:25:01 PM4/17/18
to PeerJS
It doesn't get created for you by peerjs, rather, you pass it too Peer new as the first option followed by a comma In mine, below, I've passed a value for my_id from my view using a content_tag If you get the error 'Could not get an id from server' try replacing the variable you're using for the id with a literal like 1 or 2 or 'Aishwara' so you'll know if the problems just in passing the variable from view to js Here's an example from my js file
        var peer = new Peer(my_id, {host: 'localhost', port: 9000, config: {'iceServers': [
{url:'stun:stun01.sipphone.com'}, ... long list of servers ]});

Additionally Turn is depracated in favor of Stun so don't bother looking for working Turn servers

fugee ohu

unread,
Apr 17, 2018, 2:33:41 PM4/17/18
to PeerJS


On Tuesday, July 18, 2017 at 9:05:04 AM UTC-4, Aishwarya Chaturvedi wrote:
html.erb:
<%= content_tag "div", id: "my_id", data: {my_id: current_user.id} do %>
<% end %>

js:
        var my_id = $('#my_id').data('my_id');
        var peer = new Peer(my_id, {host: 'localhost', port: 9000, config: {'iceServers': [{url:'stun:stun01.sipphone.com'}]}});

 

fugee ohu

unread,
Apr 20, 2018, 6:21:12 AM4/20/18
to PeerJS


On Tuesday, July 18, 2017 at 9:05:04 AM UTC-4, Aishwarya Chaturvedi wrote:
I decided not to use peerjs because it's no longer being maintained 
Reply all
Reply to author
Forward
0 new messages