mirror of
https://github.com/kerberos-io/agent.git
synced 2026-10-19 17:38:25 +00:00
fix errors here and there :)
This commit is contained in:
@@ -64,9 +64,7 @@ loop:
|
||||
var pkt av.Packet
|
||||
if pkt, err = infile.ReadPacket(); err != nil { // sometimes this throws an end of file..
|
||||
log.Log.Error("HandleStream: " + err.Error())
|
||||
if err.Error() == "EOF" {
|
||||
time.Sleep(30 * time.Second)
|
||||
}
|
||||
time.Sleep(30 * time.Second)
|
||||
}
|
||||
|
||||
// Could be that a decode is throwing errors.
|
||||
|
||||
@@ -58,7 +58,10 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configuratio
|
||||
|
||||
// This will return the timestamp when the last packet was correctyl received
|
||||
// this is to calculate if the camera connection is still working.
|
||||
lastPacketReceived := communication.LastPacketTimer.Load().(int64)
|
||||
lastPacketReceived := int64(0)
|
||||
if communication.LastPacketTimer != nil {
|
||||
lastPacketReceived = communication.LastPacketTimer.Load().(int64)
|
||||
}
|
||||
|
||||
// The total number of recordings stored in the directory
|
||||
numberOfRecordings := utils.NumberOfFilesInDirectory("./data/recordings")
|
||||
|
||||
@@ -17,93 +17,100 @@ func ConfigureMQTT(configuration *models.Configuration, communication *models.Co
|
||||
|
||||
config := configuration.Config
|
||||
|
||||
opts := mqtt.NewClientOptions()
|
||||
if config.Offline == "true" {
|
||||
log.Log.Info("ConfigureMQTT: not starting as running in Offline mode.")
|
||||
} else {
|
||||
|
||||
// We will set the MQTT endpoint to which we want to connect
|
||||
// and share and receive messages to/from.
|
||||
mqttURL := config.MQTTURI
|
||||
opts.AddBroker(mqttURL)
|
||||
log.Log.Info("ConfigureMQTT: Set broker uri " + mqttURL)
|
||||
opts := mqtt.NewClientOptions()
|
||||
|
||||
// Our MQTT broker can have username/password credentials
|
||||
// to protect it from the outside.
|
||||
mqtt_username := config.MQTTUsername
|
||||
mqtt_password := config.MQTTPassword
|
||||
if mqtt_username != "" || mqtt_password != "" {
|
||||
opts.SetUsername(mqtt_username)
|
||||
opts.SetPassword(mqtt_password)
|
||||
log.Log.Info("ConfigureMQTT: Set username " + mqtt_username)
|
||||
log.Log.Info("ConfigureMQTT: Set password " + mqtt_password)
|
||||
}
|
||||
// We will set the MQTT endpoint to which we want to connect
|
||||
// and share and receive messages to/from.
|
||||
mqttURL := config.MQTTURI
|
||||
opts.AddBroker(mqttURL)
|
||||
log.Log.Info("ConfigureMQTT: Set broker uri " + mqttURL)
|
||||
|
||||
// Some extra options to make sure the connection behaves
|
||||
// properly. More information here: github.com/eclipse/paho.mqtt.golang.
|
||||
opts.SetCleanSession(true)
|
||||
opts.SetConnectRetry(true)
|
||||
//opts.SetAutoReconnect(true)
|
||||
opts.SetConnectTimeout(30 * time.Second)
|
||||
|
||||
hubKey := ""
|
||||
// This is the old way ;)
|
||||
if config.Cloud == "s3" && config.S3 != nil && config.S3.Publickey != "" {
|
||||
hubKey = config.S3.Publickey
|
||||
} else if config.Cloud == "kstorage" && config.KStorage != nil && config.KStorage.CloudKey != "" {
|
||||
hubKey = config.KStorage.CloudKey
|
||||
}
|
||||
// This is the new way ;)
|
||||
if config.HubKey != "" {
|
||||
hubKey = config.HubKey
|
||||
}
|
||||
|
||||
if hubKey != "" {
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
random := rand.Intn(100)
|
||||
mqttClientID := config.Key + strconv.Itoa(random) // this random int is to avoid conflicts.
|
||||
|
||||
// This is a worked-around.
|
||||
// current S3 (Kerberos Hub SAAS) is using a secured MQTT, where the client id,
|
||||
// should match the kerberos hub key.
|
||||
if config.Cloud == "s3" {
|
||||
mqttClientID = config.Key
|
||||
// Our MQTT broker can have username/password credentials
|
||||
// to protect it from the outside.
|
||||
mqtt_username := config.MQTTUsername
|
||||
mqtt_password := config.MQTTPassword
|
||||
if mqtt_username != "" || mqtt_password != "" {
|
||||
opts.SetUsername(mqtt_username)
|
||||
opts.SetPassword(mqtt_password)
|
||||
log.Log.Info("ConfigureMQTT: Set username " + mqtt_username)
|
||||
log.Log.Info("ConfigureMQTT: Set password " + mqtt_password)
|
||||
}
|
||||
|
||||
opts.SetClientID(mqttClientID)
|
||||
log.Log.Info("ConfigureMQTT: Set ClientID " + mqttClientID)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
webrtc.CandidateArrays = make(map[string](chan string))
|
||||
// Some extra options to make sure the connection behaves
|
||||
// properly. More information here: github.com/eclipse/paho.mqtt.golang.
|
||||
opts.SetCleanSession(true)
|
||||
opts.SetConnectRetry(true)
|
||||
//opts.SetAutoReconnect(true)
|
||||
opts.SetConnectTimeout(30 * time.Second)
|
||||
|
||||
opts.OnConnect = func(c mqtt.Client) {
|
||||
|
||||
// We managed to connect to the MQTT broker, hurray!
|
||||
log.Log.Info("ConfigureMQTT: " + mqttClientID + " connected to " + mqttURL)
|
||||
|
||||
// Create a subscription to know if send out a livestream or not.
|
||||
MQTTListenerHandleLiveSD(c, hubKey, configuration, communication)
|
||||
|
||||
// Create a subscription for the WEBRTC livestream.
|
||||
MQTTListenerHandleLiveHDHandshake(c, hubKey, configuration, communication)
|
||||
|
||||
// Create a subscription for keeping alive the WEBRTC livestream.
|
||||
MQTTListenerHandleLiveHDKeepalive(c, hubKey, configuration, communication)
|
||||
|
||||
// Create a subscription to listen to the number of WEBRTC peers.
|
||||
MQTTListenerHandleLiveHDPeers(c, hubKey, configuration, communication)
|
||||
|
||||
// Create a subscription to listen for WEBRTC candidates.
|
||||
MQTTListenerHandleLiveHDCandidates(c, hubKey, configuration, communication)
|
||||
|
||||
// Create a susbcription to listen for ONVIF actions: e.g. PTZ, Zoom, etc.
|
||||
MQTTListenerHandleONVIF(c, hubKey, configuration, communication)
|
||||
hubKey := ""
|
||||
// This is the old way ;)
|
||||
if config.Cloud == "s3" && config.S3 != nil && config.S3.Publickey != "" {
|
||||
hubKey = config.S3.Publickey
|
||||
} else if config.Cloud == "kstorage" && config.KStorage != nil && config.KStorage.CloudKey != "" {
|
||||
hubKey = config.KStorage.CloudKey
|
||||
}
|
||||
}
|
||||
mqc := mqtt.NewClient(opts)
|
||||
if token := mqc.Connect(); token.WaitTimeout(3 * time.Second) {
|
||||
if token.Error() != nil {
|
||||
log.Log.Error("ConfigureMQTT: unable to establish mqtt broker connection, error was: " + token.Error().Error())
|
||||
// This is the new way ;)
|
||||
if config.HubKey != "" {
|
||||
hubKey = config.HubKey
|
||||
}
|
||||
|
||||
if hubKey != "" {
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
random := rand.Intn(100)
|
||||
mqttClientID := config.Key + strconv.Itoa(random) // this random int is to avoid conflicts.
|
||||
|
||||
// This is a worked-around.
|
||||
// current S3 (Kerberos Hub SAAS) is using a secured MQTT, where the client id,
|
||||
// should match the kerberos hub key.
|
||||
if config.Cloud == "s3" {
|
||||
mqttClientID = config.Key
|
||||
}
|
||||
|
||||
opts.SetClientID(mqttClientID)
|
||||
log.Log.Info("ConfigureMQTT: Set ClientID " + mqttClientID)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
webrtc.CandidateArrays = make(map[string](chan string))
|
||||
|
||||
opts.OnConnect = func(c mqtt.Client) {
|
||||
|
||||
// We managed to connect to the MQTT broker, hurray!
|
||||
log.Log.Info("ConfigureMQTT: " + mqttClientID + " connected to " + mqttURL)
|
||||
|
||||
// Create a subscription to know if send out a livestream or not.
|
||||
MQTTListenerHandleLiveSD(c, hubKey, configuration, communication)
|
||||
|
||||
// Create a subscription for the WEBRTC livestream.
|
||||
MQTTListenerHandleLiveHDHandshake(c, hubKey, configuration, communication)
|
||||
|
||||
// Create a subscription for keeping alive the WEBRTC livestream.
|
||||
MQTTListenerHandleLiveHDKeepalive(c, hubKey, configuration, communication)
|
||||
|
||||
// Create a subscription to listen to the number of WEBRTC peers.
|
||||
MQTTListenerHandleLiveHDPeers(c, hubKey, configuration, communication)
|
||||
|
||||
// Create a subscription to listen for WEBRTC candidates.
|
||||
MQTTListenerHandleLiveHDCandidates(c, hubKey, configuration, communication)
|
||||
|
||||
// Create a susbcription to listen for ONVIF actions: e.g. PTZ, Zoom, etc.
|
||||
MQTTListenerHandleONVIF(c, hubKey, configuration, communication)
|
||||
}
|
||||
}
|
||||
mqc := mqtt.NewClient(opts)
|
||||
if token := mqc.Connect(); token.WaitTimeout(3 * time.Second) {
|
||||
if token.Error() != nil {
|
||||
log.Log.Error("ConfigureMQTT: unable to establish mqtt broker connection, error was: " + token.Error().Error())
|
||||
}
|
||||
}
|
||||
return mqc
|
||||
}
|
||||
return mqc
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func MQTTListenerHandleLiveSD(mqttClient mqtt.Client, hubKey string, configuration *models.Configuration, communication *models.Communication) {
|
||||
@@ -187,5 +194,7 @@ func MQTTListenerHandleONVIF(mqttClient mqtt.Client, hubKey string, configuratio
|
||||
}
|
||||
|
||||
func DisconnectMQTT(mqttClient mqtt.Client) {
|
||||
mqttClient.Disconnect(1000)
|
||||
if mqttClient != nil {
|
||||
mqttClient.Disconnect(1000)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,10 @@ class Dashboard extends React.Component {
|
||||
|
||||
componentWillUnmount() {
|
||||
this.subscription.unsubscribe();
|
||||
const liveview = document.getElementsByClassName('videocard-video');
|
||||
if (liveview && liveview.length > 0) {
|
||||
liveview[0].remove();
|
||||
}
|
||||
}
|
||||
|
||||
getCurrentTimestamp() {
|
||||
|
||||
@@ -502,7 +502,7 @@ class Settings extends React.Component {
|
||||
onClick={() => this.changeTab('recording')}
|
||||
icon={<Icon label="refresh" />}
|
||||
/>
|
||||
{config.offline === 'false' && (
|
||||
{config.offline !== 'true' && (
|
||||
<Tab
|
||||
label="Streaming"
|
||||
value="streaming"
|
||||
@@ -518,7 +518,7 @@ class Settings extends React.Component {
|
||||
onClick={() => this.changeTab('conditions')}
|
||||
icon={<Icon label="activity" />}
|
||||
/>
|
||||
{config.offline === 'false' && (
|
||||
{config.offline !== 'true' && (
|
||||
<Tab
|
||||
label="Persistence"
|
||||
value="persistence"
|
||||
@@ -651,49 +651,6 @@ class Settings extends React.Component {
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
<Input
|
||||
noPadding
|
||||
label="onvif xaddr"
|
||||
value={config.capture.ipcamera.onvif_xaddr}
|
||||
placeholder="http://x.x.x.x/onvif/device_service"
|
||||
onChange={(value) =>
|
||||
this.onUpdateField(
|
||||
'capture.ipcamera',
|
||||
'onvif_xaddr',
|
||||
value,
|
||||
config.capture.ipcamera
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
<Input
|
||||
noPadding
|
||||
label="username"
|
||||
value={config.capture.ipcamera.onvif_username}
|
||||
onChange={(value) =>
|
||||
this.onUpdateField(
|
||||
'capture.ipcamera',
|
||||
'onvif_username',
|
||||
value,
|
||||
config.capture.ipcamera
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
<Input
|
||||
noPadding
|
||||
label="password"
|
||||
value={config.capture.ipcamera.onvif_password}
|
||||
onChange={(value) =>
|
||||
this.onUpdateField(
|
||||
'capture.ipcamera',
|
||||
'onvif_password',
|
||||
value,
|
||||
config.capture.ipcamera
|
||||
)
|
||||
}
|
||||
/>
|
||||
</BlockBody>
|
||||
<BlockFooter>
|
||||
<Button
|
||||
@@ -793,7 +750,7 @@ class Settings extends React.Component {
|
||||
)}
|
||||
|
||||
{/* STUN/TURN block */}
|
||||
{showStreamingSection && config.offline === 'false' && (
|
||||
{showStreamingSection && config.offline !== 'true' && (
|
||||
<Block>
|
||||
<BlockHeader>
|
||||
<h4>STUN/TURN for WebRTC</h4>
|
||||
@@ -849,7 +806,7 @@ class Settings extends React.Component {
|
||||
</Block>
|
||||
)}
|
||||
|
||||
{showPersistenceSection && config.offline === 'false' && (
|
||||
{showPersistenceSection && config.offline !== 'true' && (
|
||||
<Block>
|
||||
<BlockHeader>
|
||||
<h4>Kerberos Hub</h4>
|
||||
@@ -958,6 +915,69 @@ class Settings extends React.Component {
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{/* General settings block */}
|
||||
{showCameraSection && (
|
||||
<Block>
|
||||
<BlockHeader>
|
||||
<h4>ONVIF</h4>
|
||||
</BlockHeader>
|
||||
<BlockBody>
|
||||
<p>Credentials to communicate with ONVIF capabilities.</p>
|
||||
|
||||
<Input
|
||||
noPadding
|
||||
label="onvif xaddr"
|
||||
value={config.capture.ipcamera.onvif_xaddr}
|
||||
placeholder="http://x.x.x.x/onvif/device_service"
|
||||
onChange={(value) =>
|
||||
this.onUpdateField(
|
||||
'capture.ipcamera',
|
||||
'onvif_xaddr',
|
||||
value,
|
||||
config.capture.ipcamera
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
<Input
|
||||
noPadding
|
||||
label="username"
|
||||
value={config.capture.ipcamera.onvif_username}
|
||||
onChange={(value) =>
|
||||
this.onUpdateField(
|
||||
'capture.ipcamera',
|
||||
'onvif_username',
|
||||
value,
|
||||
config.capture.ipcamera
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
<Input
|
||||
noPadding
|
||||
label="password"
|
||||
value={config.capture.ipcamera.onvif_password}
|
||||
onChange={(value) =>
|
||||
this.onUpdateField(
|
||||
'capture.ipcamera',
|
||||
'onvif_password',
|
||||
value,
|
||||
config.capture.ipcamera
|
||||
)
|
||||
}
|
||||
/>
|
||||
</BlockBody>
|
||||
<BlockFooter>
|
||||
<Button
|
||||
label="Save"
|
||||
type="default"
|
||||
icon="pencil"
|
||||
onClick={this.saveConfig}
|
||||
/>
|
||||
</BlockFooter>
|
||||
</Block>
|
||||
)}
|
||||
|
||||
{/* General settings block */}
|
||||
{showOverviewSection && (
|
||||
<Block>
|
||||
@@ -994,7 +1014,7 @@ class Settings extends React.Component {
|
||||
</Block>
|
||||
)}
|
||||
|
||||
{showStreamingSection && config.offline === 'false' && (
|
||||
{showStreamingSection && config.offline !== 'true' && (
|
||||
<Block>
|
||||
<BlockHeader>
|
||||
<h4>MQTT</h4>
|
||||
@@ -1049,7 +1069,7 @@ class Settings extends React.Component {
|
||||
)}
|
||||
|
||||
{/* STUN/TURN block */}
|
||||
{showStreamingSection && config.offline === 'false' && (
|
||||
{showStreamingSection && config.offline !== 'true' && (
|
||||
<Block>
|
||||
<BlockHeader>
|
||||
<h4>Forwarding and transcoding</h4>
|
||||
@@ -1673,7 +1693,7 @@ class Settings extends React.Component {
|
||||
)}
|
||||
|
||||
{/* Persistence block */}
|
||||
{showPersistenceSection && config.offline === 'false' && (
|
||||
{showPersistenceSection && config.offline !== 'true' && (
|
||||
<Block>
|
||||
<BlockHeader>
|
||||
<h4>Persistence</h4>
|
||||
|
||||
Reference in New Issue
Block a user