diff --git a/backend/pkg/messages/filters.go b/backend/pkg/messages/filters.go index c28e07742..e79d1d987 100644 --- a/backend/pkg/messages/filters.go +++ b/backend/pkg/messages/filters.go @@ -2,7 +2,7 @@ package messages func IsReplayerType(id int) bool { - return 0 == id || 4 == id || 5 == id || 6 == id || 7 == id || 8 == id || 9 == id || 10 == id || 11 == id || 12 == id || 13 == id || 14 == id || 15 == id || 16 == id || 18 == id || 19 == id || 20 == id || 22 == id || 37 == id || 38 == id || 39 == id || 40 == id || 41 == id || 44 == id || 45 == id || 46 == id || 47 == id || 48 == id || 49 == id || 54 == id || 55 == id || 59 == id || 60 == id || 61 == id || 67 == id || 69 == id || 70 == id || 71 == id || 72 == id || 73 == id || 74 == id || 75 == id || 76 == id || 77 == id || 90 == id || 93 == id || 96 == id || 100 == id || 102 == id || 103 == id || 105 == id + return 0 == id || 4 == id || 5 == id || 6 == id || 7 == id || 8 == id || 9 == id || 10 == id || 11 == id || 12 == id || 13 == id || 14 == id || 15 == id || 16 == id || 18 == id || 19 == id || 20 == id || 22 == id || 37 == id || 38 == id || 39 == id || 40 == id || 41 == id || 44 == id || 45 == id || 46 == id || 47 == id || 48 == id || 49 == id || 54 == id || 55 == id || 59 == id || 60 == id || 61 == id || 67 == id || 69 == id || 70 == id || 71 == id || 72 == id || 73 == id || 74 == id || 75 == id || 76 == id || 77 == id || 79 == id || 90 == id || 93 == id || 96 == id || 100 == id || 102 == id || 103 == id || 105 == id } func IsIOSType(id int) bool { diff --git a/backend/pkg/messages/messages.go b/backend/pkg/messages/messages.go index 27712cb1f..8cdb95722 100644 --- a/backend/pkg/messages/messages.go +++ b/backend/pkg/messages/messages.go @@ -156,6 +156,8 @@ const ( MsgAdoptedSSRemoveOwner = 77 + MsgZustand = 79 + MsgIOSBatchMeta = 107 MsgIOSSessionStart = 90 @@ -3038,6 +3040,40 @@ func (msg *AdoptedSSRemoveOwner) TypeID() int { return 77 } +type Zustand struct { + message + Mutation string + State string +} + +func (msg *Zustand) Encode() []byte { + buf := make([]byte, 21+len(msg.Mutation)+len(msg.State)) + buf[0] = 79 + p := 1 + p = WriteString(msg.Mutation, buf, p) + p = WriteString(msg.State, buf, p) + return buf[:p] +} + +func (msg *Zustand) EncodeWithIndex() []byte { + encoded := msg.Encode() + if IsIOSType(msg.TypeID()) { + return encoded + } + data := make([]byte, len(encoded)+8) + copy(data[8:], encoded[:]) + binary.LittleEndian.PutUint64(data[0:], msg.Meta().Index) + return data +} + +func (msg *Zustand) Decode() Message { + return msg +} + +func (msg *Zustand) TypeID() int { + return 79 +} + type IOSBatchMeta struct { message Timestamp uint64 diff --git a/backend/pkg/messages/read-message.go b/backend/pkg/messages/read-message.go index 2b12601d9..1b0f579af 100644 --- a/backend/pkg/messages/read-message.go +++ b/backend/pkg/messages/read-message.go @@ -1306,6 +1306,18 @@ func DecodeAdoptedSSRemoveOwner(reader io.Reader) (Message, error) { return msg, err } +func DecodeZustand(reader io.Reader) (Message, error) { + var err error = nil + msg := &Zustand{} + if msg.Mutation, err = ReadString(reader); err != nil { + return nil, err + } + if msg.State, err = ReadString(reader); err != nil { + return nil, err + } + return msg, err +} + func DecodeIOSBatchMeta(reader io.Reader) (Message, error) { var err error = nil msg := &IOSBatchMeta{} @@ -1939,6 +1951,9 @@ func ReadMessage(t uint64, reader io.Reader) (Message, error) { case 77: return DecodeAdoptedSSRemoveOwner(reader) + case 79: + return DecodeZustand(reader) + case 107: return DecodeIOSBatchMeta(reader) diff --git a/ee/connectors/msgcodec/messages.py b/ee/connectors/msgcodec/messages.py index f645e2995..e1fe393a4 100644 --- a/ee/connectors/msgcodec/messages.py +++ b/ee/connectors/msgcodec/messages.py @@ -63,13 +63,6 @@ class SessionStart(Message): self.user_id = user_id -class SessionDisconnect(Message): - __id__ = 2 - - def __init__(self, timestamp): - self.timestamp = timestamp - - class SessionEnd(Message): __id__ = 3 @@ -106,7 +99,6 @@ class CreateDocument(Message): __id__ = 7 def __init__(self, ): - pass @@ -752,6 +744,14 @@ class AdoptedSSRemoveOwner(Message): self.id = id +class Zustand(Message): + __id__ = 79 + + def __init__(self, mutation, state): + self.mutation = mutation + self.state = state + + class IOSBatchMeta(Message): __id__ = 107 diff --git a/ee/connectors/msgcodec/msgcodec.py b/ee/connectors/msgcodec/msgcodec.py index 76468682a..d53c3e75d 100644 --- a/ee/connectors/msgcodec/msgcodec.py +++ b/ee/connectors/msgcodec/msgcodec.py @@ -2,6 +2,7 @@ from msgcodec.codec import Codec from msgcodec.messages import * +from typing import List import io class MessageCodec(Codec): @@ -42,7 +43,7 @@ class MessageCodec(Codec): raise UnicodeDecodeError(f"Error while decoding message key (SessionID) from {b}\n{e}") return decoded - def decode_detailed(self, b: bytes): + def decode_detailed(self, b: bytes) -> List[Message]: reader = io.BytesIO(b) messages_list = list() messages_list.append(self.handler(reader, 0)) @@ -61,7 +62,7 @@ class MessageCodec(Codec): break return messages_list - def handler(self, reader: io.BytesIO, mode=0): + def handler(self, reader: io.BytesIO, mode=0) -> Message: message_id = self.read_message_id(reader) if mode == 1: # We skip the three bytes representing the length of message. It can be used to skip unwanted messages @@ -71,9 +72,10 @@ class MessageCodec(Codec): # Old format with no bytes for message length return self.read_head_message(reader, message_id) else: - raise IOError() + raise IOError() + + def read_head_message(self, reader: io.BytesIO, message_id) -> Message: - def read_head_message(self, reader: io.BytesIO, message_id: int): if message_id == 80: return BatchMeta( page_no=self.read_uint(reader), @@ -121,11 +123,6 @@ class MessageCodec(Codec): user_id=self.read_string(reader) ) - if message_id == 2: - return SessionDisconnect( - timestamp=self.read_uint(reader) - ) - if message_id == 3: return SessionEnd( timestamp=self.read_uint(reader) @@ -665,6 +662,12 @@ class MessageCodec(Codec): id=self.read_uint(reader) ) + if message_id == 79: + return Zustand( + mutation=self.read_string(reader), + state=self.read_string(reader) + ) + if message_id == 107: return IOSBatchMeta( timestamp=self.read_uint(reader), diff --git a/frontend/app/components/Session_/Player/Controls/Controls.js b/frontend/app/components/Session_/Player/Controls/Controls.js index 0601e092f..1dcbbaa21 100644 --- a/frontend/app/components/Session_/Player/Controls/Controls.js +++ b/frontend/app/components/Session_/Player/Controls/Controls.js @@ -48,6 +48,8 @@ function getStorageIconName(type) { return 'vendors/vuex'; case STORAGE_TYPES.NGRX: return 'vendors/ngrx'; + case STORAGE_TYPES.ZUSTAND: + return 'vendors/zustand'; case STORAGE_TYPES.NONE: return 'store'; } @@ -73,6 +75,8 @@ function getStorageName(type) { return 'VUEX'; case STORAGE_TYPES.NGRX: return 'NGRX'; + case STORAGE_TYPES.ZUSTAND: + return 'ZUSTAND'; case STORAGE_TYPES.NONE: return 'STATE'; } diff --git a/frontend/app/components/Session_/Storage/Storage.js b/frontend/app/components/Session_/Storage/Storage.js index b1cf53dfc..9bd6c0174 100644 --- a/frontend/app/components/Session_/Storage/Storage.js +++ b/frontend/app/components/Session_/Storage/Storage.js @@ -121,6 +121,9 @@ export default class Storage extends React.PureComponent { const { type, listNow, list } = this.props; let src; let name; + + // ZUSTAND TODO + console.log(item, type) switch(type) { case STORAGE_TYPES.REDUX: case STORAGE_TYPES.NGRX: @@ -135,16 +138,23 @@ export default class Storage extends React.PureComponent { src = item.payload; name = `@${item.type} ${src && src.type}`; break; + case STORAGE_TYPES.ZUSTAND: + src = null; + name = item.mutation.join('') } return (
- + {src === null ? ( +
{name}
+ ) : ( + + )}
{ i + 1 < listNow.length &&