-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.rb
61 lines (54 loc) · 1.43 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'rubygems'
require 'sinatra'
require 'opentok'
require 'httparty'
require 'json'
OTKey = ENV['TB_KEY'] # Enter you OpenTok Key Here
OTSecret = ENV['TB_SECRET'] # Enter your OpenTok Secret Here
FPKey = ENV['FP_KEY_OpenTokPicker'] # Enter your FilePicker key Here
OTSDK = OpenTok::OpenTokSDK.new OTKey, OTSecret
get '/' do
session = OTSDK.createSession(request.ip)
redirect "/#{session}"
end
post '/archive/:aid' do
token= params['token']
aid= params[:aid]
p token
otArchive = OTSDK.get_archive_manifest(aid, token)
p otArchive
content_type :json
if otArchive.resources.length < 2
otVideoResource = otArchive.resources[0]
videoId = otVideoResource.getId()
url = otArchive.downloadArchiveURL(videoId, token)
printa url
if url.split('http').length > 1
printa url.split('http')
return {:status=>"success", :url=>url}.to_json
end
else
response = OTSDK.stitchArchive(aid)
if response[:code]==201
printa response
return {:status=>"success", :url=>response[:location]}.to_json
end
return {:status=>"fail"}.to_json
end
end
get '/:session' do
@key = OTKey
@FPKey = FPKey
@session = params[:session]
@token = OTSDK.generateToken( {:session_id=> @session, :role=>OpenTok::RoleConstants::MODERATOR, :expire_time=>Time.now.to_i + 604800} )
erb :index
end
def printa a
p "========"
p "========"
p "========"
p a
p "========"
p "========"
p "========"
end