我正在尝试在我的Ruby on Rails应用程序中集成视频流:
rooms_controller.rb:
class RoomsController < ApplicationController
require "opentok"
before_action :config_opentok,:except => [:index]
def index
@rooms = Room.where(:public => true).order("created_at DESC")
@new_room = Room.new
end
def create
tok_session = @opentok.create_session
@new_room = Room.new(room_params)
@new_room.update_attributes sessionId: tok_session.session_id
respond_to do |format|
if @new_room.save
format.html { redirect_to("/party/"+@new_room.id.to_s) }
#redirect_to rooms_party_path
else
format.html { render :controller => 'rooms', :action => "index" }
end
end
end
def party
@room = Room.find(params[:id])
config_opentok
@tok_token = @opentok.generate_token :session_id=>@room.sessionId
end
private
def config_opentok
if @opentok.nil?
@opentok = OpenTok::OpenTok.new '46219592', 'xxxx'
end
end
def room_params
params.require(:room).permit(:name, :sessionId, :public)
end
end
}
在Rails控制台中,我看到一个session_id创建成功。
(0.3ms) select * from rooms where rooms.id = 8;
=> [{"id"=>8, "name"=>"umadec6", "sessionId"=>"2_MX40NjIxOTU5Mn5-MTU0NDEyMjgwMDg1MX55R2xWdmovRHBoL3hsamFYZXB6dFlYRWt-UH4", "public"=>1, "created_at"=>"2018-12-06 19:00:00.260502", "updated_at"=>"2018-12-06 19:00:00.260502", 0=>8, 1=>"umadec6", 2=>"2_MX40NjIxOTU5Mn5-MTU0NDEyMjgwMDg1MX55R2xWdmovRHBoL3hsamFYZXB6dFlYRWt-UH4", 3=>1, 4=>"2018-12-06 19:00:00.260502", 5=>"2018-12-06 19:00:00.260502"}]
如果我从上述记录中复制session_id并将其粘贴到opentok网站中:https://tokbox.com/account/#/project/46219592 我能够生成令牌。但是在应用程序中,它失败并显示以下错误:
无法为不属于ap的session_id生成令牌
i_key:46219592
任何输入都会有所帮助。谢谢