forked from mkenney/go-chrome
/
cdtp.io.go
93 lines (77 loc) · 2.22 KB
/
cdtp.io.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package socket
import (
"encoding/json"
"github.com/mkenney/go-chrome/tot/io"
)
/*
IOProtocol provides a namespace for the Chrome IO protocol methods. The IO
protocol provides input/output operations for streams produced by DevTools.
https://chromedevtools.github.io/devtools-protocol/tot/IO/
*/
type IOProtocol struct {
Socket Socketer
}
/*
Close closes the stream and discards any temporary backing storage.
https://chromedevtools.github.io/devtools-protocol/tot/IO/#method-close
*/
func (protocol *IOProtocol) Close(
params *io.CloseParams,
) <-chan *io.CloseResult {
resultChan := make(chan *io.CloseResult)
command := NewCommand(protocol.Socket, "IO.close", params)
result := &io.CloseResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
Read reads a chunk of the stream.
https://chromedevtools.github.io/devtools-protocol/tot/IO/#method-read
*/
func (protocol *IOProtocol) Read(
params *io.ReadParams,
) <-chan *io.ReadResult {
resultChan := make(chan *io.ReadResult)
command := NewCommand(protocol.Socket, "IO.read", params)
result := &io.ReadResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
ResolveBlob returns the UUID of Blob object specified by a remote object id.
https://chromedevtools.github.io/devtools-protocol/tot/IO/#method-resolveBlob
*/
func (protocol *IOProtocol) ResolveBlob(
params *io.ResolveBlobParams,
) <-chan *io.ResolveBlobResult {
resultChan := make(chan *io.ResolveBlobResult)
command := NewCommand(protocol.Socket, "IO.resolveBlob", params)
result := &io.ResolveBlobResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}