summaryrefslogtreecommitdiff
path: root/app/client/socket/socket.live.js
blob: c55695f5cd874e97e3270b1c0ca2d2dc6e774164 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { dispatch } from '../store'
import types from '../types'
import * as player from '../live/player'

import { socket } from './socket.connection'

socket.on('res', (data) => {
  console.log(data.cmd)
  switch (data.cmd) {
    case 'get_last_frame':
      if (data.res !== 'working') {
        socket.emit('cmd', {
          cmd: 'get_last_frame',
        })
      }
      break
    case 'get_params':
      store.dispatch({
        type: types.socket.load_params,
        opt: data.res,
      })
      break
    case 'list_checkpoints':
      store.dispatch({
        type: types.socket.list_checkpoints,
        checkpoints: data.res,
      })
      break
    case 'list_sequences':
      store.dispatch({
        type: types.socket.list_sequences,
        sequences: data.res,
      })
      break
    case 'list_epochs':
      store.dispatch({
        type: types.socket.list_epochs,
        epochs: data.res,
      })
      break
    default:
      break
  }
  console.log(data)
})

socket.on('frame', player.onFrame)

export function list_checkpoints() {
  socket.emit('cmd', {
    cmd: 'list_checkpoints',
  })
}
export function list_epochs(checkpoint_name) {
  socket.emit('cmd', {
    cmd: 'list_epochs',
    payload: checkpoint_name,
  })
}
export function list_sequences() {
  socket.emit('cmd', {
    cmd: 'list_sequences',
  })
}
export function load_epoch(checkpoint_name, epoch) {
  console.log(">> SWITCH CHECKPOINT", checkpoint_name, epoch)
  socket.emit('cmd', {
    cmd: 'load_epoch',
    payload: checkpoint_name + ':' + epoch,
  })
}
export function load_sequence(sequence) {
  socket.emit('cmd', {
    cmd: 'load_sequence',
    payload: sequence,
  })
}
export function seek(frame) {
  socket.emit('cmd', {
    cmd: 'seek',
    payload: frame,
  })
}
export function pause(frame) {
  socket.emit('cmd', {
    cmd: 'pause',
  })
}
export function play(frame) {
  socket.emit('cmd', {
    cmd: 'play',
  })
}
export function get_params() {
  socket.emit('cmd', {
    cmd: 'get_params',
  })
}
export function set_param(key, value) {
  socket.emit('cmd', {
    cmd: 'set_param',
    payload: {
      'key': key,
      'value': value,
    }
  })
}