Handle message answer

This commit is contained in:
Yang Luo
2023-05-02 01:30:06 +08:00
parent 2cd6f9df8e
commit 84a7fdcd07
7 changed files with 93 additions and 17 deletions

View File

@ -45,13 +45,20 @@ export function getMessage(owner, name) {
}
export function getMessageAnswer(owner, name, onMessage, onError) {
const source = new EventSource(`${Setting.ServerUrl}/api/get-message-answer?id=${owner}/${encodeURIComponent(name)}`);
source.onmessage = function(event) {
onMessage(event.data);
};
source.onerror = function(error) {
onError(error);
};
const eventSource = new EventSource(`${Setting.ServerUrl}/api/get-message-answer?id=${owner}/${encodeURIComponent(name)}`);
eventSource.addEventListener("message", (e) => {
onMessage(e.data);
});
eventSource.addEventListener("myerror", (e) => {
onError(e.data);
eventSource.close();
});
eventSource.addEventListener("end", (e) => {
eventSource.close();
});
}
export function updateMessage(owner, name, message) {