github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/system/media/storageConfig.go (about)

     1  // This file is part of the Smart Home
     2  // Program complex distribution https://github.com/e154/smart-home
     3  // Copyright (C) 2023, Filippov Alex
     4  //
     5  // This library is free software: you can redistribute it and/or
     6  // modify it under the terms of the GNU Lesser General Public
     7  // License as published by the Free Software Foundation; either
     8  // version 3 of the License, or (at your option) any later version.
     9  //
    10  // This library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13  // Library General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Lesser General Public
    16  // License along with this library.  If not, see
    17  // <https://www.gnu.org/licenses/>.
    18  
    19  package media
    20  
    21  import (
    22  	"time"
    23  
    24  	"github.com/imdario/mergo"
    25  )
    26  
    27  // NewStreamCore do load config file
    28  func NewStreamCore() *StorageST {
    29  	//configFile = path.Join("conf", "media_config.json")
    30  	//
    31  	var instance StorageST
    32  	//data, err := ioutil.ReadFile(configFile)
    33  	//if err != nil {
    34  	//	log.Error(err.Error())
    35  	//	os.Exit(1)
    36  	//}
    37  	//err = json.Unmarshal(data, &tmp)
    38  	//if err != nil {
    39  	//	log.Error(err.Error())
    40  	//	os.Exit(1)
    41  	//}
    42  	//debug = tmp.Server.Debug
    43  	instance.Server = ServerST{
    44  		Debug:        false,
    45  		HTTPDemo:     true,
    46  		HTTPDebug:    false,
    47  		HTTPLogin:    "demo",
    48  		HTTPPassword: "demo",
    49  		HTTPDir:      "static_source/media",
    50  		HTTPPort:     ":8083",
    51  		RTSPPort:     ":5541",
    52  	}
    53  	instance.Streams = make(map[string]StreamST)
    54  	var err error
    55  	for i, stream := range instance.Streams {
    56  		for j, ch := range stream.Channels {
    57  			channel := instance.ChannelDefaults
    58  			err = mergo.Merge(&channel, ch)
    59  			if err != nil {
    60  				log.Error(err.Error())
    61  				//os.Exit(1)
    62  			}
    63  			channel.clients = make(map[string]ClientST)
    64  			channel.ack = time.Now().Add(-255 * time.Hour)
    65  			channel.hlsSegmentBuffer = make(map[int]SegmentOld)
    66  			channel.signals = make(chan int, 100)
    67  			stream.Channels[j] = channel
    68  		}
    69  		instance.Streams[i] = stream
    70  	}
    71  	return &instance
    72  }
    73  
    74  // SaveConfig ...
    75  func (obj *StorageST) SaveConfig() error {
    76  	//log.Debug("Saving configuration to", configFile)
    77  	//debug.Println(obj)
    78  	//v2, err := version.NewVersion("2.0.0")
    79  	//if err != nil {
    80  	//	return err
    81  	//}
    82  	//data, err := sheriff.Marshal(&sheriff.Options{
    83  	//	Groups:     []string{"config"},
    84  	//	ApiVersion: v2,
    85  	//}, obj)
    86  	//if err != nil {
    87  	//	return err
    88  	//}
    89  	//res, err := json.MarshalIndent(data, "", "  ")
    90  	//if err != nil {
    91  	//	return err
    92  	//}
    93  	//err = ioutil.WriteFile(configFile, res, 0644)
    94  	//if err != nil {
    95  	//	log.Error(err.Error())
    96  	//	return err
    97  	//}
    98  	return nil
    99  }