Opentok无法连接到会话

时间:2015-08-21 05:57:44

标签: javascript ruby-on-rails opentok

这是特定于Opentok API的。我是javascript的新手,并努力让这一切都很好地工作。

如果您需要,这里是文档的链接: https://tokbox.com/developer/guides/

我的错误是:

signal error (500): Unable to send signal - you are not connected to the session.

我的html文件如下所示:

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.");
    }
  }
);

我的后端(ruby / rails)控制器看起来像这样:

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

现在我无法让创建会话的人成为主持人(能够删除其他人),而事实上我甚至无法连接到会话。即使我运行它,我也可以同时在同一个会话中有2个人。

有人知道发生了什么(或者更可能是我的代码中缺少的内容)吗?

0 个答案:

没有答案