WebRTC-based weak network remote access method and system
By monitoring network bandwidth in the remote access system and switching ICE candidate addresses or downgrading quality, the problem of audio and video transmission quality in weak network environments is solved, achieving a stable and reliable remote access experience and high-quality real-time communication services.
Patent Information
- Application Number
- CN202410536605.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-30
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2044-04-30
AI Technical Summary
Existing technologies cannot effectively solve audio and video transmission quality problems in remote access in weak network environments, resulting in abnormal sound, blurry screens, black screens, and no response.
By establishing an end-to-end connection between the remote server and the client, the SCTP data channel is used to regularly send heartbeat events, monitor network bandwidth, and switch ICE candidate addresses or degrade quality when bandwidth is insufficient, switch to relay mode, and reduce audio and video quality. Sampling code rate to ensure the best matching of network channels and service quality.
It realizes intelligent monitoring and automatic switching of network connection modes in weak network environments, provides a stable and reliable remote access experience, and ensures high-quality real-time communication services.
Smart Images

Figure CN118540308A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of weak network remote access, and specifically relates to a weak network remote access method and system based on WebRTC. Background Art
[0002] Remote access technology refers to accessing and controlling computers, devices or resources located in another location from one place through a network connection. The emergence of remote access technology allows users to perform various operations, obtain information or manage without having to be physically close to the object being accessed. The demand for such remote access covers many fields, including but not limited to remote office, remote technical support, remote server management, remote control, remote demonstration, and remote monitoring. With the popularization of technologies such as cloud computing, the Internet of Things and remote collaboration, remote access has profoundly changed the way people work and live.
[0003] Although remote access has brought great convenience to people, the instability of the network environment has become the main factor restricting the development of remote access. The LAN environment can provide a relatively safe, efficient and controlled network environment to establish end-to-end connections. However, if end-to-end connections are established between LANs through the Internet, in addition to overcoming the limitations of firewalls and NAT devices, weak network environments must also be considered. Due to the complex and diverse network structure of the Internet, it is inevitable to encounter problems such as packet loss, jitter, congestion, and delay. These problems directly affect the effect and experience of remote access, resulting in abnormal sound, distorted screen, black screen, and no response.
[0004] WebRTC (Web Real-Time Communication) is an open technical standard for real-time audio and video communication between browsers. It is both an API and a protocol. WebRTC allows developers to implement real-time communication in Web applications, such as audio, video, file sharing, and data transmission, without the need for plug-ins or other external software support. It is widely used in the field of real-time communication. However, WebRTC focuses on the technical architecture at the protocol level and does not solve the problem of audio and video transmission quality in weak network environments. Summary of the invention
[0005] The present invention aims to solve at least one of the technical problems existing in the prior art.
[0006] A weak network remote access method based on WebRTC, the method specifically comprising the following steps:
[0007] After the remote server and the client establish an end-to-end connection, the remote server periodically sends heartbeat events to the client through the SCTP data channel. After receiving the heartbeat events, the client replies with a heartbeat response event to the remote server.
[0008] Get the approximate bandwidth BandWidth(Heart) of the current network;
[0009] Get the approximate bandwidth required for transmitting the server audio and server video respectively, and add them together to get the approximate bandwidth BandWidth(Remote) required for transmitting the remote server audio and video data;
[0010] When BandWidth(Heart) is greater than BandWidth(Remote), it means that the current network bandwidth can meet the quality transmission of remote access. When the BandWidth(Heart) collected multiple times is less than BandWidth(Remote), it means that the current network bandwidth cannot meet the remote access and it is necessary to try ICE candidate address switching or quality degradation.
[0011] When the approximate bandwidth of the end-to-end candidate addresses still cannot meet the quality transmission requirements of remote access, switch to relay mode;
[0012] When the quality is degraded, the remote server Peer-A actively reduces the audio and video sampling bit rate.
[0013] Furthermore, the method for obtaining the recent bandwidth BandWidth(Audio) required for transmitting the server audio is as follows:
[0014] BandWidth(Audio)=SampleRate*BitDepth*Channel*CompressRate*8 Calculate the approximate bandwidth BandWidth(Audio) required to transmit the server audio;
[0015] Where SampleRate is the sampling rate of the audio file, BitDepth is the bit depth of the audio file, Channel is the number of channels of the audio file, and CompressRate is the compression ratio of the audio compression format.
[0016] Furthermore, the specific method of obtaining the approximate bandwidth required for transmitting the server video is:
[0017] The approximate bandwidth BandWidth(Vedio) required to transmit the server video is calculated by the following formula:
[0018] BandWidth(Vedio)=Resolution*FPS*CompressRate*8;
[0019] Where Resolution is the resolution of the video file, FPS is the frame rate of the video file, and CompressRate is the compression ratio of the video format.
[0020] Furthermore, the remote server and the client select the best match of candidate addresses through the ICE protocol to establish an RTP and SCTP end-to-end connection.
[0021] Furthermore, the approximate bandwidth of the current network is calculated according to the following formula:
[0022] BandWidth(Heart)=2*X*8 / RTT;
[0023] Where X is the number of bytes of a single heartbeat data packet transmitted by the remote server, and RTT is the heartbeat response time.
[0024] Furthermore, the end-to-end connection between the remote server and the client is as follows:
[0025] After the remote server is started and ready, it establishes a WebSocket connection to the signaling server and sends a connect event request to establish the connection; then it calls the getUserMedia method to obtain the local audio and video tracks, and sends a join event request to register with the signaling service; the signaling server saves the status information of the remote server and waits for the client to connect;
[0026] The client sends a connect event request to the signaling server with the login authentication information; the signaling service matches the login information in the connect request with the credentials stored in the database; if the match is successful, a login success message is returned; if the match fails, the connect request is rejected;
[0027] After receiving the successful login message, the client sends a join request to the signaling server, requesting to establish a connection with the remote server. After authenticating the user operation, the signaling server forwards the connection request new-peer event to the remote server. After the remote server responds to the connection request, the signaling server responds with a resp-join event back to the client. The client sends a ready event request, and both parties are ready to negotiate media information.
[0028] Furthermore, the two parties negotiate media information in the following specific ways: the remote server creates an RTCPeerConnection object, collects local information, and calls the addTrack method to add local audio and video tracks to the RTCPeerConnection object for transmitting real-time image information on the server side;
[0029] Call the createDataChannel method to create an SCTP data channel stream for transmitting interactive information between the client and the remote server; call onIceCandidate to bind the ICE callback function and listen to ICE protocol candidate events; then call createOffer to create a session description;
[0030] The remote server calls setLocalDescription to save local information and generates SDPoffer and sends it to the signaling server, which forwards it to the client. The client receives the SDPoffer sent by the remote server, creates an RTCPeerConnection object, calls setRemoteDescription to save remote information, and uses onIceCandidate to bind the ICE callback function. Then it calls createAnswer to generate the local SDPanswer.
[0031] The client filters out the audio and video codecs or bitrate formats that are not supported in the remote server's Peer-ASDPoffer based on its own supported attributes; calls setLocalDescription to save the negotiated media information locally, and sends the SDPanswer to the remote server through the signaling server; then calls ontrack to try to establish an end-to-end connection with the remote server using the ICE protocol;
[0032] After receiving the SDP answer, the remote server calls setRemoteDescription to save the client media description information, and then calls ontrack to try to establish an end-to-end connection with the client;
[0033] The remote server and the client both send ICE requests to the Coturn server to obtain local network candidate information. Through the onIceCandidate callback function, they send their own network candidate information to the other party through the signaling server, and call addIceCandidate to store the other party's candidate address.
[0034] Furthermore, the interaction information includes mouse, keyboard, delay detection, change, and heartbeat events generated during remote access.
[0035] Furthermore, the session description includes information about audio and video bitrates, supported codec formats, ICE candidate addresses and authentication details, and the fingerprint of the certificate used for secure communication.
[0036] A weak network remote access system based on WebRTC, which adopts the aforementioned weak network remote access method to implement weak network remote access.
[0037] Compared with the prior art, the present invention has the following beneficial effects:
[0038] The present invention uses WebRTC technology to build a stable and reliable remote access method and system, which can intelligently monitor the network bandwidth. Especially in the case of weak network, the system automatically switches the end-to-end network connection mode and selects the best network path. In addition, when the network path cannot meet the service quality transmission, it has an active degradation strategy to provide users with a stable and reliable remote access experience.
[0039] At the same time, this application does not need to rely on a specific client, so it can easily adapt to the requirements of different platforms and devices, and can provide high-quality real-time communication services, creating more convenient and rich Internet experience for users. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 It is a timing diagram of the present invention. DETAILED DESCRIPTION
[0041] The technical solution of the present invention will be clearly and completely described below in conjunction with the embodiments. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0042] See also Figure 1 The present application provides a weak network remote access method based on WebRTC, which specifically includes the following steps:
[0043] S1. After the remote server Peer-A is started and ready, it establishes a WebSocket connection to the signaling server and sends a connect event request to establish the connection;
[0044] Then call the getUserMedia method to obtain the local audio and video tracks, and send a join event request to register with the signaling service;
[0045] The signaling server saves the status information of the remote server Peer-A and waits for the client Peer-B to connect;
[0046] S2, client Peer-B sends a connect event request to the signaling server with login authentication information;
[0047] The signaling service matches the login information in the connect request with the credentials stored in the database;
[0048] If the match is successful, a successful login message is returned; if the match fails, the connect request is rejected;
[0049] S3. The client receives the successful login message and then sends a join request to the signaling server to establish a connection with the remote server Peer-A.
[0050] After authenticating the user operation, the signaling server forwards the connection request new-peer event to the remote server Peer-A;
[0051] After the remote server Peer-A responds to the connection request, the signaling server responds with a resp-join event back to the client Peer-B;
[0052] Client Peer-B sends a ready event request, and both parties are ready to negotiate media information;
[0053] S4. The remote server Peer-A creates an RTCPeerConnection object, collects local information, and calls the addTrack method to add the local audio and video tracks to the RTCPeerConnection object for transmitting real-time image information on the server side.
[0054] Call the createDataChannel method to create an SCTP data channel stream, which is used to transmit the interactive information generated between the client Peer-B and the remote server Peer-A, including mouse, keyboard, delay detection, change, heartbeat and other events generated during remote access;
[0055] Call onIceCandidate to bind the ICE callback function and listen to ICE protocol candidate events;
[0056] Then call createOffer to create a session description, including audio and video bitrate information, supported codec formats, ICE candidate addresses and authentication details, and certificate fingerprints used for secure communication.
[0057] S5. The remote server Pe-A calls setLocalDescription to save local information and generates SDPoffer and sends it to the signaling server, which forwards it to the client Pe-B.
[0058] S6. Client Pe-B receives the SDPoffer sent by the remote server Pe-A, creates an RTCPeerConnection object, calls setRemoteDescription to save the remote information, and uses onIceCandidate to bind the ICE callback function;
[0059] Then call createAnswer to generate the local SDPanswer;
[0060] The client Peer-B filters out the audio and video codecs or bitrate formats that are not supported in the remote server Peer-ASDPoffer according to its own supported attributes;
[0061] Call setLocalDescription to save the negotiated media information locally, and send the SDPanswer to the remote server Peer-A through the signaling server;
[0062] Then ontrack is called to try to establish an end-to-end connection with the remote server Peer-A using the ICE protocol;
[0063] S7. After receiving the SDP answer, the remote server Pe-A calls setRemoteDescription to save the client media description information, and then calls ontrack to try to establish an end-to-end connection with the client Pe-B.
[0064] S8, the remote server Peer-A and the client Peer-B send ICE requests to the Coturn server to obtain local network candidate information, send their own network candidate information to the other party through the signaling server through the onIceCandidate callback function, and call addIceCandidate to store the candidate address of the other party;
[0065] The remote server Peer-A and the client Peer-B select the best match of candidate addresses through the ICE protocol to establish an RTP and SCTP end-to-end connection;
[0066] S9, after the remote server Pe-A establishes an end-to-end connection with the client Pe-B, the remote server Pe-A periodically sends heartbeat events to the client Pe-B through the SCTP data channel;
[0067] After receiving the heartbeat event, the client Peer-B replies with a heartbeat response event to the remote server Peer-A;
[0068] Assuming that the remote server Peer-A transmits a heartbeat data packet of X bytes at a time, and the response time to receive the heartbeat event is RTT, the approximate bandwidth BandWidth(Heart) of the current network is calculated according to the formula BandWidth(Heart)=2*X*8 / RTT;
[0069] The size of an audio file depends on the sampling rate SampleRate, the bit depth BitDepth, the number of channels Channel, and the compression ratio CompressRate of the audio compression format, according to the formula:
[0070] BandWidth(Audio)=SampleRate*BitDepth*Channel*CompressRate*8;
[0071] Get the approximate bandwidth BandWidth(Audio) required to transmit the server audio;
[0072] The size of the video file depends on the resolution, frame rate, and compression ratio of the video format, according to the formula:
[0073] BandWidth(Vedio)=Resolution*FPS*CompressRate*8;
[0074] Get the approximate bandwidth required to transmit the server video;
[0075] The approximate bandwidth BandWidth(Remote)=BandWidth(Audio)+BandWidth(Video) required for transmitting the audio and video data of the remote server can be obtained;
[0076] When BandWidth(Heart) is greater than BandWidth(Remote), it means that the current network bandwidth can meet the quality transmission of remote access. When the BandWidth(Heart) collected multiple times is less than BandWidth(Remote), it means that the current network bandwidth cannot meet the remote access and it is necessary to try ICE candidate address switching or quality degradation.
[0077] S10, when the remote server Peer-A performs ICE candidate address switching, it first sends an ICE candidate address switching event to the client Peer-B;
[0078] Then the remote server Peer-A and client Peer-B send ICE requests to the Coturn server to retrieve the network candidate information;
[0079] When the approximate bandwidth of the end-to-end candidate address still cannot meet the quality transmission requirements of remote access, it switches to relay mode, and the remote server Peer-A and the client Peer-B re-establish a connection with the Coturn server as the relay node;
[0080] S11, when the quality is degraded, the remote server Peer-A actively reduces the audio and video sampling bit rate, calls the setLocalDescription method to reset the SDP, and sends it to the client Peer-B through the SDP server;
[0081] The client Peer-B calls the setRemoteDescription method to save the remote media description information, selects the supported audio and video codec formats, and then regenerates the SDP answer and sends it to the remote server Peer-A;
[0082] After the remote server Peer-A saves the peer media description information, it retransmits the audio and video streams;
[0083] S12. When the client Peer-B actively disconnects, a leave event is sent to the remote server Peer-A via the SDP server, and both parties terminate the remote access control after closing the connection channel.
[0084] The above embodiments are only used to illustrate the technical method of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical method of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical method of the present invention.
Claims
1. A weak network remote access method based on WebRTC, characterized in that: The method specifically comprises the following steps: After the remote server and the client establish an end-to-end connection, the remote server periodically sends heartbeat events to the client through the SCTP data channel. After receiving the heartbeat events, the client replies with a heartbeat response event to the remote server. Get the approximate bandwidth BandWidth(Heart) of the current network; Get the approximate bandwidth required for transmitting the server audio and server video respectively, and add them together to get the approximate bandwidth BandWidth(Remote) required for transmitting the remote server audio and video data; When BandWidth(Heart) is greater than BandWidth(Remote), it means that the current network bandwidth can meet the quality transmission of remote access. When the BandWidth(Heart) collected multiple times is less than BandWidth(Remote), it means that the current network bandwidth cannot meet the remote access and it is necessary to try ICE candidate address switching or quality degradation. When the approximate bandwidth of the end-to-end candidate addresses still cannot meet the quality transmission requirements of remote access, switch to relay mode; When the quality is degraded, the remote server Peer-A actively reduces the audio and video sampling bit rate.
2. A weak network remote access method based on WebRTC according to claim 1, characterized in that: The method to obtain the recent bandwidth BandWidth(Audio) required to transmit the server audio is as follows: BandWidth(Audio)=SampleRate*BitDepth*Channel*CompressRa te*8 calculates the approximate bandwidth BandWidth(Audio) required to transmit the server audio; Where SampleRate is the sampling rate of the audio file, BitDepth is the bit depth of the audio file, Channel is the number of channels of the audio file, and CompressRate is the compression ratio of the audio compression format.
3. A weak network remote access method based on WebRTC according to claim 1, characterized in that: The specific method of obtaining the approximate bandwidth required to transmit the server video is: The approximate bandwidth BandWidth(Vedio) required to transmit the server video is calculated by the following formula: BandWidth(Vedio)=Resolution*FPS*CompressRate*8; Where Resolution is the resolution of the video file, FPS is the frame rate of the video file, and CompressRate is the compression ratio of the video format.
4. A weak network remote access method based on WebRTC according to claim 1, characterized in that: The remote server and the client select the best match of candidate addresses through the ICE protocol to establish an RTP and SCTP end-to-end connection.
5. A weak network remote access method based on WebRTC according to claim 1, characterized in that: The approximate bandwidth of the current network is calculated according to the following formula: BandWidth(Heart)=2*X*8 / RTT; Where X is the number of bytes of a single heartbeat data packet transmitted by the remote server, and RTT is the heartbeat response time.
6. A weak network remote access method based on WebRTC according to claim 1, characterized in that: The end-to-end connection between the remote server and the client is as follows: After the remote server is started and ready, it establishes a WebSocket connection to the signaling server and sends a connect event request to establish the connection; then it calls the getUserMedia method to obtain the local audio and video tracks, and sends a join event request to register with the signaling service; The signaling server saves the status information of the remote server and waits for the client to connect; The client sends a connect event request to the signaling server with login authentication information; The signaling service matches the login information in the connect request with the credentials stored in the database; if the match is successful, a login success message is returned; If the match fails, the connect request is rejected; The client receives the successful login message and then sends a join request to the signaling server to establish a connection with the remote server; After authenticating the user operation, the signaling server forwards the connection request new-peer event to the remote server; after the remote server responds to the connection request, the signaling server responds with a resp-join event back to the client; the client sends a ready event request, and both parties are ready to negotiate media information.
7. A weak network remote access method based on WebRTC according to claim 6, characterized in that: The specific way for the two parties to negotiate media information is as follows: the remote server creates an RTCPeerConnection object, collects local information, and calls the addTrack method to add local audio and video tracks to the RTCPeerConnection object for transmitting real-time image information on the server side; Call the createDataChannel method to create an SCTP data channel stream for transmitting interactive information between the client and the remote server; call onIceCandidate to bind the ICE callback function and listen to ICE protocol candidate events; then call createOffer to create a session description; The remote server calls setLocalDescription to save local information and generates SDPoffer and sends it to the signaling server, which forwards it to the client. The client receives the SDPoffer sent by the remote server, creates an RTCPeerConnection object, calls setRemoteDescription to save remote information, and uses onIceCandidate to bind the ICE callback function. Then it calls createAnswer to generate the local SDPanswer. The client filters out the audio and video codecs or bitrate formats that are not supported in the remote server's Peer-ASDPoffer based on its own supported attributes; calls setLocalDescription to save the negotiated media information locally, and sends the SDPanswer to the remote server through the signaling server; then calls ontrack to try to establish an end-to-end connection with the remote server using the ICE protocol; After receiving the SDP answer, the remote server calls setRemoteDescription to save the client media description information, and then calls ontrack to try to establish an end-to-end connection with the client; The remote server and the client both send ICE requests to the Coturn server to obtain local network candidate information. Through the onIceCandidate callback function, they send their own network candidate information to the other party through the signaling server, and call addIceCandidate to store the other party's candidate address.
8. A weak network remote access method based on WebRTC according to claim 7, characterized in that: Interaction information includes mouse, keyboard, delay detection, change, and heartbeat events generated during remote access.
9. A weak network remote access method based on WebRTC according to claim 1, characterized in that: The session description includes information about audio and video bitrates, supported codec formats, ICE candidate addresses and authentication details, and the fingerprint of the certificate used for secure communication.
10. A weak network remote access system based on WebRTC, characterized in that: The system adopts the weak network remote access method as described in any one of claims 1 to 9 to realize weak network remote access.
Citation Information
Patent Citations
Communication method for achieving instant message based on Web real-time communication (WebRTC) technology
CN106850399A
WebRtc-based audio and video call method and system
CN114339116A
Method for improving network instability based on WebRTC
CN116566959A
Systems and methods for automatic ICE relay candidate creation
US8601144B1
Cited By
Treatment method for multiple candidate transmission paths and computer storage medium
CN122845568A
