1

I am currently implementing a webrtc + pubnub lobby in my Rails 4 application using the sample app below: https://github.com/pubnub/webrtc-chat

I have successfully implemented all parts except for the bindings between the html and coffeescript.

In my chatroom.html.erb i have the following:

         <div class="box">
            <h3>Try Now</h3>
            <input type="text" id="userid" placeholder="Username" />
            <br />
            <a href="#" class="btn btn-large btn-inverse" id="login">Log In</a>
            <br />
            <p style="padding-top: 12px;">- or -</p>
            <span id="signinButton"></span>
         </div>


    <script type="text/html" id="user-item-template">
      <li class="user" data-user="<%= id %>">
      <span class="name"><%= name %></span>
      <a href="#" class="btn btn-success" data-user="<%= id %>">Call</a>
      </li>
    </script>

In my coffeescript I have the following:

  document.querySelector('#login').addEventListener 'click', (event) ->
    uuid = document.querySelector('#userid').value
    login "guest-#{uuid}"

  login = (name) ->
    uuid = name

 userTemplate = _.template $("#user-item-template").text()
 userList = $("#user-list")
  $(document).on 'pubnub:ready', (event) ->
    pubnub.subscribe
      channel: 'phonebook'
      callback: (message) ->
        # Do nothing
      presence: (data) ->
        # {
        # action: "join"/"leave"
        # timestamp: 12345
        # uuid: "Dan"
        # occupancy: 2
        # }
        if data.action is "join" and data.uuid isnt uuid
          newItem = userTemplate
            name: data.uuid.split('-')[1]
            id: data.uuid
          userList.append newItem
        else if data.action is "leave" and data.uuid isnt uuid
          item = userList.find "li[data-user=\"#{data.uuid}\"]"
          item.remove()

I get the following error:

Internal Server Error undefined local variable or method `id' for #<#:0x00000101ff1d40>

I am assuming that I am having complications due to the erb tags? They were defined already in the js app example. Is there a difference between rails erb tags and the tags found with javascript apps? I notice that the example is using only normal html. Maybe options like Angular.js could help but I would rather not delve into that.

EDIT: Added input form that takes in user id/name

Alistair Gillespie
  • 540
  • 1
  • 5
  • 22

0 Answers0