6 "github.com/libp2p/go-libp2p-peer"
9 // Message is a pubsub message.
17 // PubSubSubscription allow you to receive pubsub records that where published on the network.
18 type PubSubSubscription struct {
22 func newPubSubSubscription(resp *Response) *PubSubSubscription {
23 sub := &PubSubSubscription{
30 // Next waits for the next record and returns that.
31 func (s *PubSubSubscription) Next() (*Message, error) {
32 if s.resp.Error != nil {
33 return nil, s.resp.Error
36 d := json.NewDecoder(s.resp.Output)
39 From []byte `json:"from,omitempty"`
40 Data []byte `json:"data,omitempty"`
41 Seqno []byte `json:"seqno,omitempty"`
42 TopicIDs []string `json:"topicIDs,omitempty"`
50 from, err := peer.IDFromBytes(r.From)
62 // Cancel cancels the given subscription.
63 func (s *PubSubSubscription) Cancel() error {
64 if s.resp.Output == nil {
68 return s.resp.Output.Close()