Module: ORTC
- Defined in:
- lib/ortc.rb,
lib/ortc/ortc_extensibility.rb
Defined Under Namespace
Classes: Channel, MultiMessage, OrtcClient
Constant Summary collapse
- MAX_CHANNEL_NAME_SIZE =
100
- MAX_MESSAGE_SIZE =
800
- MAX_HEARTBEAT_INTERVAL =
30
- RECONNECT_INTERVAL =
5
- MAX_CONNECTION_METADATA_SIZE =
255
Class Method Summary collapse
- ._get_cluster(url) ⇒ Object
-
.disable_presence(url, is_cluster, application_key, private_key, channel, &block) ⇒ Object
Disables presence for the specified channel.
-
.enable_presence(url, is_cluster, application_key, private_key, channel, metadata, &block) ⇒ Object
Enables presence for the specified channel with first 100 unique metadata if true.
-
.presence(url, is_cluster, application_key, authentication_token, channel, &block) ⇒ Object
Gets a Hash table indicating the subscriptions in the specified channel and if active the first 100 unique metadata.
Class Method Details
._get_cluster(url) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/ortc.rb', line 232 def self._get_cluster(url) begin uri = URI.parse(url) if http = Net::HTTP.new(uri.host, uri.port) if url.include? 'https' http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end uri = URI.parse(url<< "?appkey=#{@app_key}") http.start do |http| request = Net::HTTP::Get.new(uri.request_uri) response = http.request(request) response.body.scan(/"(.*?)"/).join end end rescue Timeout::ExitException return '' rescue Timeout::Error return '' rescue => e return '' end end |
.disable_presence(url, is_cluster, application_key, private_key, channel, &block) ⇒ Object
Disables presence for the specified channel.
Note: This method will send your Private Key over the Internet. Make sure to use secure connection.
-
url - Server containing the presence service
-
is_cluster - Indicates whether the url is in a cluster.
-
application_key - Application key with access to presence service
-
private_key - The private key provided when the ORTC service is purchased.
-
channel - Channel to disable presence.
-
&block - Callback with error and result parameters.
Usage: ORTC.disable_presence(ortc_url, true, ortc_app_key, ortc_private_key, channel) { |error, result|
if error.to_s.empty?
puts "result: #{result}"
else
puts "error: #{error}"
end
}
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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ortc.rb', line 108 def self.disable_presence(url, is_cluster, application_key, private_key, channel, &block) if url.to_s.empty? block.call('URL is null or empty', nil) elsif application_key.to_s.empty? block.call('Application Key is null or empty', nil) elsif private_key.to_s.empty? block.call('Private key is null or empty', nil) elsif channel.to_s.empty? block.call('Channel is null or empty', nil) elsif not channel =~ /^[\w\-:\/.]+$/ block.call('Channel has invalid characters', nil) else begin r_thread = Thread.new { server = '' if is_cluster server = _get_cluster(url) begin block.call('Can not connect with the server', nil) r_thread.exit end if server == '' else server = url.clone end server = server << (server.match(/\/$/) ? 'presence' : '/presence') server = server << "/disable/#{application_key}/#{channel}" body = "privatekey=#{private_key}" uri = URI.parse(server) begin if http = Net::HTTP.new(uri.host, uri.port) if server.match /^https/ http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end req = Net::HTTP::Post.new(uri.request_uri) req.body = body res = http.request(req) if res.code == '200' block.call(nil, res.body) else block.call(res.body, nil) end end rescue => e block.call(e, nil) r_thread.exit end } r_thread.run end end end |
.enable_presence(url, is_cluster, application_key, private_key, channel, metadata, &block) ⇒ Object
Enables presence for the specified channel with first 100 unique metadata if true.
Note: This method will send your Private Key over the Internet. Make sure to use secure connection.
-
url - Server containing the presence service
-
is_cluster - Indicates whether the url is in a cluster.
-
application_key - Application key with access to presence service
-
private_key - The private key provided when the ORTC service is purchased.
-
channel - Channel to activate presence.
-
metadata - Defines if to collect first 100 unique metadata.
-
&block - Callback with error and result parameters.
Usage: ORTC.enable_presence(ortc_url, true, ortc_app_key, ortc_private_key, channel, true) { |error, result|
if error.to_s.empty?
puts "result: #{result}"
else
puts "error: #{error}"
end
}
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 |
# File 'lib/ortc.rb', line 37 def self.enable_presence(url, is_cluster, application_key, private_key, channel, , &block) if url.to_s.empty? block.call('URL is null or empty', nil) elsif application_key.to_s.empty? block.call('Application Key is null or empty', nil) elsif private_key.to_s.empty? block.call('Private key is null or empty', nil) elsif channel.to_s.empty? block.call('Channel is null or empty', nil) elsif not channel =~ /^[\w\-:\/.]+$/ block.call('Channel has invalid characters', nil) else begin r_thread = Thread.new { server = '' if is_cluster server = _get_cluster(url) begin block.call('Can not connect with the server', nil) r_thread.exit end if server == '' else server = url.clone end server = server << (server.match(/\/$/) ? 'presence' : '/presence') server = server << "/enable/#{application_key}/#{channel}" body = "privatekey=#{private_key}&metadata=" << ( ? '1' : '0') uri = URI.parse(server) begin if http = Net::HTTP.new(uri.host, uri.port) if server.match /^https/ http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end req = Net::HTTP::Post.new(uri.request_uri) req.body = body res = http.request(req) if res.code == '200' block.call(nil, res.body) else Block.call(res.body, nil) end end rescue => e block.call(e, nil) r_thread.exit end } r_thread.run end end end |
.presence(url, is_cluster, application_key, authentication_token, channel, &block) ⇒ Object
Gets a Hash table indicating the subscriptions in the specified channel and if active the first 100 unique metadata.
-
url - Server containing the presence service
-
is_cluster - Indicates whether the url is in a cluster.
-
application_key - Application key with access to presence service
-
authentication_token - Authentication token with access to presence service
-
channel - Channel to presence data active.
-
&block - Callback with error and result parameters.
Usage: ORTC.presence(ortc_url, true, ortc_app_key, ortc_auth_token, channel) { |error, result|
if error.to_s.empty?
puts "result: #{result}"
else
puts "error: #{error}"
end
}
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/ortc.rb', line 177 def self.presence(url, is_cluster, application_key, authentication_token, channel, &block) if url.to_s.empty? block.call('URL is null or empty', nil) elsif application_key.to_s.empty? block.call('Application Key is null or empty', nil) elsif authentication_token.to_s.empty? block.call('Authentication Token is null or empty', nil) elsif channel.to_s.empty? block.call('Channel is null or empty', nil) elsif not channel =~ /^[\w\-:\/.]+$/ block.call('Channel has invalid characters', nil) else begin r_thread = Thread.new { server = '' if is_cluster server = _get_cluster(url) begin block.call('Can not connect with the server', nil) r_thread.exit end if server == '' else server = url.clone end server = server << (server.match(/\/$/) ? 'presence' : '/presence') server = server << "/#{application_key}/#{authentication_token}/#{channel}" #body = "privatekey=#{private_key}" uri = URI.parse(server) begin if http = Net::HTTP.new(uri.host, uri.port) if server.match /^https/ http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end req = Net::HTTP::Get.new(uri.request_uri) res = http.request(req) if res.code == '200' ret = Hash.new ret = JSON.parse(res.body) if not res.body == 'null' block.call(nil, ret) else block.call(res.body, nil) end end rescue => e block.call(e, nil) r_thread.exit end } r_thread.run end end end |