vectronic / homebridge-shinobi

A Homebridge plugin integrating Shinobi for motion detector cameras

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot add monitors

a-kitaev opened this issue · comments

Configured everything as required. Looks like home bridge can detect the stream but I'm getting following errors:

[10/8/2020, 1:33:23 AM] [Shinobi] creating ShinobiStreamingDelegate using shinobi config: [{"mid":"LjGbPsIJ7R","ke":"8wbU8kIQV2","name":"Some Stream","

}]
[10/8/2020, 1:33:24 AM] [Shinobi] TypeError: Cannot read property '0' of undefined
at new ShinobiStreamingDelegate (/usr/lib/node_modules/homebridge-shinobi/src/shinobiStreamingDelegate.ts:64:87)
at new ShinobiMonitorAccessory (/usr/lib/node_modules/homebridge-shinobi/src/shinobiMonitorAccessory.ts:56:41)
at ShinobiHomebridgePlatform.createMonitor (/usr/lib/node_modules/homebridge-shinobi/src/platform.ts:129:53)
at /usr/lib/node_modules/homebridge-shinobi/src/platform.ts:92:26
at processTicksAndRejections (internal/process/task_queues.js:97:5)
[10/8/2020, 1:33:24 AM] [Shinobi] didFinishLaunching() error: Cannot read property '0' of undefined
[10/8/2020, 1:33:29 AM] [HB Supervisor] Homebridge Process Ended. Code: 143, Signal: null

I’ll try to look into this on the weekend.

My code is expecting the config returned from Shinobi to contain at least one stream entry.

In your case the config returned is:

[{"mid":"LjGbPsIJ7R","ke":"8wbU8kIQV2","name":"Some Stream","}]

Mine looks like this:

{
  "mid": "garden",
  "ke": "house",
  "name": "garden",
  "shto": "[]",
  "shfr": "[]",
  "details": "{....}",
  "type": "h264",
  "ext": "mp4",
  "protocol": "rtsp",
  "host": "....",
  "path": "/Streaming/Channels/102",
  "port": 10554,
  "fps": 1,
  "mode": "record",
  "width": 640,
  "height": 480,
  "currentlyWatching": 0,
  "status": "Recording",
  "snapshot": "/EiEETI7qNiw24fAhLZUN3I6s8XP0jq/jpeg/house/garden/s.jpg",
  "streams": ["/EiEETI7qNiw24fAhLZUN3I6s8XP0jq/hls/house/garden/s.m3u8"],
  "streamsSortedByType": {
    "hls": ["/EiEETI7qNiw24fAhLZUN3I6s8XP0jq/hls/house/garden/s.m3u8"]
  }
}

I can add a check for no streams so that it doesn't throw an error, but this won't actually get the stream working... can you recheck the config for the monitor in shinobi?

i have the same error, check it:

imagen

my monitor is working nice on shinobi

imagen

Could you look at the permissions you gave to the API key you setup. I had given my API key all permissions:

Screenshot 2020-10-12 at 18 25 02

Perhaps you haven't given permission to view streams? Looking at the Shinobi code I believe this will prevent stream URLs appearing in the response from the monitor API request.

I have All permissions on The api

Strange.

As I said, the homebridge plugin expects the content logged in the line creating ShinobiStreamingDelegate using shinobi config: to include an array of streams.

If the response doesn't come back as expected from Shinobi there isn't much I can do.

I have just updated to the latest Shinobi and it still works for me. It must be a difference in the config of the monitor in Shinobi, but I can't see what it is.

As far as I can tell, this is where the response for monitors on the Shinobi API is being generated:

https://gitlab.com/Shinobi-Systems/Shinobi/-/blob/master/libs/webServerPaths.js#L960

It could be that your monitor is not setup with a stream type included in the switch statement here:

switch(type){
                            case'mjpeg':
                                streamURL='/'+req.params.auth+'/mjpeg/'+v.ke+'/'+v.mid+channelNumber
                            break;
                            case'hls':
                                streamURL='/'+req.params.auth+'/hls/'+v.ke+'/'+v.mid+channelNumber+'/s.m3u8'
                            break;
                            case'h264':
                                streamURL='/'+req.params.auth+'/h264/'+v.ke+'/'+v.mid+channelNumber
                            break;
                            case'flv':
                                streamURL='/'+req.params.auth+'/flv/'+v.ke+'/'+v.mid+channelNumber+'/s.flv'
                            break;
                            case'mp4':
                                streamURL='/'+req.params.auth+'/mp4/'+v.ke+'/'+v.mid+channelNumber+'/s.mp4'
                            break;
                        }

I had this problem, too. Notice how in the two different configs above, @a-kitaev's config is an array and @vectronic's config is not. In my case, the config is an array and it matches what the Shinobi 'monitors' api returns. I think the reason why the streams array is missing in @a-kitaev's config is either copy-paste error or deliberate censorship, because it's also invalid json (dangling comma and closing quotes).

I fixed it on my install by making the following change in shiobiStreamingDelegate.

- const shinobiConfig = this.monitor.shinobiConfig;
+ const shinobiConfig = this.monitor.shinobiConfig[0];

@scotttherobot kudos to you for solving this! I think the Shinobi response must have changed at some point. As part of looking at your comment, I updated Shinobi and indeed hit the same problem as originally reported. And your fix did the trick. I have republished a new version with a check as to whether the response returned is an array and handling appropriately.

Thanks very much.

Glad it worked! Thanks for creating and maintaining this awesome plugin!