2 * Copyright (C) 2017-2018 "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 Filter string `json:"filter"`
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.FolderConfig
53 EVTFolderStateChange = EventTypePrefix + "folder-state-change" // type EventMsg with Data type xsapiv1.FolderConfig
54 EVTSDKAdd = EventTypePrefix + "sdk-add" // type EventMsg with Data type xsapiv1.SDK
55 EVTSDKRemove = EventTypePrefix + "sdk-remove" // type EventMsg with Data type xsapiv1.SDK
56 EVTSDKManagement = EventTypePrefix + "sdk-management" // type EventMsg with Data type xsapiv1.SDKManagementMsg
57 EVTSDKStateChange = EventTypePrefix + "sdk-state-change" // type EventMsg with Data type xsapiv1.SDK
60 // EVTAllList List of all supported events
61 var EVTAllList = []string{
70 // DecodeFolderConfig Helper to decode Data field type FolderConfig
71 func (e *EventMsg) DecodeFolderConfig() (FolderConfig, error) {
75 case EVTFolderChange, EVTFolderStateChange:
77 d, err = json.Marshal(e.Data)
79 err = json.Unmarshal(d, &f)
82 err = fmt.Errorf("Invalid type")
87 // DecodeSDKEvent Helper to decode Data field type SDK
88 func (e *EventMsg) DecodeSDKEvent() (SDK, error) {
92 case EVTSDKAdd, EVTSDKRemove, EVTSDKStateChange:
94 d, err = json.Marshal(e.Data)
96 err = json.Unmarshal(d, &s)
99 err = fmt.Errorf("Invalid type")