This commit is contained in:
syuilo 2020-09-06 13:04:44 +09:00
parent d4085085b8
commit cc35f2c186
18 changed files with 38 additions and 44 deletions

View File

@ -141,7 +141,7 @@ export default defineComponent({
}); });
} }
this.connection = this.$root.stream.useSharedConnection('drive'); this.connection = os.stream.useSharedConnection('drive');
this.connection.on('fileCreated', this.onStreamDriveFileCreated); this.connection.on('fileCreated', this.onStreamDriveFileCreated);
this.connection.on('fileUpdated', this.onStreamDriveFileUpdated); this.connection.on('fileUpdated', this.onStreamDriveFileUpdated);

View File

@ -69,7 +69,7 @@ export default defineComponent({
}, },
mounted() { mounted() {
this.connection = this.$root.stream.useSharedConnection('main'); this.connection = os.stream.useSharedConnection('main');
this.connection.on('follow', this.onFollowChange); this.connection.on('follow', this.onFollowChange);
this.connection.on('unfollow', this.onFollowChange); this.connection.on('unfollow', this.onFollowChange);

View File

@ -253,7 +253,7 @@ export default defineComponent({
async created() { async created() {
if (this.$store.getters.isSignedIn) { if (this.$store.getters.isSignedIn) {
this.connection = this.$root.stream; this.connection = os.stream;
} }
// plugin // plugin

View File

@ -104,7 +104,7 @@ export default defineComponent({
if (!this.notification.isRead) { if (!this.notification.isRead) {
this.readObserver = new IntersectionObserver((entries, observer) => { this.readObserver = new IntersectionObserver((entries, observer) => {
if (!entries.some(entry => entry.isIntersecting)) return; if (!entries.some(entry => entry.isIntersecting)) return;
this.$root.stream.send('readNotification', { os.stream.send('readNotification', {
id: this.notification.id id: this.notification.id
}); });
entries.map(({ target }) => observer.unobserve(target)); entries.map(({ target }) => observer.unobserve(target));
@ -112,7 +112,7 @@ export default defineComponent({
this.readObserver.observe(this.$el); this.readObserver.observe(this.$el);
this.connection = this.$root.stream.useSharedConnection('main'); this.connection = os.stream.useSharedConnection('main');
this.connection.on('readAllNotifications', () => this.readObserver.unobserve(this.$el)); this.connection.on('readAllNotifications', () => this.readObserver.unobserve(this.$el));
} }
}, },

View File

@ -75,7 +75,7 @@ export default defineComponent({
}, },
mounted() { mounted() {
this.connection = this.$root.stream.useSharedConnection('main'); this.connection = os.stream.useSharedConnection('main');
this.connection.on('notification', this.onNotification); this.connection.on('notification', this.onNotification);
}, },
@ -88,7 +88,7 @@ export default defineComponent({
// //
const isMuted = !!this.allIncludeTypes && !this.allIncludeTypes.includes(notification.type); const isMuted = !!this.allIncludeTypes && !this.allIncludeTypes.includes(notification.type);
if (isMuted || document.visibilityState === 'visible') { if (isMuted || document.visibilityState === 'visible') {
this.$root.stream.send('readNotification', { os.stream.send('readNotification', {
id: notification.id id: notification.id
}); });
} }

View File

@ -20,14 +20,14 @@ export default defineComponent({
}, },
computed: { computed: {
stream() { stream() {
return this.$root.stream; return os.stream;
}, },
}, },
created() { created() {
this.$root.stream.on('_disconnected_', this.onDisconnected); os.stream.on('_disconnected_', this.onDisconnected);
}, },
beforeDestroy() { beforeDestroy() {
this.$root.stream.off('_disconnected_', this.onDisconnected); os.stream.off('_disconnected_', this.onDisconnected);
}, },
methods: { methods: {
onDisconnected() { onDisconnected() {

View File

@ -88,36 +88,36 @@ export default defineComponent({
this.query = { this.query = {
antennaId: this.antenna antennaId: this.antenna
}; };
this.connection = this.$root.stream.connectToChannel('antenna', { this.connection = os.stream.connectToChannel('antenna', {
antennaId: this.antenna antennaId: this.antenna
}); });
this.connection.on('note', prepend); this.connection.on('note', prepend);
} else if (this.src == 'home') { } else if (this.src == 'home') {
endpoint = 'notes/timeline'; endpoint = 'notes/timeline';
this.connection = this.$root.stream.useSharedConnection('homeTimeline'); this.connection = os.stream.useSharedConnection('homeTimeline');
this.connection.on('note', prepend); this.connection.on('note', prepend);
this.connection2 = this.$root.stream.useSharedConnection('main'); this.connection2 = os.stream.useSharedConnection('main');
this.connection2.on('follow', onChangeFollowing); this.connection2.on('follow', onChangeFollowing);
this.connection2.on('unfollow', onChangeFollowing); this.connection2.on('unfollow', onChangeFollowing);
} else if (this.src == 'local') { } else if (this.src == 'local') {
endpoint = 'notes/local-timeline'; endpoint = 'notes/local-timeline';
this.connection = this.$root.stream.useSharedConnection('localTimeline'); this.connection = os.stream.useSharedConnection('localTimeline');
this.connection.on('note', prepend); this.connection.on('note', prepend);
} else if (this.src == 'social') { } else if (this.src == 'social') {
endpoint = 'notes/hybrid-timeline'; endpoint = 'notes/hybrid-timeline';
this.connection = this.$root.stream.useSharedConnection('hybridTimeline'); this.connection = os.stream.useSharedConnection('hybridTimeline');
this.connection.on('note', prepend); this.connection.on('note', prepend);
} else if (this.src == 'global') { } else if (this.src == 'global') {
endpoint = 'notes/global-timeline'; endpoint = 'notes/global-timeline';
this.connection = this.$root.stream.useSharedConnection('globalTimeline'); this.connection = os.stream.useSharedConnection('globalTimeline');
this.connection.on('note', prepend); this.connection.on('note', prepend);
} else if (this.src == 'list') { } else if (this.src == 'list') {
endpoint = 'notes/user-list-timeline'; endpoint = 'notes/user-list-timeline';
this.query = { this.query = {
listId: this.list listId: this.list
}; };
this.connection = this.$root.stream.connectToChannel('userList', { this.connection = os.stream.connectToChannel('userList', {
listId: this.list listId: this.list
}); });
this.connection.on('note', prepend); this.connection.on('note', prepend);
@ -128,7 +128,7 @@ export default defineComponent({
this.query = { this.query = {
channelId: this.channel channelId: this.channel
}; };
this.connection = this.$root.stream.connectToChannel('channel', { this.connection = os.stream.connectToChannel('channel', {
channelId: this.channel channelId: this.channel
}); });
this.connection.on('note', prepend); this.connection.on('note', prepend);

View File

@ -108,7 +108,7 @@ export default defineComponent({
window.addEventListener('wheel', this.onWheel); window.addEventListener('wheel', this.onWheel);
if (this.$store.getters.isSignedIn) { if (this.$store.getters.isSignedIn) {
this.connection = this.$root.stream.useSharedConnection('main'); this.connection = os.stream.useSharedConnection('main');
this.connection.on('notification', this.onNotification); this.connection.on('notification', this.onNotification);
} }
}, },
@ -162,7 +162,7 @@ export default defineComponent({
} }
if (document.visibilityState === 'visible') { if (document.visibilityState === 'visible') {
this.$root.stream.send('readNotification', { os.stream.send('readNotification', {
id: notification.id id: notification.id
}); });

View File

@ -202,7 +202,7 @@ export default defineComponent({
document.documentElement.style.overflowY = 'scroll'; document.documentElement.style.overflowY = 'scroll';
if (this.$store.getters.isSignedIn) { if (this.$store.getters.isSignedIn) {
this.connection = this.$root.stream.useSharedConnection('main'); this.connection = os.stream.useSharedConnection('main');
this.connection.on('notification', this.onNotification); this.connection.on('notification', this.onNotification);
if (this.$store.state.deviceUser.widgets.length === 0) { if (this.$store.state.deviceUser.widgets.length === 0) {
@ -331,7 +331,7 @@ export default defineComponent({
return; return;
} }
if (document.visibilityState === 'visible') { if (document.visibilityState === 'visible') {
this.$root.stream.send('readNotification', { os.stream.send('readNotification', {
id: notification.id id: notification.id
}); });

View File

@ -11,7 +11,6 @@ import { deserialize } from '@syuilo/aiscript/built/serializer';
import VueHotkey from '@/scripts/hotkey'; import VueHotkey from '@/scripts/hotkey';
import Root from './root.vue'; import Root from './root.vue';
import Stream from '@/scripts/stream';
import widgets from './widgets'; import widgets from './widgets';
import directives from './directives'; import directives from './directives';
import components from '@/components'; import components from '@/components';
@ -22,6 +21,7 @@ import { applyTheme, lightTheme } from '@/scripts/theme';
import { isDeviceDarkmode } from '@/scripts/is-device-darkmode'; import { isDeviceDarkmode } from '@/scripts/is-device-darkmode';
import { createPluginEnv } from '@/scripts/aiscript/api'; import { createPluginEnv } from '@/scripts/aiscript/api';
import { i18n, lang } from './i18n'; import { i18n, lang } from './i18n';
import { stream } from '@/os';
console.info(`Misskey v${version}`); console.info(`Misskey v${version}`);
@ -112,7 +112,7 @@ if (store.state.i != null) {
if (i != null && i !== 'null') { if (i != null && i !== 'null') {
try { try {
const me = await fetchme(i); const me = await fetchme(i);
store.dispatch('login', me); await store.dispatch('login', me);
} catch (e) { } catch (e) {
// Render the error screen // Render the error screen
// TODO: ちゃんとしたコンポーネントをレンダリングする(v10とかのトラブルシューティングゲーム付きのやつみたいな) // TODO: ちゃんとしたコンポーネントをレンダリングする(v10とかのトラブルシューティングゲーム付きのやつみたいな)
@ -122,11 +122,9 @@ if (store.state.i != null) {
} }
//#endregion //#endregion
const stream = new Stream(store.state.i); stream.init(store.state.i);
const app = createApp(Root, { const app = createApp(Root);
stream
});
app.use(store); app.use(store);
app.use(router); app.use(router);

View File

@ -1,6 +1,9 @@
import { defineAsyncComponent } from 'vue'; import { defineAsyncComponent } from 'vue';
import Stream from '@/scripts/stream';
import { store } from './store'; import { store } from './store';
export const stream = new Stream();
export function api(endpoint: string, data: Record<string, any> = {}, token?: string | null | undefined) { export function api(endpoint: string, data: Record<string, any> = {}, token?: string | null | undefined) {
return store.dispatch('api', { endpoint, data, token }); return store.dispatch('api', { endpoint, data, token });
} }

View File

@ -234,7 +234,7 @@ export default defineComponent({
stats: null, stats: null,
serverInfo: null, serverInfo: null,
connection: null, connection: null,
queueConnection: this.$root.stream.useSharedConnection('queueStats'), queueConnection: os.stream.useSharedConnection('queueStats'),
memUsage: 0, memUsage: 0,
chartCpuMem: null, chartCpuMem: null,
chartNet: null, chartNet: null,
@ -499,7 +499,7 @@ export default defineComponent({
os.api('admin/server-info', {}).then(res => { os.api('admin/server-info', {}).then(res => {
this.serverInfo = res; this.serverInfo = res;
this.connection = this.$root.stream.useSharedConnection('serverStats'); this.connection = os.stream.useSharedConnection('serverStats');
this.connection.on('stats', this.onStats); this.connection.on('stats', this.onStats);
this.connection.on('statsLog', this.onStatsLog); this.connection.on('statsLog', this.onStatsLog);
this.connection.send('requestLog', { this.connection.send('requestLog', {

View File

@ -38,7 +38,7 @@ export default defineComponent({
data() { data() {
return { return {
connection: this.$root.stream.useSharedConnection('queueStats'), connection: os.stream.useSharedConnection('queueStats'),
faExchangeAlt, faTrashAlt faExchangeAlt, faTrashAlt
} }
}, },

View File

@ -63,7 +63,7 @@ export default defineComponent({
}, },
mounted() { mounted() {
this.connection = this.$root.stream.useSharedConnection('messagingIndex'); this.connection = os.stream.useSharedConnection('messagingIndex');
this.connection.on('message', this.onMessage); this.connection.on('message', this.onMessage);
this.connection.on('read', this.onRead); this.connection.on('read', this.onRead);

View File

@ -107,7 +107,7 @@ export default defineComponent({
this.group = group; this.group = group;
} }
this.connection = this.$root.stream.connectToChannel('messaging', { this.connection = os.stream.connectToChannel('messaging', {
otherparty: this.user ? this.user.id : undefined, otherparty: this.user ? this.user.id : undefined,
group: this.group ? this.group.id : undefined, group: this.group ? this.group.id : undefined,
}); });

View File

@ -23,10 +23,6 @@ export default defineComponent({
}, },
props: { props: {
// TODO: propvueobserve
stream: {
},
isMobile: { isMobile: {
type: Boolean, type: Boolean,
required: false, required: false,

View File

@ -8,16 +8,13 @@ import { wsUrl } from '@/config';
*/ */
export default class Stream extends EventEmitter { export default class Stream extends EventEmitter {
private stream: ReconnectingWebsocket; private stream: ReconnectingWebsocket;
public state: 'initializing' | 'reconnecting' | 'connected'; public state: 'initializing' | 'reconnecting' | 'connected' = 'initializing';
private sharedConnectionPools: Pool[] = []; private sharedConnectionPools: Pool[] = [];
private sharedConnections: SharedConnection[] = []; private sharedConnections: SharedConnection[] = [];
private nonSharedConnections: NonSharedConnection[] = []; private nonSharedConnections: NonSharedConnection[] = [];
constructor(user) { @autobind
super(); public init(user): void {
this.state = 'initializing';
this.stream = new ReconnectingWebsocket(wsUrl + (user ? `?i=${user.token}` : ''), '', { minReconnectionDelay: 1 }); // https://github.com/pladaria/reconnecting-websocket/issues/91 this.stream = new ReconnectingWebsocket(wsUrl + (user ? `?i=${user.token}` : ''), '', { minReconnectionDelay: 1 }); // https://github.com/pladaria/reconnecting-websocket/issues/91
this.stream.addEventListener('open', this.onOpen); this.stream.addEventListener('open', this.onOpen);
this.stream.addEventListener('close', this.onClose); this.stream.addEventListener('close', this.onClose);

View File

@ -50,7 +50,7 @@ export default defineComponent({
}; };
}, },
mounted() { mounted() {
this.connection = this.$root.stream.useSharedConnection('main'); this.connection = os.stream.useSharedConnection('main');
this.connection.on('driveFileCreated', this.onDriveFileCreated); this.connection.on('driveFileCreated', this.onDriveFileCreated);