Download this file
| 1 | package bridge |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/calls/callscore" |
| 5 | "context" |
| 6 | "encoding/json" |
| 7 | ) |
| 8 | |
| 9 | type Authentication struct{ auth *callscore.Authentication } |
| 10 | |
| 11 | func BeginAuthentication(address string) (*Authentication, error) { |
| 12 | a, e := callscore.BeginAuthentication(context.Background(), address) |
| 13 | if e != nil { |
| 14 | return nil, e |
| 15 | } |
| 16 | return &Authentication{auth: a}, nil |
| 17 | } |
| 18 | |
| 19 | // BeginOfferAuthentication is the handoff for a link from the web's |
| 20 | // "Join in the app", which carries the offer its browser made: that |
| 21 | // browser asks the person to confirm, so the app opens none. See |
| 22 | // callscore.BeginOfferAuthentication. |
| 23 | func BeginOfferAuthentication(address, offer string) (*Authentication, error) { |
| 24 | a, e := callscore.BeginOfferAuthentication(context.Background(), address, offer) |
| 25 | if e != nil { |
| 26 | return nil, e |
| 27 | } |
| 28 | return &Authentication{auth: a}, nil |
| 29 | } |
| 30 | func (a *Authentication) BrowserURL() string { return a.auth.BrowserURL() } |
| 31 | func (a *Authentication) Cancel() { a.auth.Cancel() } |
| 32 | func (a *Authentication) Wait() (string, error) { |
| 33 | r, e := a.auth.Wait() |
| 34 | if e != nil { |
| 35 | return "", e |
| 36 | } |
| 37 | b, e := json.Marshal(r) |
| 38 | return string(b), e |
| 39 | } |
| 40 | |
| 41 | func (a *Authentication) ConfirmationCode() string { return a.auth.ConfirmationCode() } |
| 42 | |