use result of eval script expression for match. expression examples: protocol bigger than 5 : c.protocol > 5 browser if firefox: c.browser == "firefox" combined rule : c.protocol > 5 && c.browser == "firefox"
(clientInfo *livekit.ClientInfo)
| 52 | // browser if firefox: c.browser == "firefox" |
| 53 | // combined rule : c.protocol > 5 && c.browser == "firefox" |
| 54 | func (m *ScriptMatch) Match(clientInfo *livekit.ClientInfo) (bool, error) { |
| 55 | clone := m.compiled.Clone() |
| 56 | if err := clone.Set("c", &clientObject{info: clientInfo}); err != nil { |
| 57 | return false, err |
| 58 | } |
| 59 | if err := clone.Run(); err != nil { |
| 60 | return false, err |
| 61 | } |
| 62 | |
| 63 | res := clone.Get("__res__").Value() |
| 64 | if val, ok := res.(bool); ok { |
| 65 | return val, nil |
| 66 | } |
| 67 | return false, errors.New("invalid match expression result") |
| 68 | } |
| 69 | |
| 70 | // ------------------------------------------------ |
| 71 |