Skip to content

Commit

Permalink
refactor: reuse common fields for SS messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Feb 23, 2023
1 parent 9ee565d commit efcda82
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions src/io-types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,23 @@ const Types = union([Offer, Answer, IceCandidate, IceCandidates])

export const Sources = union([literal('wallet'), literal('extension')])

export const AnswerIO = object({
export const SignalingServerMessage = object({
requestId: string(),
method: Answer,
source: Sources,
connectionId: string(),
encryptedPayload: string(),
targetClientId: string(),
encryptedPayload: string(),
source: Sources.optional(), // redundant, to be removed
connectionId: string().optional(), // redundant, to be removed
})

export const AnswerIO = SignalingServerMessage.extend({
method: Answer,
payload: object({
sdp: string(),
}),
})

export const OfferIO = object({
requestId: string(),
export const OfferIO = SignalingServerMessage.extend({
method: Offer,
source: Sources,
connectionId: string(),
encryptedPayload: string(),
targetClientId: string(),
payload: object({
sdp: string(),
}),
Expand All @@ -39,23 +37,13 @@ const IceCandidatePayloadIO = object({
sdpMLineIndex: number(),
})

export const IceCandidateIO = object({
requestId: string(),
export const IceCandidateIO = SignalingServerMessage.extend({
method: IceCandidate,
source: Sources,
connectionId: string(),
encryptedPayload: string(),
targetClientId: string(),
payload: IceCandidatePayloadIO,
})

export const IceCandidatesIO = object({
requestId: string(),
export const IceCandidatesIO = SignalingServerMessage.extend({
method: IceCandidates,
source: Sources,
connectionId: string(),
encryptedPayload: string(),
targetClientId: string(),
payload: array(IceCandidatePayloadIO),
})

Expand Down

0 comments on commit efcda82

Please sign in to comment.