summaryrefslogtreecommitdiff
path: root/app/client/socket
diff options
context:
space:
mode:
Diffstat (limited to 'app/client/socket')
-rw-r--r--app/client/socket/socket.actions.js3
-rw-r--r--app/client/socket/socket.system.js49
2 files changed, 46 insertions, 6 deletions
diff --git a/app/client/socket/socket.actions.js b/app/client/socket/socket.actions.js
new file mode 100644
index 0000000..574892a
--- /dev/null
+++ b/app/client/socket/socket.actions.js
@@ -0,0 +1,3 @@
+import { list_directory_async } from './socket.system'
+
+export const list_directory = list_directory_async
diff --git a/app/client/socket/socket.system.js b/app/client/socket/socket.system.js
index a3c4f15..11cb44c 100644
--- a/app/client/socket/socket.system.js
+++ b/app/client/socket/socket.system.js
@@ -1,6 +1,6 @@
import { dispatch } from '../store'
import types from '../types'
-
+import uuidv1 from 'uuid/v1'
import { socket } from './socket.connection'
socket.on('system_res', (data) => {
@@ -28,11 +28,18 @@ socket.on('system_res', (data) => {
type: data.rpc_connected ? types.system.rpc_connected : types.system.rpc_disconnected,
runner: data.runner,
})
- case 'command_output':
- return dispatch({
- type: types.system.command_output,
- data: data,
- })
+ // case 'run_system_command':
+ // return dispatch({
+ // type: types.system.command_output,
+ // data: data,
+ // })
+ // case 'list_directory':
+ // return dispatch({
+ // type: types.system.list_directory,
+ // data: data,
+ // })
+ // break
+ default:
break
}
})
@@ -43,3 +50,33 @@ export function run_system_command(cmd) {
payload: cmd,
})
}
+
+export function list_directory(opt) {
+ socket.emit('system', {
+ cmd: 'list_directory',
+ payload: opt,
+ })
+}
+
+export function list_directory_async(opt) {
+ return syscall_async('list_directory', 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 === uuid) {
+ clearTimeout(timeout)
+ socket.off('system_res', cb)
+ resolve(data)
+ }
+ }
+ socket.emit('system', { cmd: tag, payload, uuid })
+ socket.on('system_res', cb)
+ })
+}