mirror of
https://github.com/MontFerret/ferret.git
synced 2025-04-13 11:50:30 +02:00
* Refactored networking * Some work * Added event loop * Renamed EventHandler to Handler * wip * Removed console logs * Added DOMManager * Refactored frame managment * Fixes * Fixed concurrency issues * Fixed unit tests * Improved EventLoop api * Some fixes * Refactored event loop. * Improved logic of initial page load * Cleaned up * Fixed linting issues * Fixed dom.Manager.Close * SOme works * Fixes * Removed fmt.Println statements * Refactored WaitForNavigation * Removed filter for e2e tests * Made Cookies Measurable * Made Cookies KeyedCollection * Fixes after code review * Updated e2e tests for iframes * Fixed iframe lookup in e2e tests * Added comments
75 lines
1.4 KiB
Go
75 lines
1.4 KiB
Go
package events
|
|
|
|
import (
|
|
"github.com/mafredri/cdp/rpcc"
|
|
)
|
|
|
|
type (
|
|
// ID represents a unique event ID
|
|
ID int
|
|
|
|
// Event represents a system event that is returned from an event source
|
|
Event struct {
|
|
ID ID
|
|
Data interface{}
|
|
}
|
|
|
|
// Source represents a custom source of system events
|
|
Source interface {
|
|
rpcc.Stream
|
|
Recv() (Event, error)
|
|
}
|
|
|
|
// GenericSource represents a helper struct for generating custom event sources
|
|
GenericSource struct {
|
|
eventID ID
|
|
stream rpcc.Stream
|
|
recv func(stream rpcc.Stream) (interface{}, error)
|
|
}
|
|
)
|
|
|
|
var (
|
|
Error = New("error")
|
|
)
|
|
|
|
// NewSource create a new custom event source
|
|
// eventID - is a unique event ID
|
|
// stream - is a custom event stream
|
|
// recv - is a value conversion function
|
|
func NewSource(
|
|
eventID ID,
|
|
stream rpcc.Stream,
|
|
recv func(stream rpcc.Stream) (interface{}, error),
|
|
) Source {
|
|
return &GenericSource{eventID, stream, recv}
|
|
}
|
|
|
|
func (src *GenericSource) EventID() ID {
|
|
return src.eventID
|
|
}
|
|
|
|
func (src *GenericSource) Ready() <-chan struct{} {
|
|
return src.stream.Ready()
|
|
}
|
|
|
|
func (src *GenericSource) RecvMsg(m interface{}) error {
|
|
return src.stream.RecvMsg(m)
|
|
}
|
|
|
|
func (src *GenericSource) Close() error {
|
|
return src.stream.Close()
|
|
}
|
|
|
|
func (src *GenericSource) Recv() (Event, error) {
|
|
data, err := src.recv(src.stream)
|
|
|
|
if err != nil {
|
|
return Event{}, err
|
|
}
|
|
|
|
return Event{
|
|
ID: src.eventID,
|
|
Data: data,
|
|
}, nil
|
|
}
|