|
@@ -6,6 +6,8 @@ import log from "electron-log/main";
|
|
import { handeGet, handeSet } from "./store";
|
|
import { handeGet, handeSet } from "./store";
|
|
import io from "socket.io-client";
|
|
import io from "socket.io-client";
|
|
|
|
|
|
|
|
+export let socket: any = null;
|
|
|
|
+
|
|
export const initTray = () => {
|
|
export const initTray = () => {
|
|
const handlePath = (icon: string) => {
|
|
const handlePath = (icon: string) => {
|
|
return url ? path.join(PUBLIC!, icon) : path.join(DIST, icon);
|
|
return url ? path.join(PUBLIC!, icon) : path.join(DIST, icon);
|
|
@@ -54,16 +56,17 @@ export const initTray = () => {
|
|
|
|
|
|
// 服务端地址
|
|
// 服务端地址
|
|
const SOCKET_URL = "http://114.215.252.134:2120";
|
|
const SOCKET_URL = "http://114.215.252.134:2120";
|
|
- const socket = io(SOCKET_URL, {
|
|
|
|
|
|
+ socket = io(SOCKET_URL, {
|
|
reconnection: true,
|
|
reconnection: true,
|
|
reconnectionDelay: 1000,
|
|
reconnectionDelay: 1000,
|
|
timeout: 20000,
|
|
timeout: 20000,
|
|
});
|
|
});
|
|
- // socket连接后以uid登录
|
|
|
|
|
|
+
|
|
|
|
+ // socket连接后等待 uid
|
|
socket.on("connect", function () {
|
|
socket.on("connect", function () {
|
|
- console.log("Connected via CDN ES6");
|
|
|
|
- socket.emit("login", 123);
|
|
|
|
|
|
+ console.log("Socket connected, waiting for uid...");
|
|
});
|
|
});
|
|
|
|
+
|
|
// 后端推送来消息时
|
|
// 后端推送来消息时
|
|
socket.on("new_msg", function (msg) {
|
|
socket.on("new_msg", function (msg) {
|
|
const fixedData = msg.replace(/"/g, '"');
|
|
const fixedData = msg.replace(/"/g, '"');
|