SocketIOSession.ts (hoppscotch-2.2.1) | : | SocketIOSession.ts (hoppscotch-3.0.0) | ||
---|---|---|---|---|
skipping to change at line 13 | skipping to change at line 13 | |||
import { Socket as SocketV3 } from "socket.io-client-v3" | import { Socket as SocketV3 } from "socket.io-client-v3" | |||
import { Socket as SocketV4 } from "socket.io-client-v4" | import { Socket as SocketV4 } from "socket.io-client-v4" | |||
import DispatchingStore, { defineDispatchers } from "./DispatchingStore" | import DispatchingStore, { defineDispatchers } from "./DispatchingStore" | |||
import { | import { | |||
HoppRealtimeLog, | HoppRealtimeLog, | |||
HoppRealtimeLogLine, | HoppRealtimeLogLine, | |||
} from "~/helpers/types/HoppRealtimeLog" | } from "~/helpers/types/HoppRealtimeLog" | |||
type SocketIO = SocketV2 | SocketV3 | SocketV4 | type SocketIO = SocketV2 | SocketV3 | SocketV4 | |||
export type SIOClientVersion = "v4" | "v3" | "v2" | ||||
type HoppSIORequest = { | type HoppSIORequest = { | |||
endpoint: string | endpoint: string | |||
path: string | path: string | |||
version: string | version: SIOClientVersion | |||
} | } | |||
type HoppSIOSession = { | type HoppSIOSession = { | |||
request: HoppSIORequest | request: HoppSIORequest | |||
connectingState: boolean | ||||
connectionState: boolean | ||||
log: HoppRealtimeLog | log: HoppRealtimeLog | |||
socket: SocketIO | null | socket: SocketIO | null | |||
} | } | |||
const defaultSIORequest: HoppSIORequest = { | const defaultSIORequest: HoppSIORequest = { | |||
endpoint: "wss://hoppscotch-socketio.herokuapp.com", | endpoint: "wss://echo-socketio.hoppscotch.io", | |||
path: "/socket.io", | path: "/socket.io", | |||
version: "v4", | version: "v4", | |||
} | } | |||
const defaultSIOSession: HoppSIOSession = { | const defaultSIOSession: HoppSIOSession = { | |||
request: defaultSIORequest, | request: defaultSIORequest, | |||
connectionState: false, | ||||
connectingState: false, | ||||
socket: null, | socket: null, | |||
log: [], | log: [], | |||
} | } | |||
const dispatchers = defineDispatchers({ | const dispatchers = defineDispatchers({ | |||
setRequest( | setRequest( | |||
_: HoppSIOSession, | _: HoppSIOSession, | |||
{ newRequest }: { newRequest: HoppSIORequest } | { newRequest }: { newRequest: HoppSIORequest } | |||
) { | ) { | |||
return { | return { | |||
skipping to change at line 66 | skipping to change at line 64 | |||
} | } | |||
}, | }, | |||
setPath(curr: HoppSIOSession, { newPath }: { newPath: string }) { | setPath(curr: HoppSIOSession, { newPath }: { newPath: string }) { | |||
return { | return { | |||
request: { | request: { | |||
...curr.request, | ...curr.request, | |||
path: newPath, | path: newPath, | |||
}, | }, | |||
} | } | |||
}, | }, | |||
setVersion(curr: HoppSIOSession, { newVersion }: { newVersion: string }) { | setVersion( | |||
curr: HoppSIOSession, | ||||
{ newVersion }: { newVersion: SIOClientVersion } | ||||
) { | ||||
return { | return { | |||
request: { | request: { | |||
...curr.request, | ...curr.request, | |||
version: newVersion, | version: newVersion, | |||
}, | }, | |||
} | } | |||
}, | }, | |||
setSocket(_: HoppSIOSession, { socket }: { socket: SocketIO }) { | setSocket(_: HoppSIOSession, { socket }: { socket: SocketIO }) { | |||
return { | return { | |||
socket, | socket, | |||
} | } | |||
}, | }, | |||
setConnectionState(_: HoppSIOSession, { state }: { state: boolean }) { | ||||
return { | ||||
connectionState: state, | ||||
} | ||||
}, | ||||
setConnectingState(_: HoppSIOSession, { state }: { state: boolean }) { | ||||
return { | ||||
connectingState: state, | ||||
} | ||||
}, | ||||
setLog(_: HoppSIOSession, { log }: { log: HoppRealtimeLog }) { | setLog(_: HoppSIOSession, { log }: { log: HoppRealtimeLog }) { | |||
return { | return { | |||
log, | log, | |||
} | } | |||
}, | }, | |||
addLogLine(curr: HoppSIOSession, { line }: { line: HoppRealtimeLogLine }) { | addLogLine(curr: HoppSIOSession, { line }: { line: HoppRealtimeLogLine }) { | |||
return { | return { | |||
log: [...curr.log, line], | log: [...curr.log, line], | |||
} | } | |||
}, | }, | |||
skipping to change at line 148 | skipping to change at line 139 | |||
export function setSIOSocket(socket: SocketIO) { | export function setSIOSocket(socket: SocketIO) { | |||
SIOSessionStore.dispatch({ | SIOSessionStore.dispatch({ | |||
dispatcher: "setSocket", | dispatcher: "setSocket", | |||
payload: { | payload: { | |||
socket, | socket, | |||
}, | }, | |||
}) | }) | |||
} | } | |||
export function setSIOConnectionState(state: boolean) { | ||||
SIOSessionStore.dispatch({ | ||||
dispatcher: "setConnectionState", | ||||
payload: { | ||||
state, | ||||
}, | ||||
}) | ||||
} | ||||
export function setSIOConnectingState(state: boolean) { | ||||
SIOSessionStore.dispatch({ | ||||
dispatcher: "setConnectingState", | ||||
payload: { | ||||
state, | ||||
}, | ||||
}) | ||||
} | ||||
export function setSIOLog(log: HoppRealtimeLog) { | export function setSIOLog(log: HoppRealtimeLog) { | |||
SIOSessionStore.dispatch({ | SIOSessionStore.dispatch({ | |||
dispatcher: "setLog", | dispatcher: "setLog", | |||
payload: { | payload: { | |||
log, | log, | |||
}, | }, | |||
}) | }) | |||
} | } | |||
export function addSIOLogLine(line: HoppRealtimeLogLine) { | export function addSIOLogLine(line: HoppRealtimeLogLine) { | |||
skipping to change at line 203 | skipping to change at line 177 | |||
export const SIOVersion$ = SIOSessionStore.subject$.pipe( | export const SIOVersion$ = SIOSessionStore.subject$.pipe( | |||
pluck("request", "version"), | pluck("request", "version"), | |||
distinctUntilChanged() | distinctUntilChanged() | |||
) | ) | |||
export const SIOPath$ = SIOSessionStore.subject$.pipe( | export const SIOPath$ = SIOSessionStore.subject$.pipe( | |||
pluck("request", "path"), | pluck("request", "path"), | |||
distinctUntilChanged() | distinctUntilChanged() | |||
) | ) | |||
export const SIOConnectingState$ = SIOSessionStore.subject$.pipe( | ||||
pluck("connectingState"), | ||||
distinctUntilChanged() | ||||
) | ||||
export const SIOConnectionState$ = SIOSessionStore.subject$.pipe( | export const SIOConnectionState$ = SIOSessionStore.subject$.pipe( | |||
pluck("connectionState"), | pluck("connectionState"), | |||
distinctUntilChanged() | distinctUntilChanged() | |||
) | ) | |||
export const SIOSocket$ = SIOSessionStore.subject$.pipe( | export const SIOSocket$ = SIOSessionStore.subject$.pipe( | |||
pluck("socket"), | pluck("socket"), | |||
distinctUntilChanged() | distinctUntilChanged() | |||
) | ) | |||
End of changes. 9 change blocks. | ||||
39 lines changed or deleted | 8 lines changed or added |