ITADN

How to recreate connection class from existing connection?

#22Closedminwidth0px 创建于 2024-08-05
M
minwidth0pxcommented
For example, If a user goes to another page, they will lose the current network class and will have to create a new one and redo all the signaling. Is there a way to recreate a network once a connection was already established? For example to recreate the network from an sdp answer and list of candidates? I tried creating a mock Hub class that re-uses the address and sdp params instead of trying to fetch them but it did not work: (It times out in the async connect(remoteAddress, port) function): ```ts constructor(endpoint: string, address: string, ICEParams: any) { this.#ICEParams = ICEParams //<-- list of SDP answer and candidates saved from the real hub class this.#address = address this.#receiveCallback = () => {} } //... public send(message: { to: string; data: any }): Promise<void> { if(!this.#isSet){//only set the params once this.#isSet = true const ICEParams = this.#ICEParams for (let i = 0; i < ICEParams.params.length; i++){ this.#onReceive(ICEParams.params[i]) } } } ``` I want this feature because currently I am setting the SDP and and candidates manually (ie. the `send` function prints the SDP and candidates to the page, and `onReceive` is called when you paste the SDP/candidates into a `textarea`) so reconnecting on each page load would take a long time. I would like to be able to just store some info in sessionStorage/localStorage that can re-create the existing connection newtork class (serializing deeply nested classes is impossible in JS, so I can't just do that).
关闭于 2024-08-12 3 条评论