2017-05-18 20:08:54 +00:00
|
|
|
"use strict";
|
|
|
|
|
2019-11-11 21:39:09 +00:00
|
|
|
import Vue from "vue";
|
|
|
|
|
2019-11-16 17:24:03 +00:00
|
|
|
import socket from "../socket";
|
|
|
|
import store from "../store";
|
|
|
|
import {switchToChannel} from "../router";
|
2017-05-18 20:08:54 +00:00
|
|
|
|
2020-03-21 20:55:36 +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
|
|
|
|
2019-11-02 19:40:59 +00:00
|
|
|
store.commit("networks", [...store.state.networks, network]);
|
2020-01-16 16:07:16 +00:00
|
|
|
|
|
|
|
// Open last channel specified in `join`
|
|
|
|
switchToChannel(network.channels[network.channels.length - 1]);
|
2017-05-18 20:08:54 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
socket.on("network:options", function (data) {
|
2019-11-03 14:59:43 +00:00
|
|
|
const network = store.getters.findNetwork(data.network);
|
2019-11-02 19:40:59 +00:00
|
|
|
|
|
|
|
if (network) {
|
|
|
|
network.serverOptions = data.serverOptions;
|
|
|
|
}
|
2017-05-18 20:08:54 +00:00
|
|
|
});
|
2018-02-19 11:12:01 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
socket.on("network:status", function (data) {
|
2019-11-03 14:59:43 +00:00
|
|
|
const network = store.getters.findNetwork(data.network);
|
2018-09-19 14:48:13 +00:00
|
|
|
|
|
|
|
if (!network) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-06 18:15:15 +00:00
|
|
|
network.status.connected = data.connected;
|
|
|
|
network.status.secure = data.secure;
|
2018-07-19 18:03:53 +00:00
|
|
|
|
|
|
|
if (!data.connected) {
|
2018-08-24 08:29:03 +00:00
|
|
|
network.channels.forEach((channel) => {
|
|
|
|
channel.users = [];
|
|
|
|
channel.state = 0;
|
|
|
|
});
|
2018-07-19 18:03:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
socket.on("channel:state", function (data) {
|
2019-11-03 14:59:43 +00:00
|
|
|
const channel = store.getters.findChannel(data.chan);
|
2018-07-19 18:03:53 +00:00
|
|
|
|
|
|
|
if (channel) {
|
|
|
|
channel.channel.state = data.state;
|
|
|
|
}
|
2018-02-19 11:12:01 +00:00
|
|
|
});
|
2018-03-15 08:37:32 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
socket.on("network:info", function (data) {
|
2019-11-03 14:59:43 +00:00
|
|
|
const network = store.getters.findNetwork(data.uuid);
|
2019-11-02 18:45:00 +00:00
|
|
|
|
|
|
|
if (!network) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const key in data) {
|
2019-11-11 21:39:09 +00:00
|
|
|
Vue.set(network, key, data[key]);
|
2019-11-02 18:45:00 +00:00
|
|
|
}
|
2018-03-15 08:37:32 +00:00
|
|
|
});
|
2019-10-28 16:11:45 +00:00
|
|
|
|
|
|
|
socket.on("network:name", function (data) {
|
|
|
|
const network = store.getters.findNetwork(data.uuid);
|
|
|
|
network.name = network.channels[0].name = data.name;
|
|
|
|
});
|