Disclosure of Invention
The invention mainly aims to provide a method and a device for detecting terminal equipment on line and a computer readable storage medium, and aims to solve the technical problems that resources are occupied highly or the on-line state cannot be detected timely due to the adoption of fixed heartbeat frequency.
In order to achieve the above object, the present invention provides a method for online detecting a terminal device, the method comprising:
the terminal equipment detects a target call request and a target hang-up request, wherein the target call request is a call request sent by the terminal equipment or a received call request, and the target hang-up request is a hang-up request initiated after the terminal equipment calls or a hang-up request sent by called equipment;
When the target call request is detected, switching from a second heartbeat frequency to a first heartbeat frequency, and sending first heartbeat data to a server according to the first heartbeat frequency so that the server detects whether the terminal equipment is online or not according to the first heartbeat data;
Or when the target hang-up request is detected, switching from the first heartbeat frequency to the second heartbeat frequency, and sending second heartbeat data to the server according to the second heartbeat frequency, so that the server detects whether the terminal equipment is online or not according to the second heartbeat data, wherein the first heartbeat frequency is larger than the second heartbeat frequency.
Optionally, after the step of detecting the target call request and the target hang-up request, the terminal device further includes:
detecting whether an online detection request sent by the server is received or not when the target call request and the target hang-up request are not detected;
And when the online detection request sent by the server is received, sending a response detection request to the server so that the server determines that the terminal equipment is online according to the response detection request.
Optionally, when the target call request is detected, the step of switching from the second heartbeat frequency to the first heartbeat frequency and sending the first heartbeat data to the server according to the first heartbeat frequency includes:
And when the target call request sent by the server is received, sending ringing signaling to the server, switching from the second heartbeat frequency to the first heartbeat frequency, and sending the first heartbeat data to the server according to the first heartbeat frequency so that the server detects whether the terminal equipment is online according to the ringing signaling and the first heartbeat data.
Optionally, after the step of detecting the target call request and the target hang-up request, the terminal device further includes:
detecting whether the terminal equipment logs in or not when the target call request and the target hang-up request are not detected;
detecting whether the terminal equipment is in a call or not when the terminal equipment is logged in;
And when the terminal equipment is not in communication, sending the second heartbeat data to the server according to the second heartbeat frequency, so that the server detects whether the terminal equipment is online according to the second heartbeat data.
In addition, in order to achieve the above object, the present invention further provides an online detection method for a terminal device, where the method includes:
the method comprises the steps that a server detects a target call request and a target hang-up request, wherein the target call request is a call request sent by terminal equipment, and the target hang-up request is a hang-up request sent by the terminal equipment;
When the target call request is detected, switching from a second preset time interval to a first preset time interval, detecting whether the time interval for transmitting the heartbeat data is overtime or not according to first heartbeat data transmitted by the terminal equipment and the first preset time interval, judging whether the terminal equipment is online or not according to whether the time interval for transmitting the heartbeat data is overtime or not, and transmitting the first heartbeat data by the terminal equipment according to a first heartbeat frequency;
Or when the target hang-up request is detected, switching from the first preset time interval to the second preset time interval, detecting whether the time interval for sending the heartbeat data is overtime or not according to second heartbeat data sent by the terminal equipment and the second preset time interval, judging whether the terminal equipment is online or not according to whether the time interval is overtime, and sending the second heartbeat data by the terminal equipment according to a second heartbeat frequency, wherein the first heartbeat frequency is larger than the second heartbeat frequency, and the second preset time interval is larger than the first preset time interval.
Optionally, after the step of detecting the target call request and the target hang-up request, the server further includes:
when the target call request is detected, determining called equipment corresponding to the target call request;
Sending an online detection request to the called equipment;
when receiving a response detection request sent by the called equipment according to the online detection request, determining that the terminal equipment is online, and forwarding the target call request to the called equipment;
And when the response detection request sent by the called equipment is not received within a preset time period, determining that the called equipment is offline, and sending a call ending request to the terminal equipment so that the terminal equipment ends a call process according to the call ending request.
Optionally, the step of switching from the second preset time interval to the first preset time interval when the target call request is detected includes:
Forwarding the target call request to called equipment when the target call request is detected;
And when receiving the ringing signaling sent by the called equipment according to the target call request, switching from the second preset time interval to the first preset time interval, and forwarding the ringing signaling to the calling equipment.
In addition, in order to achieve the above object, the present invention also provides an online detection device for a terminal device, where the device includes a first detection module and a sending module, where:
The first detection module is configured to detect a target call request and a target hang-up request by using the terminal device, where the target call request is a call request sent by the terminal device or a received call request, and the target hang-up request is a hang-up request initiated after the terminal device calls or a hang-up request sent by a called device;
The sending module is configured to switch from a second heartbeat frequency to a first heartbeat frequency when the target call request is detected, and send first heartbeat data to a server according to the first heartbeat frequency, so that the server detects whether the terminal device is online according to the first heartbeat data, or switch from the first heartbeat frequency to the second heartbeat frequency when the target hang-up request is detected, and send second heartbeat data to the server according to the second heartbeat frequency, so that the server detects whether the terminal device is online according to the second heartbeat data, where the first heartbeat frequency is greater than the second heartbeat frequency;
or the device comprises a second detection module and a determination module, wherein:
the second detection module is configured to detect a target call request and a target hang-up request by using a server, where the target call request is a call request sent by the terminal device, and the target hang-up request is a hang-up request sent by the terminal device;
The determining module is configured to switch from a second preset time interval to a first preset time interval when the target call request is detected, detect whether the time interval for sending the heartbeat data is overtime according to first heartbeat data sent by the terminal device and the first preset time interval, and determine whether the terminal device is online according to whether the time interval is overtime, where the first heartbeat data is sent by the terminal device according to a first heartbeat frequency; or when the target hang-up request is detected, switching from the first preset time interval to the second preset time interval, detecting whether the time interval for sending the heartbeat data is overtime or not according to second heartbeat data sent by the terminal equipment and the second preset time interval, judging whether the terminal equipment is online or not according to whether the time interval is overtime, and sending the second heartbeat data by the terminal equipment according to a second heartbeat frequency, wherein the first heartbeat frequency is larger than the second heartbeat frequency, and the second preset time interval is larger than the first preset time interval.
In addition, to achieve the above object, the present invention also provides an online detection device for a terminal device, the device including a memory, a processor, and an online detection program for the terminal device stored in the memory and executable on the processor, wherein:
The step of realizing the terminal equipment online detection method of any one of the above-mentioned application to the terminal equipment when the terminal equipment online detection program is executed by the processor;
Or the terminal equipment online detection program when executed by the processor realizes the step of the terminal equipment online detection method applied to the server by any one of the above.
In addition, to achieve the above object, the present invention further provides a computer-readable storage medium, on which a terminal device online detection program is stored, which when executed by a processor, implements the steps of the terminal device online detection method described in any one of the above.
According to the method, the device and the computer readable storage medium for detecting the terminal equipment on line, the terminal equipment detects a target call request and a target hang-up request, the target call request is a call request sent by the terminal equipment or a received call request, the target hang-up request is a hang-up request initiated after the terminal equipment calls or a hang-up request sent by a called equipment, when the target call request is detected, the second heartbeat frequency is switched to the first heartbeat frequency, first heartbeat data are sent to a server according to the first heartbeat frequency, so that the server detects whether the terminal equipment is on line or not according to the first heartbeat data, or when the target hang-up request is detected, the first heartbeat frequency is switched to the second heartbeat frequency, and the second heartbeat data are sent to the server according to the second heartbeat frequency, so that the server detects whether the terminal equipment is on line or not according to the second heartbeat data, the first heartbeat frequency is larger than the second heartbeat frequency, when the terminal equipment sends the call request or receives the call request, the first heartbeat frequency is switched to the first heartbeat frequency, the first heartbeat frequency is switched to the second heartbeat frequency is high, and the first heartbeat frequency is prevented from being changed when the first heartbeat frequency is high, and the second heartbeat frequency is changed to the second heartbeat frequency is detected, and the first heartbeat frequency is not changed, and the first heartbeat frequency is high, and the on line is prevented from being sent.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
Referring to fig. 1, fig. 1 is a schematic diagram of an apparatus structure of a hardware running environment according to an embodiment of the present invention.
As shown in fig. 1, the apparatus may include: a processor 1001, such as a CPU, a communication interface 1002, a memory 1003, and a communication bus 1004. Wherein the communication bus 1004 is used to enable connected communication between these components. Communication interface 1002 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1003 may be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. The memory 1003 may alternatively be a storage device separate from the processor 1001 described above.
It will be appreciated by those skilled in the art that the device structure shown in fig. 1 is not limiting of the device and may include more or fewer components than shown, or may be combined with certain components, or a different arrangement of components.
As shown in fig. 1, an operating system and a terminal device online detection program may be included in a memory 1003 as a kind of computer storage medium.
In the apparatus shown in fig. 1, the apparatus is a terminal device, where the communication interface 1002 is mainly used to connect to a server and perform data communication with the server; and the processor 1001 may be configured to call the terminal device presence detection program stored in the memory 1003 and perform the following operations:
the terminal equipment detects a target call request and a target hang-up request, wherein the target call request is a call request sent by the terminal equipment or a received call request, and the target hang-up request is a hang-up request initiated after the terminal equipment calls or a hang-up request sent by called equipment;
When the target call request is detected, switching from a second heartbeat frequency to a first heartbeat frequency, and sending first heartbeat data to a server according to the first heartbeat frequency so that the server detects whether the terminal equipment is online or not according to the first heartbeat data;
Or when the target hang-up request is detected, switching from the first heartbeat frequency to the second heartbeat frequency, and sending second heartbeat data to the server according to the second heartbeat frequency, so that the server detects whether the terminal equipment is online or not according to the second heartbeat data, wherein the first heartbeat frequency is larger than the second heartbeat frequency.
Further, the processor 1001 may call the terminal device online detection program stored in the memory 1003, and further perform the following operations:
detecting whether an online detection request sent by the server is received or not when the target call request and the target hang-up request are not detected;
And when the online detection request sent by the server is received, sending a response detection request to the server, so that the server determines that the terminal equipment is online according to the response detection request, and/or forwarding the target call request to the called equipment according to the response detection request.
Further, the processor 1001 may call the terminal device online detection program stored in the memory 1003, and further perform the following operations:
And when the target call request sent by the server is received, sending ringing signaling to the server, switching from the second heartbeat frequency to the first heartbeat frequency, and sending the first heartbeat data to the server according to the first heartbeat frequency so that the server detects whether the terminal equipment is online according to the ringing signaling and the first heartbeat data.
Further, the processor 1001 may call the terminal device online detection program stored in the memory 1003, and further perform the following operations:
detecting whether the terminal equipment logs in or not when the target call request and the target hang-up request are not detected;
detecting whether the terminal equipment is in a call or not when the terminal equipment is logged in;
And when the terminal equipment is not in communication, sending the second heartbeat data to the server according to the second heartbeat frequency, so that the server detects whether the terminal equipment is online according to the second heartbeat data.
Or in the apparatus shown in fig. 1, the apparatus is a server, where the communication interface 1002 is mainly used for connecting to a terminal device and performing data communication with the terminal device; and the processor 1001 may be configured to call the terminal device presence detection program stored in the memory 1003 and perform the following operations:
the method comprises the steps that a server detects a target call request and a target hang-up request, wherein the target call request is a call request sent by terminal equipment, and the target hang-up request is a hang-up request sent by the terminal equipment;
When the target call request is detected, switching from a second preset time interval to a first preset time interval, detecting whether the time interval for transmitting the heartbeat data is overtime or not according to first heartbeat data transmitted by the terminal equipment and the first preset time interval, judging whether the terminal equipment is online or not according to whether the time interval for transmitting the heartbeat data is overtime or not, and transmitting the first heartbeat data by the terminal equipment according to a first heartbeat frequency;
Or when the target hang-up request is detected, switching from the first preset time interval to the second preset time interval, detecting whether the time interval for sending the heartbeat data is overtime or not according to second heartbeat data sent by the terminal equipment and the second preset time interval, judging whether the terminal equipment is online or not according to whether the time interval is overtime, and sending the second heartbeat data by the terminal equipment according to a second heartbeat frequency, wherein the first heartbeat frequency is larger than the second heartbeat frequency, and the second preset time interval is larger than the first preset time interval.
Further, the processor 1001 may call the terminal device online detection program stored in the memory 1003, and further perform the following operations:
when the target call request is detected, determining called equipment corresponding to the target call request;
Sending an online detection request to the called equipment;
when receiving a response detection request sent by the called equipment according to the online detection request, determining that the terminal equipment is online, and forwarding the target call request to the called equipment;
And when the response detection request sent by the called equipment is not received within a preset time period, determining that the called equipment is offline, and sending a call ending request to the terminal equipment so that the terminal equipment ends a call process according to the call ending request.
Further, the processor 1001 may call the terminal device online detection program stored in the memory 1003, and further perform the following operations:
Forwarding the target call request to called equipment when the target call request is detected;
And when receiving the ringing signaling sent by the called equipment according to the target call request, switching from a second preset time interval to a first preset time interval, and forwarding the ringing signaling to the calling equipment.
In the audio/video real-time call system, because the terminal equipment needs to be called up in real time, the online condition of the terminal equipment needs to be mastered in real time when needed, so that the online state real-time detection is an important function of the audio/video call system. The audio and video call terminal equipment generally maintains and judges the online state through a long connection and heartbeat method, the frequency setting of the long connection heartbeat is very critical, the process is frequently evoked when the terminal equipment is idle due to the fact that the process is too short, the resources are occupied, the electricity consumption is too large, the online state of a user cannot be judged in real time due to the fact that the terminal equipment is in false online due to the fact that the process is too long.
In order to solve the above problems, the embodiments of the present invention propose to selectively switch different heartbeat frequencies for a specific call scenario, so as to implement variable frequency heartbeat, that is, switch to a higher heartbeat frequency when a call is initiated or received, that is, reduce the time interval of sending heartbeats every two times, so as to timely detect whether a terminal device is online, switch to a lower heartbeat frequency when a hang-up is initiated or received, that is, improve the time interval of sending heartbeats every two times, thereby reducing the overhead and avoiding the resource occupation from being too high.
The technical scheme of the invention is specifically described below in connection with a plurality of embodiments.
Referring to fig. 2, a first embodiment of the present invention provides a method for online detection of a terminal device, the method including:
Step S10, the terminal equipment detects a target call request and a target hang-up request, wherein the target call request is a call request sent by the terminal equipment or a received call request, and the target hang-up request is a hang-up request initiated after the terminal equipment calls or a hang-up request sent by called equipment;
The call request sent by the terminal device refers to a call request sent by the terminal device as a calling device to a called device. The received call request refers to a call request sent by the called equipment, wherein the terminal equipment is used as the called equipment. When the call request is transmitted between the calling device and the called device, the call request is forwarded by the server as an intermediate forwarding device through the server. The hang-up request initiated after the terminal device calls refers to a hang-up request generated by the calling device actively carrying out hang-up under the condition that the terminal device is used as the calling device to carry out calling and the called device is answered. The hang-up request sent by the called equipment refers to the received hang-up request or hang-up response sent by the called equipment. Wherein the server forwards the hang-up request as an intermediate forwarding device. In addition, the target hang-up request can also be a hang-up request generated by the terminal device actively hanging-up under the condition that the called device does not answer.
The terminal device can be used as a calling device or a called device in different call scenes.
Step S20, when the target call request is detected, switching from a second heartbeat frequency to a first heartbeat frequency, and sending first heartbeat data to a server according to the first heartbeat frequency so that the server detects whether the terminal equipment is online according to the first heartbeat data;
step S30, or when the target hang-up request is detected, switching from the first heartbeat frequency to the second heartbeat frequency, and sending second heartbeat data to the server according to the second heartbeat frequency, so that the server detects whether the terminal device is online according to the second heartbeat data, wherein the first heartbeat frequency is greater than the second heartbeat frequency.
The first heartbeat frequency is preset higher than the second heartbeat frequency, the second heartbeat frequency is preset lower than the first heartbeat frequency, and the time interval between every two adjacent sending heartbeat data is shorter as the heartbeat frequency is higher. That is, the time interval between every two adjacent transmissions of heartbeat data at the first heartbeat frequency is shorter than the second heartbeat frequency. The first heartbeat data is heartbeat data transmitted at a first heartbeat frequency. The time interval of sending the heartbeat data every two adjacent times corresponding to the first heartbeat frequency can be as small as possible, so that the online state of the terminal equipment can be detected in time, for example, the time interval can be set to a few seconds or even hundreds of milliseconds, so that whether the network switch is online or not can be detected in time. The time interval of sending the heartbeat data every two adjacent times corresponding to the second heartbeat frequency can be set relatively large, for example, can be set to be several tens of minutes or even several hours, so that the terminal equipment can realize low overhead and low energy consumption in a standby state.
After the first heartbeat data or the second heartbeat data are sent to the server, the server detects whether the terminal equipment is online or not according to the first heartbeat data or the second heartbeat data. When the server detects whether the terminal equipment is online, the server actually detects whether the sending time of the heartbeat data is overtime or not, and the time interval for actually sending the heartbeat data is required to be compared with the preset time interval in the process of detecting whether the sending time of the heartbeat data is overtime or not so as to judge whether the sending time is overtime or not. It should be noted that, in the case that the terminal device is offline, the server may not always receive the heartbeat data, and at this time, if the server detects that the time interval from the last time the terminal device sent the heartbeat data has exceeded the preset time interval, it determines that the terminal device is not online. Therefore, the server side also needs to adopt the matched preset time interval to realize comparison. In order to obtain the matched preset time interval, the server side can determine the corresponding preset time interval according to the type of the received request.
The terminal device needs to send the call request or the hang-up request to the server first, and the server forwards the call request or the hang-up request to another call object. Therefore, when receiving the call request, the server can determine a first preset time interval matched with the first heartbeat frequency, and according to the first preset time interval, detect whether the first heartbeat data sent by the terminal equipment is overtime, if so, the server indicates that the terminal equipment is not on line, and if not, the server indicates that the terminal equipment is on line. When the server receives the hang-up request, a second preset time interval matched with the second heartbeat frequency can be determined, so that whether the terminal equipment sends second heartbeat data is overtime or not is detected according to the second preset time interval, if yes, the terminal equipment is not on line, and if not, the terminal equipment is on line. The first preset time interval is smaller than the second preset time interval.
By adopting the method, the terminal equipment can be well matched with the terminal equipment when the heart beat frequency is changed, the situation that the detection mode of the server is not matched with the heart beat frequency of the terminal equipment and the server is misjudged to be in an off-line state due to the mismatching is avoided.
The first preset time interval may be set according to the first heartbeat frequency, for example, the first heartbeat frequency is 2 times/second, the first heartbeat data is transmitted every 0.5 seconds, and the first preset time interval may be set to 0.5 seconds, or set to 1 second, 2 seconds, or longer. For example, the second heartbeat frequency is 1 time/hour, that is, the second heartbeat data is transmitted every 1 hour, and at this time, the second preset time interval may be set to 1 hour, or may be set to 2 hours, 3 hours, or longer.
The first heartbeat frequency and the second heartbeat frequency can be updated, and the terminal equipment updates the first heartbeat frequency and the second heartbeat frequency according to the heartbeat frequency configuration information by receiving the heartbeat frequency configuration information sent by the server. The first heartbeat frequency may be considered a fast frequency call heartbeat and the second heartbeat frequency may be considered a slow frequency keep-alive heartbeat. The condition for triggering the terminal device to switch from the first heartbeat frequency to the second heartbeat frequency may also be that the terminal device receives a hang-up request or receives a hang-up response.
The server may switch from the second preset time interval to the first preset time interval when receiving a call request or a ring signaling, and may switch from the first preset time interval to the second preset time interval when receiving a hang-up request or a hang-up response.
In this embodiment, a target call request and a target hang-up request are detected by a terminal device, where the target call request is a call request sent by the terminal device or a received call request, and the target hang-up request is a hang-up request initiated after the terminal device calls, or a hang-up request sent by a called device, when the target call request is detected, the target call request is switched from a second heartbeat frequency to a first heartbeat frequency, and first heartbeat data is sent to a server according to the first heartbeat frequency, so that the server detects whether the terminal device is online according to the first heartbeat data, or detects whether the terminal device is online or not, and sends second heartbeat data to the server according to the second heartbeat frequency, so that the server detects whether the terminal device is online according to the second heartbeat data, wherein the first heartbeat frequency is greater than the second heartbeat frequency, and can switch from the second heartbeat frequency to the first heartbeat frequency when the terminal device sends the call request or receives the call request, and the server can avoid the situation that the frequency of the second heartbeat is high, and the second heartbeat frequency is switched from the first heartbeat frequency to the second heartbeat frequency when the second heartbeat request is detected, and the second heartbeat frequency is detected to be high, and the first heartbeat frequency is not occupied.
Referring to fig. 3, a second embodiment of the present invention provides an online detection method for a terminal device, based on the first embodiment shown in fig. 2, after step S10, the method further includes:
Step S40, when the target call request and the target hang-up request are not detected, detecting whether an online detection request sent by the server is received or not;
the server stores the equipment information of the on-line terminal equipment, and when the server forwards the call request of the calling equipment, the server firstly detects whether the equipment information of the on-line terminal equipment comprises the information of the called equipment. If the equipment information of the online terminal equipment is detected to be free of the equipment information of the called equipment, the called equipment is indicated to be in an offline state, and at the moment, the server does not forward the call request to the called equipment, but directly sends the call ending request to the calling equipment, so that the calling equipment is hung up directly according to the call ending request. If the equipment information of the online terminal equipment is detected to be in the equipment information of the called equipment, in order to avoid that the called equipment is false online, at the moment, the server sends an online detection request to the called equipment, and indicates that the terminal equipment is truly online under the condition that a response detection request returned by the called equipment according to the online detection request is received, and at the moment, the call request is further forwarded to the called equipment.
Furthermore, the main reason that the terminal device is not actually online is that the terminal device may be in a keep-alive state, i.e. the terminal device is currently transmitting the second heartbeat data at the second heartbeat frequency, such as every few hours, at which time the server records that it is in a previous state but that the terminal device is not online at the present moment, and therefore the server needs to transmit an online probe request to detect whether the terminal device is actually online. Therefore, the terminal device may not be in a call state when the target call request and the target hang-up request are not detected, and at this time, if the calling device calls the terminal device, the terminal device may receive an online detection request sent by the server, so that the server detects whether the terminal device is actually online.
And step S50, when the online detection request sent by the server is received, a response detection request is sent to the server, so that the server determines that the terminal equipment is online according to the response detection request.
When receiving the online detection request sent by the server, the terminal equipment needs to prove that the terminal equipment is in a real online state, so that the terminal equipment sends a response detection request to the server, the server determines that the terminal equipment is real online according to the response detection request, and further forwards the call request to the terminal equipment.
The above-mentioned online probe request is a computer instruction for detecting whether the terminal device is online, and the response probe request is a computer instruction for the terminal device to prove that itself is online. After sending the response probe request to the server, the terminal device may continue to detect whether a call request sent by the calling device is received, and may switch from the second heartbeat frequency to the first heartbeat frequency when the call request sent by the calling device is received.
In this embodiment, in order to determine whether the terminal device is actually online, when the terminal device does not detect the target call request and the target hang-up request, whether the online detection request sent by the server is received is detected, and when the online detection request sent by the server is received, a response detection request is sent to the server, so that the server determines the terminal device according to the response detection request, thereby being capable of detecting whether the terminal device is actually online, and avoiding the situation that the terminal device is online if the detection is overtime according to an excessive time interval.
Referring to fig. 4, a third embodiment of the present invention provides an online detection method for a terminal device, based on the first embodiment shown in fig. 2, the step S20 includes:
step S21, when the target call request sent by the server is received, a ringing signaling is sent to the server, the second heartbeat frequency is switched to the first heartbeat frequency, and the first heartbeat data is sent to the server according to the first heartbeat frequency, so that the server detects whether the terminal device is online according to the ringing signaling and the first heartbeat data.
When receiving the target call request, the terminal device also needs to send a ringing signaling to the server, and after receiving the ringing signaling, the server forwards the ringing signaling to the calling device. And when receiving the target call request, the terminal equipment switches from the second heartbeat frequency to the first heartbeat frequency, and sends first heartbeat data to the server according to the first heartbeat frequency. When receiving the ringing signaling, the server switches the preset time interval for detecting whether to timeout from the second preset time interval to the first preset time interval, so that the mechanism for detecting whether to timeout is matched with the heartbeat frequency of the terminal equipment.
After receiving the ringing heartbeat, the server switches from the second preset time interval to the first preset time interval, and the situation that whether the detection on-line state is wrong caused by detecting whether the sending of the heartbeat data of the terminal equipment is overtime or not according to the second preset time interval is avoided.
In this embodiment, when receiving the target call request sent by the server, the server sends the ringing signaling, switches from the second heartbeat frequency to the first heartbeat frequency, and sends the first heartbeat data to the server according to the first heartbeat frequency, so that the server detects whether the terminal device is online according to the ringing signaling and the first heartbeat data, thereby being capable of timely adopting a higher heartbeat frequency to send the heartbeat data and timely detecting whether the terminal device is online.
Referring to fig. 5, a fourth embodiment of the present invention provides an online detection method for a terminal device, based on the first embodiment shown in fig. 2, after step S10, further including:
Step S60, detecting whether the terminal equipment logs in or not when the target call request and the target hang-up request are not detected;
Judging a login state, and if the login state is not achieved, returning to the login of the execution terminal equipment; if the call is logged in, judging whether the call is in progress, and if the judgment is based on the judgment, the terminal equipment initiates the call or the terminal equipment receives the call. If the call is in progress, setting the heartbeat of the terminal equipment to be a call heartbeat with a fast frequency, namely, sending first heartbeat data according to the first heartbeat frequency, and if the call is not in progress, setting the heartbeat of the terminal equipment to be a keep-alive heartbeat with a slow frequency, namely, sending second heartbeat data according to the second heartbeat frequency.
Step S70, detecting whether the terminal equipment is in a call or not when the terminal equipment is logged in;
When the terminal equipment is in the fast-frequency call heartbeat, namely under the condition of sending the first heartbeat data according to the first heartbeat frequency, judging whether the call is ended or not according to the condition that the terminal equipment receives a hang-up request or the terminal equipment receives a hang-up response. If the call is still in the call, the terminal equipment keeps the call heartbeat with the fast frequency, namely, sends the first heartbeat data according to the first heartbeat frequency. If the call is ended, returning to the login state judgment. When the terminal equipment is in the slow-frequency keep-alive heartbeat, namely when the second heartbeat data is sent according to the second heartbeat frequency, the judgment of returning to the login state is triggered.
And step S80, when the terminal equipment is not in communication, sending the second heartbeat data to the server according to the second heartbeat frequency so that the server detects whether the terminal equipment is online according to the second heartbeat data.
And triggering and judging whether the heartbeat is overtime according to the heartbeat frequency by the server for the logged-in terminal equipment, and setting the terminal equipment to be offline if the heartbeat is overtime. If not, judging whether the terminal equipment is in a call, and judging whether the call initiated by the terminal equipment is received or the ringing signaling of the terminal equipment is received. If the call is in progress, setting the heartbeat corresponding to the terminal equipment in the server as the call heartbeat with the fast frequency, namely switching to the first heartbeat frequency in the server to detect whether the time-out exists. If not, i.e. not in the call, it is determined whether a call to the terminal device is ready to be initiated. If the call to the terminal equipment is ready to be initiated, initiating a detection message, if not, setting the heartbeat corresponding to the terminal equipment in the server as the keep-alive heartbeat with slow frequency, namely switching to a second preset time interval in the server to detect whether the time is overtime.
After an online detection request is initiated to the terminal equipment, judging whether the terminal equipment returns a response detection request or not. If yes, the terminal equipment returns a response detection request, and then the judgment of whether the heartbeat is overtime is triggered and returned according to the heartbeat frequency. If not, the terminal equipment is set to be offline if the terminal equipment does not return the response detection request. When the heartbeat of the terminal equipment in the server is set to be the call heartbeat with the fast frequency, judging whether the call is ended or not, wherein the judging basis is whether the server receives the hang-up request or whether the server sends the hang-up request or not. If not, setting the heartbeat of the terminal equipment in the server as the call heartbeat with fast frequency in the call. If yes, returning to the judgment of whether the heartbeat of the terminal equipment is overtime. When the heartbeat of the terminal equipment in the server is set to be the keep-alive heartbeat with slow frequency, triggering to return to the judgment of whether the heartbeat of the terminal equipment is overtime according to the heartbeat frequency.
In this embodiment, whether the terminal device logs in is detected by not detecting the target call request and the target hang-up request; detecting whether the terminal equipment is in a call or not when the terminal equipment is logged in; when the terminal equipment is not in communication, second heartbeat data is sent to the server according to the second heartbeat frequency, so that the server detects whether the terminal equipment is on line or not according to the second heartbeat data, and therefore when the terminal equipment is logged in and is not in communication, the heartbeat data can be sent by adopting slow frequency, and excessive occupation of resources is avoided.
Referring to fig. 6, a fifth embodiment of the present invention provides an online detection method for a terminal device, the method including:
Step S90, a server detects a target call request and a target hang-up request, wherein the target call request is a call request sent by the terminal equipment, and the target hang-up request is a hang-up request sent by the terminal equipment;
When a call request is transmitted between a calling device and a called device, the call request also needs to be forwarded by a server, and the server serves as an intermediate forwarding device.
Step S100, when the target call request is detected, switching from a second preset time interval to a first preset time interval, detecting whether the time interval for transmitting the heartbeat data is overtime or not according to first heartbeat data transmitted by the terminal equipment and the first preset time interval, judging whether the terminal equipment is online or not according to whether the time interval for transmitting the heartbeat data is overtime, and transmitting the first heartbeat data by the terminal equipment according to a first heartbeat frequency;
forwarding the target call request to called equipment when the target call request is detected; and when receiving the ringing signaling sent by the called equipment according to the target call request, switching from a second preset time interval to a first preset time interval, and forwarding the ringing signaling to the calling equipment.
When receiving the target call request, the terminal device also needs to send a ringing signaling to the server, and after receiving the ringing signaling, the server forwards the ringing signaling to the calling device. And when receiving the target call request, the terminal equipment switches from the second heartbeat frequency to the first heartbeat frequency, and sends first heartbeat data to the server according to the first heartbeat frequency. When receiving the ringing signaling, the server switches the preset time interval for detecting whether to timeout from the second preset time interval to the first preset time interval, so that the mechanism for detecting whether to timeout is matched with the heartbeat frequency of the terminal equipment.
After receiving the ringing heartbeat, the server switches from the second preset time interval to the first preset time interval, and the situation that whether the detection on-line state is wrong caused by detecting whether the sending of the heartbeat data of the terminal equipment is overtime or not according to the second preset time interval is avoided.
And judging whether the terminal is on line or not according to the return condition of the detection message. Normally returning to the online response detection request, and enabling the terminal to be online; and if the response is not returned after the timeout, the terminal is offline. The method can avoid inconsistent heartbeat frequency of the server and the terminal when the heartbeat frequency is changed, the heartbeat frequency set by the server is high, the heartbeat frequency of the terminal equipment is low, and the server does not receive the heartbeat of the terminal equipment in the heartbeat interval time, so that the terminal equipment is misjudged to be offline.
The triggering condition of the call heartbeat of which the frequency is changed from the keep-alive heartbeat with slow frequency to the call heartbeat with fast frequency by the terminal equipment is as follows: the terminal device initiates the call or the terminal device receives the call. The triggering condition that the terminal equipment changes the frequency from the calling heartbeat with fast frequency to the keep-alive heartbeat with slow frequency is as follows: the terminal equipment receives the hang-up request or the terminal equipment receives the hang-up response. The triggering condition of the server for converting the slow keep-alive heartbeat into the fast call heartbeat is as follows: the server receives the call signaling or the server receives the ringing signaling. The triggering condition of the server for converting the quick frequency calling heartbeat into the slow frequency keep-alive heartbeat is as follows: the server receives the hang-up signaling or the server sends the hang-up signaling.
Step S110, or when the target hang-up request is detected, switching from the first preset time interval to the second preset time interval, detecting whether the time interval for sending the heartbeat data is overtime according to second heartbeat data sent by the terminal device and the second preset time interval, and judging whether the terminal device is online according to whether the time interval is overtime, wherein the second heartbeat data is sent by the terminal device according to a second heartbeat frequency, the first heartbeat frequency is greater than the second heartbeat frequency, and the second preset time interval is greater than the first preset time interval.
The first heartbeat frequency is preset higher than the second heartbeat frequency, the second heartbeat frequency is preset lower than the first heartbeat frequency, and the time interval between every two adjacent sending heartbeat data is shorter as the heartbeat frequency is higher. That is, the first heartbeat frequency is shorter than the second heartbeat frequency for the time interval between every adjacent two transmissions of heartbeat data. The first heartbeat data is heartbeat data transmitted at a first heartbeat frequency. The time interval of sending the heartbeat data every two adjacent times corresponding to the first heartbeat frequency can be as small as possible, so that the online state of the terminal equipment can be detected in time, for example, the time interval can be set to a few seconds or even hundreds of milliseconds, so that whether the network switch is online or not can be detected in time. The time interval of sending the heartbeat data every two adjacent times corresponding to the second heartbeat frequency can be set relatively large, for example, can be set to be several tens of minutes or even several hours, so that the terminal equipment can realize low overhead and low energy consumption in a standby state.
After the first heartbeat data or the second heartbeat data are sent to the server, the server detects whether the terminal equipment is online or not according to the first heartbeat data or the second heartbeat data. When the server detects whether the terminal equipment is online, the server actually detects whether the sending time of the heartbeat data is overtime or not, and the time interval for actually sending the heartbeat data is required to be compared with the preset time interval in the process of detecting whether the sending time of the heartbeat data is overtime or not so as to judge whether the sending time is overtime or not. It should be noted that, in the case that the terminal device is offline, the server may not always receive the heartbeat data, and at this time, if the server detects that the time interval from the last time the terminal device sent the heartbeat data has exceeded the preset time interval, it determines that the terminal device is not online. Therefore, the server side also needs to adopt the matched preset time interval to realize comparison. In order to obtain the matched preset time interval, the server side can determine the corresponding preset time interval according to the type of the received request.
The terminal device needs to send the call request or the hang-up request to the server first, and the server forwards the call request or the hang-up request to another call object. Therefore, when receiving the call request, the server can determine a first preset time interval matched with the first heartbeat frequency, and according to the first preset time interval, detect whether the first heartbeat data sent by the terminal equipment is overtime, if so, the server indicates that the terminal equipment is not on line, and if not, the server indicates that the terminal equipment is on line. When the server receives the hang-up request, a second preset time interval matched with the second heartbeat frequency can be determined, so that whether the terminal equipment sends second heartbeat data is overtime or not is detected according to the second preset time interval, if yes, the terminal equipment is not on line, and if not, the terminal equipment is on line. By adopting the method, the terminal equipment can be well matched with the terminal equipment when the heart beat frequency is changed, the situation that the detection mode of the server is not matched with the heart beat frequency of the terminal equipment and the server is misjudged to be in an off-line state due to the mismatching is avoided.
The first preset time interval may be set according to the first heartbeat frequency, for example, the first heartbeat frequency is 2 times/second, the first heartbeat data is transmitted every 0.5 seconds, and the first preset time interval may be set to 0.5 seconds, or set to 1 second, 2 seconds, or longer. For example, the second heartbeat frequency is 1 time/hour, that is, the second heartbeat data is transmitted every 1 hour, and at this time, the second preset time interval may be set to 1 hour, or may be set to 2 hours, 3 hours, or longer.
The condition for triggering the terminal device to switch from the first heartbeat frequency to the second heartbeat frequency may also be that the terminal device receives a hang-up request or receives a hang-up response. The server may switch from the second preset time interval to the first preset time interval when receiving a call request or a ring signaling, and may switch from the first preset time interval to the second preset time interval when receiving a hang-up request or a hang-up response.
The heartbeat frequency conversion is based on login and call state, namely when the user is in a login state without call, the connection between the slow-frequency keep-alive heartbeat and the server is kept active, and if the server does not receive the heartbeat signaling packet of the terminal equipment in a plurality of heartbeat interval time, the server judges that the terminal equipment is offline.
In this embodiment, a server detects a target call request and a target hang-up request, where the target call request is a call request sent by the terminal device, and the target hang-up request is a hang-up request sent by the terminal device; when the target call request is detected, switching from a second preset time interval to a first preset time interval, detecting whether the time interval for transmitting the heartbeat data is overtime or not according to first heartbeat data transmitted by the terminal equipment and the first preset time interval, judging whether the terminal equipment is online or not according to whether the time interval for transmitting the heartbeat data is overtime or not, and transmitting the first heartbeat data by the terminal equipment according to a first heartbeat frequency; or when the target hang-up request is detected, switching from the first preset time interval to the second preset time interval, detecting whether the time interval for sending the heartbeat data is overtime or not according to second heartbeat data sent by the terminal equipment and the second preset time interval, judging whether the terminal equipment is online or not according to whether the time interval is overtime, and sending the second heartbeat data by the terminal equipment according to a second heartbeat frequency, wherein the first heartbeat frequency is larger than the second heartbeat frequency, and the second preset time interval is larger than the first preset time interval. Therefore, excessive occupation of resources can be avoided, and whether the terminal equipment is on-line or not can be timely detected.
Referring to fig. 7, a sixth embodiment of the present invention provides an online detection method for a terminal device, based on the fifth embodiment shown in fig. 6, after step S90, further including:
Step S120, when the target call request is detected, determining called equipment corresponding to the target call request;
the server stores the equipment information of the on-line terminal equipment, and when the server forwards the call request of the calling equipment, the server firstly detects whether the equipment information of the on-line terminal equipment comprises the information of the called equipment. If the equipment information of the online terminal equipment is detected to be free of the equipment information of the called equipment, the called equipment is indicated to be in an offline state, and at the moment, the server does not forward the call request to the called equipment, but directly sends the call ending request to the calling equipment, so that the calling equipment is hung up directly according to the call ending request. If the equipment information of the online terminal equipment is detected to be in the equipment information of the called equipment, in order to avoid that the called equipment is false online, at the moment, the server sends an online detection request to the called equipment, and indicates that the terminal equipment is truly online under the condition that a response detection request returned by the called equipment according to the online detection request is received, and at the moment, the call request is further forwarded to the called equipment.
Furthermore, the main reason that the terminal device is not actually online is that the terminal device may be in a keep-alive state, i.e. the terminal device is currently transmitting the second heartbeat data at the second heartbeat frequency, such as every few hours, at which time the server records that it is in a previous state but that the terminal device is not online at the present moment, and therefore the server needs to transmit an online probe request to detect whether the terminal device is actually online. Therefore, the terminal device may not be in a call state when the target call request and the target hang-up request are not detected, and at this time, if the calling device calls the terminal device, the terminal device may receive an online detection request sent by the server, so that the server detects whether the terminal device is actually online.
Step S130, an online detection request is sent to the called equipment;
Step S140, when receiving a response detection request sent by the called equipment according to the online detection request, determining that the terminal equipment is online, and forwarding the target call request to the called equipment;
before the call records the current online terminal equipment according to the heartbeat message, an online detection request is initiated, if the terminal equipment does not return to the online response detection request after overtime, the terminal equipment is judged to be offline. The false online condition of the terminal equipment can be avoided when the heartbeat frequency is low and the interval time is long.
When receiving the online detection request sent by the server, the terminal equipment needs to prove that the terminal equipment is in a real online state, so that the terminal equipment sends a response detection request to the server, the server determines that the terminal equipment is real online according to the response detection request, and further forwards the call request to the terminal equipment.
The above-mentioned online probe request is a computer instruction for detecting whether the terminal device is online, and the response probe request is a computer instruction for the terminal device to prove that itself is online. After sending the response probe request to the server, the terminal device may continue to detect whether a call request sent by the calling device is received, and may switch from the second heartbeat frequency to the first heartbeat frequency when the call request sent by the calling device is received.
And step S150, when the response detection request sent by the called equipment is not received within a preset time period, determining that the called equipment is offline, and sending a call ending request to the terminal equipment so that the terminal equipment ends a call process according to the call ending request.
Before the server initiates a call to the called party, an online detection request is sent to detect the real online condition of the called terminal. Sending an online detection request, and if the called party returns a response within the timeout time, judging that the called party is truly online; if the called party does not return the response, the called party is judged to be offline.
In this embodiment, when the target call request is detected, determining a called device corresponding to the target call request; sending an online detection request to the called equipment; when receiving a response detection request sent by the called equipment according to the online detection request, determining that the terminal equipment is online, and forwarding the target call request to the called equipment; and when the response detection request sent by the called equipment is not received within a preset time period, determining that the called equipment is offline, and sending a call ending request to the terminal equipment so that the terminal equipment ends a call process according to the call ending request. Thereby being capable of detecting whether the terminal device is truly online.
Referring to fig. 8, fig. 8 is a schematic diagram of communication interaction among a calling terminal device, a called terminal device and a server according to the present invention, and an embodiment of online detection of a terminal device in a specific scenario is described in conjunction with fig. 8.
After logging in, the terminal equipment is connected and kept between the non-talking state and the audio/video talking server through the slow frequency keep-alive heartbeat, and the slow frequency keep-alive heartbeat refers to sending second heartbeat data according to the second heartbeat frequency. The calling terminal equipment initiates a call request, and changes the heartbeat into a quick-frequency call heartbeat, wherein the quick-frequency call heartbeat refers to the first heartbeat data sent according to the first heartbeat frequency.
After receiving the call request of the calling terminal equipment, the server changes the heartbeat into the call heartbeat with fast frequency, inquires the online state of the called terminal equipment, and if the online state is on line, sends an online detection request to the called terminal equipment. If the called terminal equipment is overtime and does not answer the online detection request, judging that the called terminal equipment is false online, modifying the called terminal equipment into an offline state, and sending a call termination response to the calling terminal equipment. If the called terminal equipment returns a response detection request within the timeout time, judging that the called terminal equipment is truly online, and initiating a call request to the called terminal equipment by the server. After receiving the call request, the called terminal device changes the heartbeat into a quick-frequency call heartbeat and returns a ringing signaling to the server.
The server receives the ringing signaling of the called terminal equipment, changes the heartbeat with the called terminal equipment into the calling heartbeat with fast frequency, and simultaneously sends the ringing signaling to the calling terminal equipment. After the called terminal equipment answers, an answer signaling is sent to a server, and the server forwards the answer signaling to the calling terminal equipment, so that an audio-video call is established. The hang-up scene includes, but is not limited to, hang-up when the called ringing is not answered, hang-up when the called answering ends the call, the calling cancels the hang-up of the call request when the called ringing is not answered, and the calling ends the hang-up when the called answering. In this case, the called terminal device sends a hang-up request to the server, and after receiving the hang-up request, the server changes the heartbeat with the called terminal device into a keep-alive heartbeat with a slow frequency and sends a hang-up response to the called terminal device.
After receiving the hang-up response of the server, the called terminal equipment changes the heartbeat into a keep-alive heartbeat with slow frequency. Meanwhile, the server changes the heartbeat with the calling terminal equipment into a keep-alive heartbeat with a slow frequency, and sends a hang-up request to the calling terminal equipment. The calling terminal equipment receives the hang-up request of the server, changes the heartbeat into the keep-alive heartbeat with slow frequency, and returns a hang-up response to the server. So far, the calling terminal equipment and the called terminal equipment are restored to the low-frequency keep-alive heartbeat of the login online non-communication.
Fig. 9 is a schematic diagram of an embodiment of an online detection apparatus for a terminal device according to the present invention, where the apparatus includes:
The first detection module 10 is configured to detect, by the terminal device, a target call request and a target hang-up request, where the target call request is a call request sent by the terminal device or a received call request, and the target hang-up request is a hang-up request initiated after the terminal device calls, or a hang-up request sent by a called device;
And the sending module 20 is configured to switch from a second heartbeat frequency to a first heartbeat frequency when the target call request is detected, and send first heartbeat data to a server according to the first heartbeat frequency, so that the server detects whether the terminal device is online according to the first heartbeat data, or switch from the first heartbeat frequency to the second heartbeat frequency when the target hang-up request is detected, and send second heartbeat data to the server according to the second heartbeat frequency, so that the server detects whether the terminal device is online according to the second heartbeat data, where the first heartbeat frequency is greater than the second heartbeat frequency.
Fig. 10 is a schematic diagram of another embodiment of an online detection apparatus for a terminal device according to the present invention, where the apparatus includes:
The second detection module 30 is configured to detect a target call request and a target hang-up request by using a server, where the target call request is a call request sent by the terminal device, and the target hang-up request is a hang-up request sent by the terminal device;
The determining module 40 is configured to switch from a second preset time interval to a first preset time interval when the target call request is detected, detect whether the time interval for sending the heartbeat data is overtime according to first heartbeat data sent by the terminal device and the first preset time interval, and determine whether the terminal device is online according to whether the time interval is overtime, where the first heartbeat data is sent by the terminal device according to a first heartbeat frequency; or when the target hang-up request is detected, switching from the first preset time interval to the second preset time interval, detecting whether the time interval for sending the heartbeat data is overtime or not according to second heartbeat data sent by the terminal equipment and the second preset time interval, judging whether the terminal equipment is online or not according to whether the time interval is overtime, and sending the second heartbeat data by the terminal equipment according to a second heartbeat frequency, wherein the first heartbeat frequency is larger than the second heartbeat frequency, and the second preset time interval is larger than the first preset time interval.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The foregoing embodiment numbers of the present invention are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) as described above, comprising instructions for causing a terminal device on-line detection means to perform the method according to the embodiments of the present invention.
The foregoing description is only of the preferred embodiments of the present invention, and is not intended to limit the scope of the invention, but rather is intended to cover any equivalents of the structures or equivalent processes disclosed herein or in the alternative, which may be employed directly or indirectly in other related arts.