Fix bugs
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
declare const _HOST_: string;
|
||||
|
||||
export default () => {
|
||||
localStorage.removeItem('me');
|
||||
document.cookie = `i=; domain=.${_HOST_}; expires=Thu, 01 Jan 1970 00:00:01 GMT;`;
|
||||
location.href = '/';
|
||||
};
|
@@ -1,18 +1,21 @@
|
||||
import StreamManager from './stream-manager';
|
||||
import Connection from './home-stream';
|
||||
import MiOS from '../../mios';
|
||||
|
||||
export default class HomeStreamManager extends StreamManager<Connection> {
|
||||
private me;
|
||||
private os: MiOS;
|
||||
|
||||
constructor(me) {
|
||||
constructor(os: MiOS, me) {
|
||||
super();
|
||||
|
||||
this.me = me;
|
||||
this.os = os;
|
||||
}
|
||||
|
||||
public getConnection() {
|
||||
if (this.connection == null) {
|
||||
this.connection = new Connection(this.me);
|
||||
this.connection = new Connection(this.os, this.me);
|
||||
}
|
||||
|
||||
return this.connection;
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import Stream from './stream';
|
||||
import signout from '../signout';
|
||||
import MiOS from '../../mios';
|
||||
|
||||
/**
|
||||
* Home stream connection
|
||||
*/
|
||||
export default class Connection extends Stream {
|
||||
constructor(me) {
|
||||
constructor(os: MiOS, me) {
|
||||
super('', {
|
||||
i: me.token
|
||||
});
|
||||
@@ -25,7 +25,7 @@ export default class Connection extends Stream {
|
||||
// このままではAPIが利用できないので強制的にサインアウトさせる
|
||||
this.on('my_token_regenerated', () => {
|
||||
alert('%i18n:common.my-token-regenerated%');
|
||||
signout();
|
||||
os.signout();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,14 @@ export default abstract class StreamManager<T extends Connection> extends EventE
|
||||
this.emit('disconnected');
|
||||
} else {
|
||||
this.emit('connected', this._connection);
|
||||
|
||||
this._connection.on('_connected_', () => {
|
||||
this.emit('_connected_');
|
||||
});
|
||||
|
||||
this._connection.on('_disconnected_', () => {
|
||||
this.emit('_disconnected_');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +45,11 @@ export default abstract class StreamManager<T extends Connection> extends EventE
|
||||
return this._connection != null;
|
||||
}
|
||||
|
||||
public get state(): string {
|
||||
if (!this.hasConnection) return 'no-connection';
|
||||
return this._connection.state;
|
||||
}
|
||||
|
||||
/**
|
||||
* コネクションを要求します
|
||||
*/
|
||||
|
@@ -1,13 +1,12 @@
|
||||
declare const _API_URL_: string;
|
||||
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import * as ReconnectingWebsocket from 'reconnecting-websocket';
|
||||
import { apiUrl } from '../../../config';
|
||||
|
||||
/**
|
||||
* Misskey stream connection
|
||||
*/
|
||||
export default class Connection extends EventEmitter {
|
||||
private state: string;
|
||||
public state: string;
|
||||
private buffer: any[];
|
||||
private socket: ReconnectingWebsocket;
|
||||
|
||||
@@ -25,7 +24,7 @@ export default class Connection extends EventEmitter {
|
||||
this.state = 'initializing';
|
||||
this.buffer = [];
|
||||
|
||||
const host = _API_URL_.replace('http', 'ws');
|
||||
const host = apiUrl.replace('http', 'ws');
|
||||
const query = params
|
||||
? Object.keys(params)
|
||||
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
|
||||
@@ -58,7 +57,7 @@ export default class Connection extends EventEmitter {
|
||||
*/
|
||||
private onClose() {
|
||||
this.state = 'reconnecting';
|
||||
this.emit('_closed_');
|
||||
this.emit('_disconnected_');
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user