Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,26 @@ enum RRWebIncrementalData: RRWebEventData {
case mouseInteraction(RRWebMouseInteractionData)
case touchMove(RRWebTouchMoveData)

// enum CodingKeys: CodingKey {
// case source
// }
enum CodingKeys: CodingKey {
case source
}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let source = try container.decode(RRWebIncrementalSource.self, forKey: .source)

switch source {
case .mutation:
let data = try RRWebMutationData(from: decoder)
self = .mutation(data)
case .mouseInteraction:
let data = try RRWebMouseInteractionData(from: decoder)
self = .mouseInteraction(data)
case .touchMove:
let data = try RRWebTouchMoveData(from: decoder)
self = .touchMove(data)
}
}

func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
Expand Down Expand Up @@ -157,10 +174,18 @@ enum RRWebMouseInteractionType: Int, Codable {

struct RRWebMouseInteractionData: Codable {
let type: RRWebMouseInteractionType
let source: RRWebIncrementalSource = .mouseInteraction
let source: RRWebIncrementalSource
let id: Int
let x: CGFloat
let y: CGFloat

init(type: RRWebMouseInteractionType, id: Int, x: CGFloat, y: CGFloat) {
self.type = type
self.source = .mouseInteraction
self.id = id
self.x = x
self.y = y
}
}

struct RRWebTouchPosition: Codable {
Expand All @@ -171,6 +196,11 @@ struct RRWebTouchPosition: Codable {
}

struct RRWebTouchMoveData: Codable {
let source: RRWebIncrementalSource = .touchMove
let source: RRWebIncrementalSource
let positions: [RRWebTouchPosition]

init(positions: [RRWebTouchPosition]) {
self.source = .touchMove
self.positions = positions
}
}
14 changes: 13 additions & 1 deletion Agent/SessionReplay/RRWebModels/SerializedNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class ElementNodeData: SerializedNodeData {
self.id = try container.decode(Int.self, forKey: .id)
self.tagName = try container.decode(TagType.self, forKey: .tagName)
self.attributes = try container.decode(RRWebAttributes.self, forKey: .attributes)
self.childNodes = try container.decode([SerializedNode].self, forKey: .childNodes)
self.childNodes = try container.decodeIfPresent([SerializedNode].self, forKey: .childNodes) ?? []
}

func encode(to encoder: Encoder) throws {
Expand All @@ -188,13 +188,25 @@ class TextNodeData: SerializedNodeData {
let textContent: String
var childNodes: [SerializedNode] = []

enum CodingKeys: CodingKey {
case type, id, isStyle, textContent, childNodes
}

init(id: Int, isStyle: Bool, textContent: String, childNodes: [SerializedNode]) {
self.id = id
self.isStyle = isStyle
self.textContent = textContent
self.childNodes = childNodes
}

required init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(Int.self, forKey: .id)
self.isStyle = try container.decode(Bool.self, forKey: .isStyle)
self.textContent = try container.decode(String.self, forKey: .textContent)
self.childNodes = try container.decodeIfPresent([SerializedNode].self, forKey: .childNodes) ?? []
}

func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(type, forKey: .type)
Expand Down
Loading