This repository has been archived by the owner on Aug 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
voximplant_bitcode.rb
141 lines (113 loc) · 3.84 KB
/
voximplant_bitcode.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
class Voximplant
require 'fileutils'
require 'colorize'
require 'net/http'
require 'uri'
require 'zip'
require 'progressbar'
$voximplant_verified = false
private
def self.create_directories(pods_path)
sdk_path = "#{pods_path}/VoxImplantSDK"
webrtc_path = "#{pods_path}/VoxImplantWebRTC"
unless FileTest.exists?(sdk_path)
puts "Creating #{sdk_path} directory...".yellow
FileUtils.mkdir_p(sdk_path)
end
unless FileTest.exists?(webrtc_path)
puts "Creating #{webrtc_path} directory...".yellow
FileUtils.mkdir_p(webrtc_path)
end
end
private
def self.download(title, url, out)
url_base = url.split('/')[2]
url_path = '/' + url.split('/')[3..-1].join('/')
counter = 0
Net::HTTP.start(url_base) do |http|
response = http.request_head(URI.escape(url_path))
unless response.code == "200"
raise "Failed to download #{title}!".red
end
pbar = ProgressBar.create(:title => title, :total => response['content-length'].to_i)
File.open(out, 'w') { |f|
http.get(URI.escape(url_path)) do |str|
f.write str
counter += str.length
pbar.progress = counter
end
}
pbar.finish
end
end
private
def self.extract_zip(file, destination)
if FileTest.exist?(destination)
FileUtils.rm_rf(destination)
end
FileUtils.mkdir_p(destination)
Zip::File.open(file) do |zip_file|
zip_file.each do |f|
fpath = File.join(destination, f.name)
zip_file.extract(f, fpath) unless File.exist?(fpath)
end
end
end
private
def self.check_sdk_version(pods_path, sdk_version)
sdk_path = "#{pods_path}/VoxImplantSDK"
begin
spec = Pod::Specification.from_file("#{sdk_path}/VoxImplantSDK.podspec")
unless spec.version.to_s == sdk_version.to_s
puts "Version mismatch: found #{spec.version}, required #{sdk_version}".red
raise "Version mismatch"
end
webrtc = nil
spec.subspecs.find do |subspec|
webrtc = subspec.dependencies.find do |dep|
dep.name == "VoxImplantWebRTC"
end
end
webrtc_version = Pod::Requirement.parse(webrtc.requirement)[1]
puts "Voximplant iOS SDK v#{sdk_version} ... OK".green
return webrtc_version
rescue
puts "Downloading Voximplant iOS SDK v#{sdk_version}".yellow
url = "https://s3.eu-central-1.amazonaws.com/voximplant-releases/ios-sdk/#{sdk_version}/VoxImplant_bitcode.zip"
zip = "#{pods_path}/VoxImplantSDK.zip"
download "Voximpant iOS SDK", url, zip
puts "Unpacking".yellow
extract_zip zip, sdk_path
return check_sdk_version pods_path, sdk_version
end
end
private
def self.check_webrtc_version(pods_path, webrtc_version)
webrtc_path = "#{pods_path}/VoxImplantWebRTC"
begin
spec = Pod::Specification.from_file("#{webrtc_path}/VoxImplantWebRTC.podspec")
if spec.version != webrtc_version
puts "Version mismatch: found #{spec.version}, required #{webrtc_version}".red
raise "Version mismatch"
end
rescue
puts "Downloading VoximplantWebRTC v#{webrtc_version}".yellow
url = "https://s3.eu-central-1.amazonaws.com/voximplant-releases/ios-webrtc/#{webrtc_version}/VoxImplantWebRTC_bitcode.zip"
zip = "#{pods_path}/VoxImplantWebRTC.zip"
download "Voximpant WebRTC", url, zip
puts "Unpacking".yellow
extract_zip zip, webrtc_path
end
puts "Voximplant WebRTC v#{webrtc_version} ... OK".green
end
def self.prepare_voximplant_pods(sdk_version)
unless $voximplant_verified
puts "Verifying Voximplant Pods"
pods_path = "./Pods"
create_directories pods_path
webrtc_version = check_sdk_version pods_path, sdk_version
check_webrtc_version pods_path, webrtc_version
$voximplant_verified = true
end
end
end