This commit is contained in:
syuilo
2017-11-16 23:46:36 +09:00
parent 3d3309282e
commit a8c6d0ed90
12 changed files with 91 additions and 29 deletions

View File

@@ -4,6 +4,7 @@ import MiOS from './mios';
import ServerStreamManager from './scripts/server-stream-manager';
import RequestsStreamManager from './scripts/requests-stream-manager';
import MessagingIndexStream from './scripts/messaging-index-stream-manager';
import DriveStreamManager from './scripts/drive-stream-manager';
export default (mios: MiOS) => {
(riot as any).mixin('os', {
@@ -30,7 +31,7 @@ export default (mios: MiOS) => {
(riot as any).mixin('api', {
api: mios.api
});
(riot as any).mixin('drive-stream', { driveStream: new DriveStreamManager(mios.i) });
(riot as any).mixin('stream', { stream: mios.stream });
(riot as any).mixin('server-stream', { serverStream: new ServerStreamManager() });

View File

@@ -0,0 +1,20 @@
import StreamManager from './stream-manager';
import Connection from './drive-stream';
export default class DriveStreamManager extends StreamManager<Connection> {
private me;
constructor(me) {
super();
this.me = me;
}
public getConnection() {
if (this.connection == null) {
this.connection = new Connection(this.me);
}
return this.connection;
}
}

View File

@@ -0,0 +1,14 @@
import Stream from './stream';
/**
* Drive stream connection
*/
class Connection extends Stream {
constructor(me) {
super('drive', {
i: me.token
});
}
}
export default Connection;

View File

@@ -247,7 +247,10 @@
this.mixin('i');
this.mixin('api');
this.mixin('stream');
this.mixin('drive-stream');
this.connection = this.driveStream.getConnection();
this.connectionId = this.driveStream.use();
this.files = [];
this.folders = [];
@@ -280,10 +283,10 @@
});
});
this.stream.on('drive_file_created', this.onStreamDriveFileCreated);
this.stream.on('drive_file_updated', this.onStreamDriveFileUpdated);
this.stream.on('drive_folder_created', this.onStreamDriveFolderCreated);
this.stream.on('drive_folder_updated', this.onStreamDriveFolderUpdated);
this.connection.on('file_created', this.onStreamDriveFileCreated);
this.connection.on('file_updated', this.onStreamDriveFileUpdated);
this.connection.on('folder_created', this.onStreamDriveFolderCreated);
this.connection.on('folder_updated', this.onStreamDriveFolderUpdated);
if (this.opts.folder) {
this.move(this.opts.folder);
@@ -293,10 +296,11 @@
});
this.on('unmount', () => {
this.stream.off('drive_file_created', this.onStreamDriveFileCreated);
this.stream.off('drive_file_updated', this.onStreamDriveFileUpdated);
this.stream.off('drive_folder_created', this.onStreamDriveFolderCreated);
this.stream.off('drive_folder_updated', this.onStreamDriveFolderUpdated);
this.connection.off('file_created', this.onStreamDriveFileCreated);
this.connection.off('file_updated', this.onStreamDriveFileUpdated);
this.connection.off('folder_created', this.onStreamDriveFolderCreated);
this.connection.off('folder_updated', this.onStreamDriveFolderUpdated);
this.driveStream.dispose(this.connectionId);
});
this.onStreamDriveFileCreated = file => {

View File

@@ -172,7 +172,10 @@
<script>
this.mixin('i');
this.mixin('api');
this.mixin('stream');
this.mixin('drive-stream');
this.connection = this.driveStream.getConnection();
this.connectionId = this.driveStream.use();
this.files = [];
this.folders = [];
@@ -189,10 +192,10 @@
this.multiple = this.opts.multiple;
this.on('mount', () => {
this.stream.on('drive_file_created', this.onStreamDriveFileCreated);
this.stream.on('drive_file_updated', this.onStreamDriveFileUpdated);
this.stream.on('drive_folder_created', this.onStreamDriveFolderCreated);
this.stream.on('drive_folder_updated', this.onStreamDriveFolderUpdated);
this.connection.on('file_created', this.onStreamDriveFileCreated);
this.connection.on('file_updated', this.onStreamDriveFileUpdated);
this.connection.on('folder_created', this.onStreamDriveFolderCreated);
this.connection.on('folder_updated', this.onStreamDriveFolderUpdated);
if (this.opts.folder) {
this.cd(this.opts.folder, true);
@@ -208,10 +211,11 @@
});
this.on('unmount', () => {
this.stream.off('drive_file_created', this.onStreamDriveFileCreated);
this.stream.off('drive_file_updated', this.onStreamDriveFileUpdated);
this.stream.off('drive_folder_created', this.onStreamDriveFolderCreated);
this.stream.off('drive_folder_updated', this.onStreamDriveFolderUpdated);
this.connection.off('file_created', this.onStreamDriveFileCreated);
this.connection.off('file_updated', this.onStreamDriveFileUpdated);
this.connection.off('folder_created', this.onStreamDriveFolderCreated);
this.connection.off('folder_updated', this.onStreamDriveFolderUpdated);
this.driveStream.dispose(this.connectionId);
});
this.onStreamDriveFileCreated = file => {