2 * Copyright (C) 2017 "IoT.bzh"
3 * Author Sebastien Douheret <sebastien@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
25 // EventRegisterArgs Parameters (json format) of /events/register command
26 type EventRegisterArgs struct {
27 Name string `json:"name"`
28 ProjectID string `json:"filterProjectID"`
31 // EventUnRegisterArgs Parameters of /events/unregister command
32 type EventUnRegisterArgs struct {
33 Name string `json:"name"`
37 // EventMsg Message send
38 type EventMsg struct {
39 Time string `json:"time"`
40 FromSessionID string `json:"sessionID"` // Session ID of client who produce this event
41 Type string `json:"type"`
42 Data interface{} `json:"data"` // Data
45 // EventEvent Event send in WS when an internal event (eg. Syncthing event is received)
47 // EventTypePrefix Used as event prefix
48 EventTypePrefix = "event:" // following by event type
50 // Supported Events type
51 EVTAll = EventTypePrefix + "all"
52 EVTFolderChange = EventTypePrefix + "folder-change" // type EventMsg with Data type xsapiv1.???
53 EVTFolderStateChange = EventTypePrefix + "folder-state-change" // type EventMsg with Data type xsapiv1.???
56 // EVTAllList List of all supported events
57 var EVTAllList = []string{
62 // DecodeFolderConfig Helper to decode Data field type FolderConfig
63 func (e *EventMsg) DecodeFolderConfig() (FolderConfig, error) {
67 case EVTFolderChange, EVTFolderStateChange:
69 d, err = json.Marshal(e.Data)
71 err = json.Unmarshal(d, &f)
74 err = fmt.Errorf("Invalid type")