Add flag to use webhooks and API call to register a hook

It almost works with webhooks now. Still TODO is:
* Remove the hook after the recording is published
* To process the publish_ended event from the webhooks either the webhook
  needs to include the metadata (currently it doesn't) or GreenLight has
  find out the meeting token without reading it from the metadata.
This commit is contained in:
Leonardo Crauss Daronco
2016-12-08 14:01:57 -02:00
parent 906b21ab0e
commit 09c30bb5bd
3 changed files with 59 additions and 12 deletions

View File

@ -78,9 +78,13 @@ module BbbApi
"meta_#{BbbApi::META_TOKEN}": meeting_token
}
meeting_options.merge!(
{ "meta_#{BbbApi::META_HOOK_URL}": options[:hook_url] }
) if options[:hook_url]
if ENV['GREENLIGHT_USE_WEBHOOKS']
webhook_register(options[:hook_url], meeting_id)
else
meeting_options.merge!(
{ "meta_#{BbbApi::META_HOOK_URL}": options[:hook_url] }
) if options[:hook_url]
end
# Create the meeting
bbb.create_meeting(options[:meeting_name], meeting_id, meeting_options)
@ -253,6 +257,26 @@ module BbbApi
}
end
def webhook_register(url, meeting_id=nil)
params = { callbackURL: url }
params.merge!({ meetingID: meeting_id }) if meeting_id.present?
bbb_safe_execute :send_api_request, "hooks/create", params
end
def webhook_remove(url)
res = bbb_safe_execute :send_api_request, "hooks/list"
if res && res[:hooks] && res[:hooks][:hook]
res[:hooks][:hook] = [res[:hooks][:hook]] unless res[:hooks][:hook].is_a?(Array)
hook = res[:hooks][:hook].select{ |h|
h[:callbackURL] == url
}.first
if hook.present?
params = { hookID: hook[:hookID] }
bbb_safe_execute :send_api_request, "hooks/destroy", params
end
end
end
def success_join_res(join_url)
{
returncode: true,