MCPcopy
hub / github.com/livekit/livekit / Match

Method Match

pkg/clientconfiguration/match.go:54–68  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

52// browser if firefox: c.browser == "firefox"
53// combined rule : c.protocol > 5 && c.browser == "firefox"
54func (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

Callers 1

TestScriptMatchFunction · 0.95

Calls 3

CloneMethod · 0.65
RunMethod · 0.45
GetMethod · 0.45

Tested by 1

TestScriptMatchFunction · 0.76