Skip to content

Instantly share code, notes, and snippets.

@Yardanico
Created August 21, 2017 18:38
Show Gist options
  • Save Yardanico/e15182322ae9706339686c3fc4562c7b to your computer and use it in GitHub Desktop.
Save Yardanico/e15182322ae9706339686c3fc4562c7b to your computer and use it in GitHub Desktop.
proc gen_event(ad: AddressDirection) {.async.} =
let href = ("http://$1:$2/sub$3" % [ cts.host, $cts.port, $sid ])
let ev = %* CallEventNotification(
callingParticipant: calling,
calledParticipant: called,
eventDescription: EventDescription(callEvent: evtype),
notificationType: "callEvent",
callSessionIdentifier: $ id,
addressDirection: ad,
link: Link(rel: "callEventSubscription", href: href)
)
let evp = ev.pretty()
debug("tx> " & evp)
let url = ces.callbackReference.notifyURL
let c = newAsyncHttpCLient()
let req = c.post(url, body = evp)
if await withTimeout(req, 1000):
yield req
if req.failed:
# do stuff
let r = req.read()
if r.code() != Http204:
error r.status
else:
debug "rx> " & await r.body
else:
warn("timeout")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment