aboutsummaryrefslogtreecommitdiff
path: root/src/Actions.js
blob: 9424c5153e1e5ca8e16eb4c661bd47f81c284939 (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
const NO_OP = 'NO_OP'
const SET_PIXEL = 'SET_PIXEL'
const CLEAR = 'CLEAR'
const SAVE = 'SAVE'
const LOAD = 'LOAD'
const ADD_FRAME = "ADD_FRAME"
const REMOVE_FRAME = "REMOVE_FRAME"

function sendAction(websocket, action) {
  let actionStr = JSON.stringify(action)
  websocket.send(actionStr)
}

function save(websocket, saveName) {
  sendAction(websocket, {
    type: SAVE,
    saveName: saveName
  })
}

function load(websocket, saveName) {
  sendAction(websocket, {
    type: LOAD,
    saveName: saveName
  })
}

function setPixel(websocket, x, y, r, g, b, frame) {
  sendAction(websocket, {
    type: SET_PIXEL,
    x: x,
    y: y,
    r: r, 
    g: g,
    b: b,
    frame: frame
  })
}

function clear(websocket) {
  sendAction(websocket, { type: CLEAR })
}

function noop(websocket) {
  sendAction(websocket, { type: NO_OP })
}

function addFrame(websocket, frame = 1, delay = 50) {
  sendAction(websocket, { 
    type: ADD_FRAME, 
    frame: frame, 
    delay: delay
  })
}

function removeFrame(websocket, frame = 1) {
  sendAction(websocket, {
    type: REMOVE_FRAME, 
    frame: frame
  })
}

export {
    setPixel, 
    clear, 
    noop,
    save,
    load,
    addFrame,
    removeFrame
}