hardlounge/client/js/socket-events/network.ts

71 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

2019-11-16 17:24:03 +00:00
import socket from "../socket";
import {store} from "../store";
2019-11-16 17:24:03 +00:00
import {switchToChannel} from "../router";
2017-05-18 20:08:54 +00:00
socket.on("network", function (data) {
2018-07-12 18:33:52 +00:00
const network = data.networks[0];
2017-05-18 20:08:54 +00:00
2018-07-12 19:06:17 +00:00
network.isJoinChannelShown = false;
network.isCollapsed = false;
2019-11-12 15:51:40 +00:00
network.channels.forEach(store.getters.initChannel);
2018-07-12 19:06:17 +00:00
store.commit("networks", [...store.state.networks, network]);
// Open last channel specified in `join`
switchToChannel(network.channels[network.channels.length - 1]);
2017-05-18 20:08:54 +00:00
});
socket.on("network:options", function (data) {
const network = store.getters.findNetwork(data.network);
if (network) {
network.serverOptions = data.serverOptions as typeof network.serverOptions;
}
2017-05-18 20:08:54 +00:00
});
socket.on("network:status", function (data) {
const network = store.getters.findNetwork(data.network);
if (!network) {
return;
}
network.status.connected = data.connected;
network.status.secure = data.secure;
if (!data.connected) {
network.channels.forEach((channel) => {
channel.users = [];
channel.state = 0;
});
}
});
socket.on("channel:state", function (data) {
const channel = store.getters.findChannel(data.chan);
if (channel) {
channel.channel.state = data.state;
}
});
socket.on("network:info", function (data) {
const network = store.getters.findNetwork(data.uuid);
2019-11-02 18:45:00 +00:00
if (!network) {
return;
}
for (const key in data) {
network[key] = data[key];
2019-11-02 18:45:00 +00:00
}
});
socket.on("network:name", function (data) {
const network = store.getters.findNetwork(data.uuid);
if (network) {
network.name = network.channels[0].name = data.name;
}
});