From 6ce80d1aecd6031ce0be4589490b1fe2816eeb88 Mon Sep 17 00:00:00 2001 From: zijiren233 Date: Fri, 10 May 2024 23:33:47 +0800 Subject: [PATCH] Feat: expire and reload bilibili live --- internal/cache/bilibili.go | 2 +- internal/op/movie.go | 12 +- proto/message/message.pb.go | 244 +++++++++++++---------------------- proto/message/message.proto | 11 +- server/handlers/websocket.go | 13 +- 5 files changed, 111 insertions(+), 171 deletions(-) diff --git a/internal/cache/bilibili.go b/internal/cache/bilibili.go index 98dc731..801d227 100644 --- a/internal/cache/bilibili.go +++ b/internal/cache/bilibili.go @@ -371,7 +371,7 @@ func NewBilibiliMovieCache(movie *model.Movie) *BilibiliMovieCache { NoSharedMovie: newMapCache(NewBilibiliNoSharedMovieCacheInitFunc(movie), time.Minute*60), SharedMpd: refreshcache.NewRefreshCache(NewBilibiliSharedMpdCacheInitFunc(movie), time.Minute*60), Subtitle: refreshcache.NewRefreshCache(NewBilibiliSubtitleCacheInitFunc(movie), 0), - Live: refreshcache.NewRefreshCache(NewBilibiliLiveCacheInitFunc(movie), 0), + Live: refreshcache.NewRefreshCache(NewBilibiliLiveCacheInitFunc(movie), time.Minute*55), } } diff --git a/internal/op/movie.go b/internal/op/movie.go index ae64cd4..4556cfc 100644 --- a/internal/op/movie.go +++ b/internal/op/movie.go @@ -38,10 +38,10 @@ func (m *Movie) ExpireId() uint64 { if amcd != nil && amcd.Ali != nil { return uint64(m.AlistCache().Last()) } - fallthrough - default: - return uint64(crc32.ChecksumIEEE([]byte(m.Movie.ID))) + case m.Movie.Base.Live && m.Movie.Base.VendorInfo.Vendor == model.VendorBilibili: + return uint64(m.BilibiliCache().Live.Last()) } + return uint64(crc32.ChecksumIEEE([]byte(m.Movie.ID))) } func (m *Movie) CheckExpired(expireId uint64) bool { @@ -51,10 +51,10 @@ func (m *Movie) CheckExpired(expireId uint64) bool { if amcd != nil && amcd.Ali != nil { return time.Now().UnixNano()-int64(expireId) > m.AlistCache().MaxAge() } - fallthrough - default: - return expireId != m.ExpireId() + case m.Movie.Base.Live && m.Movie.Base.VendorInfo.Vendor == model.VendorBilibili: + return time.Now().UnixNano()-int64(expireId) > m.BilibiliCache().Live.MaxAge() } + return expireId != m.ExpireId() } func (m *Movie) ClearCache() error { diff --git a/proto/message/message.pb.go b/proto/message/message.pb.go index d489671..7243ca9 100644 --- a/proto/message/message.pb.go +++ b/proto/message/message.pb.go @@ -28,7 +28,7 @@ const ( ElementMessageType_CHAT_MESSAGE ElementMessageType = 2 ElementMessageType_PLAY ElementMessageType = 3 ElementMessageType_PAUSE ElementMessageType = 4 - ElementMessageType_CHECK ElementMessageType = 5 + ElementMessageType_CHECK_STATUS ElementMessageType = 5 ElementMessageType_TOO_FAST ElementMessageType = 6 ElementMessageType_TOO_SLOW ElementMessageType = 7 ElementMessageType_CHANGE_RATE ElementMessageType = 8 @@ -38,6 +38,7 @@ const ( ElementMessageType_PEOPLE_CHANGED ElementMessageType = 12 ElementMessageType_SYNC_MOVIE_STATUS ElementMessageType = 13 ElementMessageType_CURRENT_EXPIRED ElementMessageType = 14 + ElementMessageType_CHECK_EXPIRED ElementMessageType = 15 ) // Enum value maps for ElementMessageType. @@ -48,7 +49,7 @@ var ( 2: "CHAT_MESSAGE", 3: "PLAY", 4: "PAUSE", - 5: "CHECK", + 5: "CHECK_STATUS", 6: "TOO_FAST", 7: "TOO_SLOW", 8: "CHANGE_RATE", @@ -58,6 +59,7 @@ var ( 12: "PEOPLE_CHANGED", 13: "SYNC_MOVIE_STATUS", 14: "CURRENT_EXPIRED", + 15: "CHECK_EXPIRED", } ElementMessageType_value = map[string]int32{ "UNKNOWN": 0, @@ -65,7 +67,7 @@ var ( "CHAT_MESSAGE": 2, "PLAY": 3, "PAUSE": 4, - "CHECK": 5, + "CHECK_STATUS": 5, "TOO_FAST": 6, "TOO_SLOW": 7, "CHANGE_RATE": 8, @@ -75,6 +77,7 @@ var ( "PEOPLE_CHANGED": 12, "SYNC_MOVIE_STATUS": 13, "CURRENT_EXPIRED": 14, + "CHECK_EXPIRED": 15, } ) @@ -333,61 +336,6 @@ func (x *MovieStatusChanged) GetStatus() *MovieStatus { return nil } -type CheckReq struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Status *MovieStatus `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"` - ExpireId uint64 `protobuf:"varint,2,opt,name=expireId,proto3" json:"expireId,omitempty"` -} - -func (x *CheckReq) Reset() { - *x = CheckReq{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_message_message_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CheckReq) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CheckReq) ProtoMessage() {} - -func (x *CheckReq) ProtoReflect() protoreflect.Message { - mi := &file_proto_message_message_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use CheckReq.ProtoReflect.Descriptor instead. -func (*CheckReq) Descriptor() ([]byte, []int) { - return file_proto_message_message_proto_rawDescGZIP(), []int{4} -} - -func (x *CheckReq) GetStatus() *MovieStatus { - if x != nil { - return x.Status - } - return nil -} - -func (x *CheckReq) GetExpireId() uint64 { - if x != nil { - return x.ExpireId - } - return 0 -} - type ElementMessage struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -401,7 +349,8 @@ type ElementMessage struct { ChangeMovieStatusReq *MovieStatus `protobuf:"bytes,6,opt,name=changeMovieStatusReq,proto3" json:"changeMovieStatusReq,omitempty"` MovieStatusChanged *MovieStatusChanged `protobuf:"bytes,7,opt,name=movieStatusChanged,proto3" json:"movieStatusChanged,omitempty"` ChangeSeekReq float64 `protobuf:"fixed64,8,opt,name=changeSeekReq,proto3" json:"changeSeekReq,omitempty"` - CheckReq *CheckReq `protobuf:"bytes,9,opt,name=checkReq,proto3" json:"checkReq,omitempty"` + CheckStatusReq *MovieStatus `protobuf:"bytes,9,opt,name=checkStatusReq,proto3" json:"checkStatusReq,omitempty"` + ExpireId uint64 `protobuf:"varint,10,opt,name=expireId,proto3" json:"expireId,omitempty"` PeopleChanged int64 `protobuf:"varint,11,opt,name=peopleChanged,proto3" json:"peopleChanged,omitempty"` MoviesChanged *Sender `protobuf:"bytes,12,opt,name=moviesChanged,proto3" json:"moviesChanged,omitempty"` CurrentChanged *Sender `protobuf:"bytes,13,opt,name=currentChanged,proto3" json:"currentChanged,omitempty"` @@ -410,7 +359,7 @@ type ElementMessage struct { func (x *ElementMessage) Reset() { *x = ElementMessage{} if protoimpl.UnsafeEnabled { - mi := &file_proto_message_message_proto_msgTypes[5] + mi := &file_proto_message_message_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -423,7 +372,7 @@ func (x *ElementMessage) String() string { func (*ElementMessage) ProtoMessage() {} func (x *ElementMessage) ProtoReflect() protoreflect.Message { - mi := &file_proto_message_message_proto_msgTypes[5] + mi := &file_proto_message_message_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -436,7 +385,7 @@ func (x *ElementMessage) ProtoReflect() protoreflect.Message { // Deprecated: Use ElementMessage.ProtoReflect.Descriptor instead. func (*ElementMessage) Descriptor() ([]byte, []int) { - return file_proto_message_message_proto_rawDescGZIP(), []int{5} + return file_proto_message_message_proto_rawDescGZIP(), []int{4} } func (x *ElementMessage) GetType() ElementMessageType { @@ -495,13 +444,20 @@ func (x *ElementMessage) GetChangeSeekReq() float64 { return 0 } -func (x *ElementMessage) GetCheckReq() *CheckReq { +func (x *ElementMessage) GetCheckStatusReq() *MovieStatus { if x != nil { - return x.CheckReq + return x.CheckStatusReq } return nil } +func (x *ElementMessage) GetExpireId() uint64 { + if x != nil { + return x.ExpireId + } + return 0 +} + func (x *ElementMessage) GetPeopleChanged() int64 { if x != nil { return x.PeopleChanged @@ -548,64 +504,64 @@ var file_proto_message_message_proto_rawDesc = []byte{ 0x65, 0x6e, 0x64, 0x65, 0x72, 0x52, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4d, 0x6f, 0x76, 0x69, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, - 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x52, 0x0a, 0x08, 0x43, 0x68, 0x65, - 0x63, 0x6b, 0x52, 0x65, 0x71, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4d, 0x6f, - 0x76, 0x69, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, - 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x49, 0x64, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x08, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x49, 0x64, 0x22, 0xa8, 0x04, - 0x0a, 0x0e, 0x45, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x12, 0x2d, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x19, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x4d, 0x65, - 0x73, 0x73, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, - 0x12, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, - 0x69, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x68, 0x61, - 0x74, 0x52, 0x65, 0x71, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x68, 0x61, 0x74, - 0x52, 0x65, 0x71, 0x12, 0x2b, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, - 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x52, 0x08, 0x63, 0x68, 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, - 0x12, 0x46, 0x0a, 0x14, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x4d, 0x6f, 0x76, 0x69, 0x65, 0x53, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4d, 0x6f, 0x76, 0x69, 0x65, 0x53, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x52, 0x14, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x4d, 0x6f, 0x76, 0x69, 0x65, 0x53, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x12, 0x49, 0x0a, 0x12, 0x6d, 0x6f, 0x76, 0x69, - 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x18, 0x07, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4d, 0x6f, 0x76, - 0x69, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x52, - 0x12, 0x6d, 0x6f, 0x76, 0x69, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x68, 0x61, 0x6e, - 0x67, 0x65, 0x64, 0x12, 0x24, 0x0a, 0x0d, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x53, 0x65, 0x65, - 0x6b, 0x52, 0x65, 0x71, 0x18, 0x08, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0d, 0x63, 0x68, 0x61, 0x6e, - 0x67, 0x65, 0x53, 0x65, 0x65, 0x6b, 0x52, 0x65, 0x71, 0x12, 0x2b, 0x0a, 0x08, 0x63, 0x68, 0x65, - 0x63, 0x6b, 0x52, 0x65, 0x71, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x52, 0x08, 0x63, 0x68, - 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x70, 0x65, 0x6f, 0x70, 0x6c, 0x65, - 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x70, - 0x65, 0x6f, 0x70, 0x6c, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x12, 0x33, 0x0a, 0x0d, - 0x6d, 0x6f, 0x76, 0x69, 0x65, 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x18, 0x0c, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x6e, 0x64, - 0x65, 0x72, 0x52, 0x0d, 0x6d, 0x6f, 0x76, 0x69, 0x65, 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x64, 0x12, 0x35, 0x0a, 0x0e, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x43, 0x68, 0x61, 0x6e, - 0x67, 0x65, 0x64, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x52, 0x0e, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, - 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x2a, 0x85, 0x02, 0x0a, 0x12, 0x45, 0x6c, 0x65, - 0x6d, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, - 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, - 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x01, 0x12, 0x10, 0x0a, 0x0c, 0x43, 0x48, 0x41, 0x54, 0x5f, - 0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x10, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x50, 0x4c, 0x41, - 0x59, 0x10, 0x03, 0x12, 0x09, 0x0a, 0x05, 0x50, 0x41, 0x55, 0x53, 0x45, 0x10, 0x04, 0x12, 0x09, - 0x0a, 0x05, 0x43, 0x48, 0x45, 0x43, 0x4b, 0x10, 0x05, 0x12, 0x0c, 0x0a, 0x08, 0x54, 0x4f, 0x4f, - 0x5f, 0x46, 0x41, 0x53, 0x54, 0x10, 0x06, 0x12, 0x0c, 0x0a, 0x08, 0x54, 0x4f, 0x4f, 0x5f, 0x53, - 0x4c, 0x4f, 0x57, 0x10, 0x07, 0x12, 0x0f, 0x0a, 0x0b, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, 0x5f, - 0x52, 0x41, 0x54, 0x45, 0x10, 0x08, 0x12, 0x0f, 0x0a, 0x0b, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, - 0x5f, 0x53, 0x45, 0x45, 0x4b, 0x10, 0x09, 0x12, 0x13, 0x0a, 0x0f, 0x43, 0x55, 0x52, 0x52, 0x45, - 0x4e, 0x54, 0x5f, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, 0x44, 0x10, 0x0a, 0x12, 0x12, 0x0a, 0x0e, - 0x4d, 0x4f, 0x56, 0x49, 0x45, 0x53, 0x5f, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, 0x44, 0x10, 0x0b, - 0x12, 0x12, 0x0a, 0x0e, 0x50, 0x45, 0x4f, 0x50, 0x4c, 0x45, 0x5f, 0x43, 0x48, 0x41, 0x4e, 0x47, - 0x45, 0x44, 0x10, 0x0c, 0x12, 0x15, 0x0a, 0x11, 0x53, 0x59, 0x4e, 0x43, 0x5f, 0x4d, 0x4f, 0x56, - 0x49, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x10, 0x0d, 0x12, 0x13, 0x0a, 0x0f, 0x43, - 0x55, 0x52, 0x52, 0x45, 0x4e, 0x54, 0x5f, 0x45, 0x58, 0x50, 0x49, 0x52, 0x45, 0x44, 0x10, 0x0e, - 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0xd3, 0x04, 0x0a, 0x0e, 0x45, 0x6c, + 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x2d, 0x0a, 0x04, + 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x19, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2e, 0x45, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, + 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x12, + 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, + 0x65, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x68, 0x61, 0x74, 0x52, 0x65, 0x71, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x68, 0x61, 0x74, 0x52, 0x65, 0x71, 0x12, + 0x2b, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x52, 0x08, 0x63, 0x68, 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x46, 0x0a, 0x14, + 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x4d, 0x6f, 0x76, 0x69, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x52, 0x65, 0x71, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2e, 0x4d, 0x6f, 0x76, 0x69, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x14, + 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x4d, 0x6f, 0x76, 0x69, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x52, 0x65, 0x71, 0x12, 0x49, 0x0a, 0x12, 0x6d, 0x6f, 0x76, 0x69, 0x65, 0x53, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4d, 0x6f, 0x76, 0x69, 0x65, 0x53, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x52, 0x12, 0x6d, 0x6f, 0x76, + 0x69, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x12, + 0x24, 0x0a, 0x0d, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x53, 0x65, 0x65, 0x6b, 0x52, 0x65, 0x71, + 0x18, 0x08, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0d, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x53, 0x65, + 0x65, 0x6b, 0x52, 0x65, 0x71, 0x12, 0x3a, 0x0a, 0x0e, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x53, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4d, 0x6f, 0x76, 0x69, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x52, 0x0e, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, + 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x49, 0x64, 0x18, 0x0a, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x08, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x49, 0x64, 0x12, 0x24, 0x0a, + 0x0d, 0x70, 0x65, 0x6f, 0x70, 0x6c, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x18, 0x0b, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x70, 0x65, 0x6f, 0x70, 0x6c, 0x65, 0x43, 0x68, 0x61, 0x6e, + 0x67, 0x65, 0x64, 0x12, 0x33, 0x0a, 0x0d, 0x6d, 0x6f, 0x76, 0x69, 0x65, 0x73, 0x43, 0x68, 0x61, + 0x6e, 0x67, 0x65, 0x64, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x52, 0x0d, 0x6d, 0x6f, 0x76, 0x69, 0x65, + 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x12, 0x35, 0x0a, 0x0e, 0x63, 0x75, 0x72, 0x72, + 0x65, 0x6e, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x0d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x52, + 0x0e, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x2a, + 0x9f, 0x02, 0x0a, 0x12, 0x45, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, + 0x4e, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x01, 0x12, 0x10, + 0x0a, 0x0c, 0x43, 0x48, 0x41, 0x54, 0x5f, 0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x10, 0x02, + 0x12, 0x08, 0x0a, 0x04, 0x50, 0x4c, 0x41, 0x59, 0x10, 0x03, 0x12, 0x09, 0x0a, 0x05, 0x50, 0x41, + 0x55, 0x53, 0x45, 0x10, 0x04, 0x12, 0x10, 0x0a, 0x0c, 0x43, 0x48, 0x45, 0x43, 0x4b, 0x5f, 0x53, + 0x54, 0x41, 0x54, 0x55, 0x53, 0x10, 0x05, 0x12, 0x0c, 0x0a, 0x08, 0x54, 0x4f, 0x4f, 0x5f, 0x46, + 0x41, 0x53, 0x54, 0x10, 0x06, 0x12, 0x0c, 0x0a, 0x08, 0x54, 0x4f, 0x4f, 0x5f, 0x53, 0x4c, 0x4f, + 0x57, 0x10, 0x07, 0x12, 0x0f, 0x0a, 0x0b, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, 0x5f, 0x52, 0x41, + 0x54, 0x45, 0x10, 0x08, 0x12, 0x0f, 0x0a, 0x0b, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, 0x5f, 0x53, + 0x45, 0x45, 0x4b, 0x10, 0x09, 0x12, 0x13, 0x0a, 0x0f, 0x43, 0x55, 0x52, 0x52, 0x45, 0x4e, 0x54, + 0x5f, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, 0x44, 0x10, 0x0a, 0x12, 0x12, 0x0a, 0x0e, 0x4d, 0x4f, + 0x56, 0x49, 0x45, 0x53, 0x5f, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, 0x44, 0x10, 0x0b, 0x12, 0x12, + 0x0a, 0x0e, 0x50, 0x45, 0x4f, 0x50, 0x4c, 0x45, 0x5f, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, 0x44, + 0x10, 0x0c, 0x12, 0x15, 0x0a, 0x11, 0x53, 0x59, 0x4e, 0x43, 0x5f, 0x4d, 0x4f, 0x56, 0x49, 0x45, + 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x10, 0x0d, 0x12, 0x13, 0x0a, 0x0f, 0x43, 0x55, 0x52, + 0x52, 0x45, 0x4e, 0x54, 0x5f, 0x45, 0x58, 0x50, 0x49, 0x52, 0x45, 0x44, 0x10, 0x0e, 0x12, 0x11, + 0x0a, 0x0d, 0x43, 0x48, 0x45, 0x43, 0x4b, 0x5f, 0x45, 0x58, 0x50, 0x49, 0x52, 0x45, 0x44, 0x10, + 0x0f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -621,33 +577,31 @@ func file_proto_message_message_proto_rawDescGZIP() []byte { } var file_proto_message_message_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_proto_message_message_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_proto_message_message_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_proto_message_message_proto_goTypes = []interface{}{ (ElementMessageType)(0), // 0: proto.ElementMessageType (*ChatResp)(nil), // 1: proto.ChatResp (*Sender)(nil), // 2: proto.Sender (*MovieStatus)(nil), // 3: proto.MovieStatus (*MovieStatusChanged)(nil), // 4: proto.MovieStatusChanged - (*CheckReq)(nil), // 5: proto.CheckReq - (*ElementMessage)(nil), // 6: proto.ElementMessage + (*ElementMessage)(nil), // 5: proto.ElementMessage } var file_proto_message_message_proto_depIdxs = []int32{ 2, // 0: proto.ChatResp.sender:type_name -> proto.Sender 2, // 1: proto.MovieStatusChanged.sender:type_name -> proto.Sender 3, // 2: proto.MovieStatusChanged.status:type_name -> proto.MovieStatus - 3, // 3: proto.CheckReq.status:type_name -> proto.MovieStatus - 0, // 4: proto.ElementMessage.type:type_name -> proto.ElementMessageType - 1, // 5: proto.ElementMessage.chatResp:type_name -> proto.ChatResp - 3, // 6: proto.ElementMessage.changeMovieStatusReq:type_name -> proto.MovieStatus - 4, // 7: proto.ElementMessage.movieStatusChanged:type_name -> proto.MovieStatusChanged - 5, // 8: proto.ElementMessage.checkReq:type_name -> proto.CheckReq - 2, // 9: proto.ElementMessage.moviesChanged:type_name -> proto.Sender - 2, // 10: proto.ElementMessage.currentChanged:type_name -> proto.Sender - 11, // [11:11] is the sub-list for method output_type - 11, // [11:11] is the sub-list for method input_type - 11, // [11:11] is the sub-list for extension type_name - 11, // [11:11] is the sub-list for extension extendee - 0, // [0:11] is the sub-list for field type_name + 0, // 3: proto.ElementMessage.type:type_name -> proto.ElementMessageType + 1, // 4: proto.ElementMessage.chatResp:type_name -> proto.ChatResp + 3, // 5: proto.ElementMessage.changeMovieStatusReq:type_name -> proto.MovieStatus + 4, // 6: proto.ElementMessage.movieStatusChanged:type_name -> proto.MovieStatusChanged + 3, // 7: proto.ElementMessage.checkStatusReq:type_name -> proto.MovieStatus + 2, // 8: proto.ElementMessage.moviesChanged:type_name -> proto.Sender + 2, // 9: proto.ElementMessage.currentChanged:type_name -> proto.Sender + 10, // [10:10] is the sub-list for method output_type + 10, // [10:10] is the sub-list for method input_type + 10, // [10:10] is the sub-list for extension type_name + 10, // [10:10] is the sub-list for extension extendee + 0, // [0:10] is the sub-list for field type_name } func init() { file_proto_message_message_proto_init() } @@ -705,18 +659,6 @@ func file_proto_message_message_proto_init() { } } file_proto_message_message_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CheckReq); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_message_message_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ElementMessage); i { case 0: return &v.state @@ -735,7 +677,7 @@ func file_proto_message_message_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_proto_message_message_proto_rawDesc, NumEnums: 1, - NumMessages: 6, + NumMessages: 5, NumExtensions: 0, NumServices: 0, }, diff --git a/proto/message/message.proto b/proto/message/message.proto index b0767c4..cbc0bd6 100644 --- a/proto/message/message.proto +++ b/proto/message/message.proto @@ -9,7 +9,7 @@ enum ElementMessageType { CHAT_MESSAGE = 2; PLAY = 3; PAUSE = 4; - CHECK = 5; + CHECK_STATUS = 5; TOO_FAST = 6; TOO_SLOW = 7; CHANGE_RATE = 8; @@ -19,6 +19,7 @@ enum ElementMessageType { PEOPLE_CHANGED = 12; SYNC_MOVIE_STATUS = 13; CURRENT_EXPIRED = 14; + CHECK_EXPIRED = 15; } message ChatResp { @@ -42,11 +43,6 @@ message MovieStatusChanged { MovieStatus status = 2; } -message CheckReq { - MovieStatus status = 1; - uint64 expireId = 2; -} - message ElementMessage { ElementMessageType type = 1; int64 time = 2; @@ -56,7 +52,8 @@ message ElementMessage { MovieStatus changeMovieStatusReq = 6; MovieStatusChanged movieStatusChanged = 7; double changeSeekReq = 8; - CheckReq checkReq = 9; + MovieStatus checkStatusReq = 9; + uint64 expireId = 10; int64 peopleChanged = 11; Sender moviesChanged = 12; Sender currentChanged = 13; diff --git a/server/handlers/websocket.go b/server/handlers/websocket.go index 31deeaf..93d943e 100644 --- a/server/handlers/websocket.go +++ b/server/handlers/websocket.go @@ -236,9 +236,9 @@ func handleElementMsg(cli *op.Client, msg *pb.ElementMessage) error { }, }, }) - case pb.ElementMessageType_CHECK: + case pb.ElementMessageType_CHECK_EXPIRED: current := cli.Room().Current() - if msg.CheckReq.ExpireId != 0 && current.MovieID != "" { + if msg.ExpireId != 0 && current.MovieID != "" { currentMovie, err := cli.Room().GetMovieByID(current.MovieID) if err != nil { return cli.Send(&pb.ElementMessage{ @@ -246,15 +246,16 @@ func handleElementMsg(cli *op.Client, msg *pb.ElementMessage) error { Error: fmt.Sprintf("get movie by id error: %v", err), }) } - if currentMovie.CheckExpired(msg.CheckReq.ExpireId) { + if currentMovie.CheckExpired(msg.ExpireId) { return cli.Send(&pb.ElementMessage{ Type: pb.ElementMessageType_CURRENT_EXPIRED, }) } } + case pb.ElementMessageType_CHECK_STATUS: + current := cli.Room().Current() status := current.Status - cliStatus := msg.CheckReq.Status - if status.Seek+maxInterval < cliStatus.Seek+timeDiff { + if status.Seek+maxInterval < msg.CheckStatusReq.Seek+timeDiff { return cli.Send(&pb.ElementMessage{ Type: pb.ElementMessageType_TOO_FAST, MovieStatusChanged: &pb.MovieStatusChanged{ @@ -265,7 +266,7 @@ func handleElementMsg(cli *op.Client, msg *pb.ElementMessage) error { }, }, }) - } else if status.Seek-maxInterval > cliStatus.Seek+timeDiff { + } else if status.Seek-maxInterval > msg.CheckStatusReq.Seek+timeDiff { return cli.Send(&pb.ElementMessage{ Type: pb.ElementMessageType_TOO_SLOW, MovieStatusChanged: &pb.MovieStatusChanged{