Skip to content

Commit

Permalink
Integrate BroadcastEvent into DocEvent and filter event at client side
Browse files Browse the repository at this point in the history
  • Loading branch information
sejongk committed Sep 13, 2023
1 parent de2ee7d commit 5bf5466
Show file tree
Hide file tree
Showing 19 changed files with 694 additions and 2,166 deletions.
2 changes: 2 additions & 0 deletions api/converter/from_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ func FromEventType(pbDocEventType api.DocEventType) (types.DocEventType, error)
return types.DocumentWatchedEvent, nil
case api.DocEventType_DOC_EVENT_TYPE_DOCUMENT_UNWATCHED:
return types.DocumentUnwatchedEvent, nil
case api.DocEventType_DOC_EVENT_TYPE_DOCUMENT_BROADCAST:
return types.DocumentBroadcastEvent, nil
}
return "", fmt.Errorf("%v: %w", pbDocEventType, ErrUnsupportedEventType)
}
Expand Down
2 changes: 2 additions & 0 deletions api/converter/to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ func ToDocEventType(eventType types.DocEventType) (api.DocEventType, error) {
return api.DocEventType_DOC_EVENT_TYPE_DOCUMENT_WATCHED, nil
case types.DocumentUnwatchedEvent:
return api.DocEventType_DOC_EVENT_TYPE_DOCUMENT_UNWATCHED, nil
case types.DocumentBroadcastEvent:
return api.DocEventType_DOC_EVENT_TYPE_DOCUMENT_BROADCAST, nil
default:
return 0, fmt.Errorf("%s: %w", eventType, ErrUnsupportedEventType)
}
Expand Down
27 changes: 10 additions & 17 deletions api/types/event.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
package types

import "github.com/yorkie-team/yorkie/pkg/document/time"

// DocEvent represents events that occur related to the document.
type DocEvent struct {
Type DocEventType
Publisher *time.ActorID
DocumentID ID
}

// BroadcastEvent represents events that are delievered to broadcast
// event subscribers.
type BroadcastEvent struct {
Type string
Publisher *time.ActorID
Payload []byte
}

// DocEventType represents the event that the Server delivers to the client.
type DocEventType string

Expand All @@ -32,4 +15,14 @@ const (
// DocumentUnwatchedEvent is an event that occurs when document is
// unwatched by other clients.
DocumentUnwatchedEvent DocEventType = "document-unwatched"

// DocumentBroadcastEvent is an event that occurs when a payload is broadcasted
// on a specific topic.
DocumentBroadcastEvent DocEventType = "document-broadcast"
)

// DocEventBody includes additional data specific to the DocEvent.
type DocEventBody struct {
Topic string
Payload []byte
}
593 changes: 303 additions & 290 deletions api/yorkie/v1/resources.pb.go

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions api/yorkie/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,16 @@ enum DocEventType {
DOC_EVENT_TYPE_DOCUMENT_CHANGED = 0;
DOC_EVENT_TYPE_DOCUMENT_WATCHED = 1;
DOC_EVENT_TYPE_DOCUMENT_UNWATCHED = 2;
DOC_EVENT_TYPE_DOCUMENT_BROADCAST = 3;
}

message DocEvent {
DocEventType type = 1;
string publisher = 2;
message DocEventBody {
string topic = 1;
bytes payload = 2;
}

message BroadcastEvent {
string type = 1;
message DocEvent {
DocEventType type = 1;
string publisher = 2;
bytes payload = 3;
DocEventBody body = 3;
}
Loading

0 comments on commit 5bf5466

Please sign in to comment.