| 43 | } |
| 44 | |
| 45 | func NewRestAPI(s *session.Session) *RestAPI { |
| 46 | mod := &RestAPI{ |
| 47 | SessionModule: session.NewSessionModule("api.rest", s), |
| 48 | server: &http.Server{}, |
| 49 | quit: make(chan bool), |
| 50 | useWebsocket: false, |
| 51 | allowOrigin: "*", |
| 52 | upgrader: websocket.Upgrader{ |
| 53 | ReadBufferSize: 1024, |
| 54 | WriteBufferSize: 1024, |
| 55 | }, |
| 56 | recClock: 1, |
| 57 | recording: false, |
| 58 | recTime: 0, |
| 59 | loading: false, |
| 60 | replaying: false, |
| 61 | recordFileName: "", |
| 62 | recordWait: &sync.WaitGroup{}, |
| 63 | record: nil, |
| 64 | } |
| 65 | |
| 66 | mod.State.Store("recording", &mod.recording) |
| 67 | mod.State.Store("rec_clock", &mod.recClock) |
| 68 | mod.State.Store("replaying", &mod.replaying) |
| 69 | mod.State.Store("loading", &mod.loading) |
| 70 | mod.State.Store("load_progress", 0) |
| 71 | mod.State.Store("rec_time", &mod.recTime) |
| 72 | mod.State.Store("rec_filename", &mod.recordFileName) |
| 73 | mod.State.Store("rec_frames", 0) |
| 74 | mod.State.Store("rec_cur_frame", 0) |
| 75 | mod.State.Store("rec_started", &mod.recStarted) |
| 76 | mod.State.Store("rec_stopped", &mod.recStopped) |
| 77 | |
| 78 | mod.AddParam(session.NewStringParameter("api.rest.address", |
| 79 | "127.0.0.1", |
| 80 | session.IPv4Validator, |
| 81 | "Address to bind the API REST server to.")) |
| 82 | |
| 83 | mod.AddParam(session.NewIntParameter("api.rest.port", |
| 84 | "8081", |
| 85 | "Port to bind the API REST server to.")) |
| 86 | |
| 87 | mod.AddParam(session.NewStringParameter("api.rest.alloworigin", |
| 88 | mod.allowOrigin, |
| 89 | "", |
| 90 | "Value of the Access-Control-Allow-Origin header of the API server.")) |
| 91 | |
| 92 | mod.AddParam(session.NewStringParameter("api.rest.username", |
| 93 | "user", |
| 94 | "", |
| 95 | "API authentication username.")) |
| 96 | |
| 97 | mod.AddParam(session.NewStringParameter("api.rest.password", |
| 98 | "pass", |
| 99 | "", |
| 100 | "API authentication password.")) |
| 101 | |
| 102 | mod.AddParam(session.NewStringParameter("api.rest.certificate", |