diff options
| author | mo khan <mo@mokhan.ca> | 2025-05-14 13:18:54 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-05-14 13:18:54 -0600 |
| commit | 4b2d609a0efcc1d9b2f1a08f954d067ad1d9cd1e (patch) | |
| tree | 0afacf9217b0569130da6b97d4197331681bf119 /vendor/github.com/playwright-community/playwright-go/jsonPipe.go | |
| parent | ab373d1fe698cd3f53258c09bc8515d88a6d0b9e (diff) | |
test: use playwright to test out an OIDC login
Diffstat (limited to 'vendor/github.com/playwright-community/playwright-go/jsonPipe.go')
| -rw-r--r-- | vendor/github.com/playwright-community/playwright-go/jsonPipe.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/vendor/github.com/playwright-community/playwright-go/jsonPipe.go b/vendor/github.com/playwright-community/playwright-go/jsonPipe.go new file mode 100644 index 0000000..e6c0e79 --- /dev/null +++ b/vendor/github.com/playwright-community/playwright-go/jsonPipe.go @@ -0,0 +1,64 @@ +package playwright + +import ( + "encoding/json" + "errors" + "fmt" +) + +type jsonPipe struct { + channelOwner + msgChan chan *message +} + +func (j *jsonPipe) Send(message map[string]interface{}) error { + _, err := j.channel.Send("send", map[string]interface{}{ + "message": message, + }) + return err +} + +func (j *jsonPipe) Close() error { + _, err := j.channel.Send("close") + return err +} + +func (j *jsonPipe) Poll() (*message, error) { + msg := <-j.msgChan + if msg == nil { + return nil, errors.New("jsonPipe closed") + } + return msg, nil +} + +func newJsonPipe(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *jsonPipe { + j := &jsonPipe{ + msgChan: make(chan *message, 2), + } + j.createChannelOwner(j, parent, objectType, guid, initializer) + j.channel.On("message", func(ev map[string]interface{}) { + var msg message + m, err := json.Marshal(ev["message"]) + if err == nil { + err = json.Unmarshal(m, &msg) + } + if err != nil { + msg = message{ + Error: &struct { + Error Error "json:\"error\"" + }{ + Error: Error{ + Name: "Error", + Message: fmt.Sprintf("jsonPipe: could not decode message: %s", err.Error()), + }, + }, + } + } + j.msgChan <- &msg + }) + j.channel.Once("closed", func() { + j.Emit("closed") + close(j.msgChan) + }) + return j +} |
