Created
August 8, 2013 02:24
-
-
Save Jaffery5/6180910 to your computer and use it in GitHub Desktop.
Open tok code... Really need some help
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id= "Share" http://tokboxvideochat.herokuapp.com/party/<%= @room.id %></div> | |
<div id="videobox"> | |
</div> | |
<script src="http://static.opentok.com/v0.91/js/TB.min.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
var apiKey = xxxxx102; | |
var sessionId = "<%= @room.sessionId %>"; | |
var token = "<%= @tok_token %>"; | |
var session; | |
// TB.addEventListener('exception', exceptionHandler); | |
//Video chat event listeners | |
//session.addEventListener('sessionConnected', sessionConnectedHandler); | |
//session.addEventListener('streamCreated', streamCreatedHandler); | |
//session.addEventListener('streamDestroyed', streamDestroyedHandler); | |
TB.setLogLevel(TB.DEBUG); | |
//session.connect(apiKey, token); | |
var session = TB.initSession(sessionId); | |
session.addEventListener('sessionConnected', sessionConnectedHandler); | |
session.addEventListener('streamCreated', streamCreatedHandler); | |
session.connect(apiKey, token); | |
var publisher; | |
function sessionConnectedHandler(event) { | |
publisher = TB.initPublisher(apiKey, 'videobox'); | |
session.publish(publisher); | |
// Subscribe to streams that were in the session when we connected | |
subscribeToStreams(event.streams); | |
} | |
function streamCreatedHandler(event) { | |
// Subscribe to any new streams that are created | |
subscribeToStreams(event.streams); | |
} | |
function subscribeToStreams(streams) { | |
for (var i = 0; i < streams.length; i++) { | |
// Make sure we don't subscribe to ourself | |
if (streams[i].connection.connectionId == session.connection.connectionId) { | |
return; | |
} | |
// Create the div to put the subscriber element in to | |
var div = document.createElement('div'); | |
div.setAttribute('id', 'stream' + streams[i].streamId); | |
document.body.appendChild(div); | |
// Subscribe to the stream | |
session.subscribe(streams[i], div.id); | |
} | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RoomsController < ApplicationController | |
before_filter :config_opentok,:except => [:index] | |
def index | |
@rooms = Room.where(:public => true).order("created_at DESC") | |
@new_room = Room.new | |
end | |
def create | |
session_properties = {OpenTok::SessionPropertyConstants::P2P_PREFERENCE => "enabled"} | |
@location = 'localhost' | |
session = @opentok.create_session(@location, session_properties) | |
params[:room][:sessionId] = session.session_id | |
@new_room = Room.new(params[:room]) | |
respond_to do |format| | |
if @new_room.save | |
format.html { redirect_to("/party/"+@new_room.id.to_s) } | |
else | |
format.html { render :controller => 'rooms', | |
:action => "index" } | |
end | |
end | |
end | |
def party | |
@room = Room.find(params[:id]) | |
@tok_token = @opentok.generate_token :session_id =>@room.sessionId | |
end | |
private | |
def config_opentok | |
if @opentok.nil? | |
@opentok = OpenTok::OpenTokSDK.new xxxxx102, "Xxxxbae5xxxx9dd1xx8xx62784210badb92" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= f.submit "Connect",:class=>'btn btn-success' %> | |
##This is to connect to the user on the other side. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment