mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 17:46:28 +08:00
socket 断线自动重连,文件上传功能
This commit is contained in:
1 parent
95bfd98b43
commit
10956f1fee
18 files changed
+157
-50
No files matched your search
@@ -1,25 +1,19 @@
|
||||
import { AutoloadPage } from 'vj/misc/PageLoader';
|
||||
import Notification from 'vj/components/notification';
|
||||
import i18n from 'vj/utils/i18n';
|
||||
|
||||
const messagePage = new AutoloadPage('messagePage', () => {
|
||||
async function init(isReconnect = false) {
|
||||
const { default: SockJs } = await import('sockjs-client');
|
||||
async function init() {
|
||||
const { default: SockJs } = await import('../socket');
|
||||
|
||||
const sock = new SockJs(`/home/messages-conn?token=${UiContext.token}`);
|
||||
sock.onopen = () => {
|
||||
if (isReconnect) Notification.info('Reconnected');
|
||||
};
|
||||
sock.onmessage = (message) => {
|
||||
const msg = JSON.parse(message.data);
|
||||
console.log(msg);
|
||||
Notification.show({ title: msg.udoc.uname, message: msg.mdoc.content, duration: 0 });
|
||||
};
|
||||
sock.onclose = () => {
|
||||
Notification.warn(i18n('Disconnected from the server. Reconnecting...'));
|
||||
setTimeout(() => {
|
||||
init(true);
|
||||
}, 3000);
|
||||
Notification.show({
|
||||
title: msg.udoc.uname,
|
||||
avatar: msg.udoc.gravatar,
|
||||
message: msg.mdoc.content,
|
||||
duration: 0,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user