title: Opentok unable to connect to session
body: <p>This is specific to the Opentok API. I'm quite new to javascript and struggling to get this all to work nicely.</p>
  
  <p>Here's a link to the docs if you need it:
  <a href="https://tokbox.com/developer/guides/" rel="nofollow">https://tokbox.com/developer/guides/</a></p>
  
  <p>My error is:</p>
  
  <pre><code>signal error (500): Unable to send signal - you are not connected to the session.
  </code></pre>
  
  <p>My html file looks like this:</p>
  
  <pre><code>var apiKey = 45317102;
  var sessionID = "#{@session.session_id}";
  if (OT.checkSystemRequirements() == 1) {
    var session = OT.initSession(apiKey, sessionID);
  } else {
    // the client does not support WebRTC
    console.log('does not support WebRTC');
  }
  
  var token = "#{@token.token}";
  var publisher;
  
  var publisherOptions = {
    width: 600,
    height: 400,
    name: 'Publisher',
    // publishAudio: true,
    // publishVideo: false
  }
  
  var subscriberOptions = {
    width: 300,
    height: 200,
    name: 'Subscriber'
  }
  
  // for publisher
  session.connect(token, function(error) {
    if (error) {
      console.log(error.message);
    } else {
      session.publish('myPublisherDiv', publisherOptions);
      console.log('Publishing a stream.');
    }
  });
  
  // for subscribers
  session.on({
    streamCreated: function(event) { 
      session.subscribe(event.stream, 'subscribersDiv', subscriberOptions); 
      console.log("New stream in the session: " + event.stream.streamId);
    }
  });
  
  // check if the user is a moderator
  if (session.capabilities.forceDisconnect == 1) {
    console.log('you can moderate.')
  } else {
    console.log('you cant moderate');
  }
  
  session.signal(
    {
      data:"hello"
    },
    function(error) {
      if (error) {
        console.log("signal error ("
                     + error.code
                     + "): " + error.message);
      } else {
        console.log("signal sent.");
      }
    }
  );
  </code></pre>
  
  <p>and my backend (ruby / rails) controller looks like this:</p>
  
  <pre><code>def create
    session = OPENTOK.create_session media_mode: :routed
    session_id = session.session_id
    @session = Session.new(session_id: session_id)
    if @session.save
      redirect_to @session
    else
      render 'new'
    end
  end
  
  
  def show
    @session = Session.find(params[:id])
    unless params[:id].blank?
      s = Session.find(params[:id])
      token = OPENTOK.generate_token s.session_id
      @token = Token.create(session_id: s.id, token: token, active: true)
      @token.save
    end
  end
  </code></pre>
  
  <p>now I'm not able to make the person who creates the session a moderator (ability to remove others) and it seems like I'm in-fact even unable to connect to the session. Even though when I run it I'm able to have 2 people in the same session at the same time.</p>
  
  <p>Does anybody know what's happening (or more likely what I'm missing from my code)?</p>