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

65 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-05-18 20:08:54 +00:00
"use strict";
import Vue from "vue";
2017-05-18 20:08:54 +00:00
const socket = require("../socket");
const store = require("../store").default;
2019-11-11 19:18:55 +00:00
const {switchToChannel} = require("../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]);
2019-11-11 19:18:55 +00:00
switchToChannel(network.channels[0]);
2017-05-18 20:08:54 +00:00
});
2018-07-19 17:44:24 +00:00
socket.on("network:options", function(data) {
const network = store.getters.findNetwork(data.network);
if (network) {
network.serverOptions = data.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) {
Vue.set(network, key, data[key]);
2019-11-02 18:45:00 +00:00
}
});