diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-06-02 16:10:49 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-06-02 16:10:49 +0200 |
| commit | 5572f16800fee6200e0f7aa32452ac5f80be7431 (patch) | |
| tree | 6af7099992f1f893688e0b6a6aabf42504bc2eba /app/client/socket/socket.actions.js | |
| parent | dbd27d8ab455c6372fae1516dcb677a53d9e23ca (diff) | |
whmmm
Diffstat (limited to 'app/client/socket/socket.actions.js')
| -rw-r--r-- | app/client/socket/socket.actions.js | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/app/client/socket/socket.actions.js b/app/client/socket/socket.actions.js index dc8d6fc..e787f1a 100644 --- a/app/client/socket/socket.actions.js +++ b/app/client/socket/socket.actions.js @@ -1,3 +1,31 @@ -import * as socketActions from './socket.system' +import uuidv1 from 'uuid/v1' +import { socket } from './socket.connection' -export default socketActions +export function run_system_command(opt) { + return syscall_async('run_system_command', opt) +} +export function list_directory(opt) { + return syscall_async('list_directory', opt).then(res => res.files) +} +export function run_script(opt) { + return syscall_async('run_script', opt) +} +export const syscall_async = (tag, payload, ttl=10000) => { + return new Promise( (resolve, reject) => { + const uuid = uuidv1() + const timeout = setTimeout(() => { + socket.off('system_res', cb) + reject('timeout') + }, ttl) + const cb = (data) => { + if (!data.uuid) return + if (data.uuid === uuid) { + clearTimeout(timeout) + socket.off('system_res', cb) + resolve(data) + } + } + socket.emit('system', { cmd: tag, payload, uuid }) + socket.on('system_res', cb) + }) +}
\ No newline at end of file |
