-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from sinricpro/2.8.1
getCameraStreamUrl, getWebRTCAnswer added
- Loading branch information
Showing
7 changed files
with
123 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ module.exports = { | |
"no-underscore-dangle": "off", | ||
quotes: "off", | ||
"linebreak-style": 0, | ||
printWidth: 120, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"printWidth": 120 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const { | ||
SinricPro, startSinricPro, raiseEvent, eventNames, | ||
} = require('sinricpro'); | ||
|
||
const fetch = require('node-fetch'); | ||
|
||
const APPKEY = ""; | ||
const APPSECRET = ""; | ||
const cameraId = ""; | ||
const deviceIds = [cameraId]; | ||
|
||
async function mediamtx(offer) { | ||
/* | ||
Get the answer from mediamtx `http://<hostname>:8889/<name>/whep`. eg: http://pi3:8889/cam/whep | ||
*/ | ||
const url = `http://pi3:8889/cam/whep`; | ||
const response = await fetch(url, { | ||
headers: { | ||
"content-type": "application/sdp", | ||
}, | ||
body: offer, | ||
method: "POST", | ||
}); | ||
|
||
// eslint-disable-next-line no-return-await | ||
return await response.text(); | ||
} | ||
|
||
const getWebRTCAnswer = async (deviceid, base64Offer) => { | ||
// Alexa Eco needs camera stream answer | ||
const offer = Buffer.from(base64Offer, 'base64').toString(); | ||
try { | ||
const answer = await mediamtx(offer); | ||
const answerInBase64 = Buffer.from(answer).toString('base64'); | ||
return { success: true, answer: answerInBase64 }; | ||
} catch (error) { | ||
console.error(error); | ||
return { success: false }; | ||
} | ||
}; | ||
|
||
const getCameraStreamUrl = async (deviceid, cameraStreamProtocol) => { | ||
// Google Home: RTSP protocol not supported. Requires a Chromecast TV or Google Nest Hub | ||
// Alexa: RTSP url must be interleaved TCP on port 443 (for both RTP and RTSP) over TLS 1.2 port 443 | ||
|
||
if(cameraStreamProtocol === 'hls') { | ||
return { success: true, url: 'https://cph-p2p-msl.akamaized.net/hls/live/2000341/test/master.m3u8' }; | ||
} | ||
else if(cameraStreamProtocol === 'rtsp') { | ||
return { success: true, url: 'rtsp://rtspurl:443' }; | ||
} else { | ||
return { success: false}; | ||
} | ||
}; | ||
|
||
const setPowerState = async (deviceid, data) => { | ||
console.log(deviceid, data); | ||
return true; | ||
}; | ||
|
||
const sinricpro = new SinricPro(APPKEY, deviceIds, APPSECRET, false); | ||
const callbacks = { setPowerState, getWebRTCAnswer, getCameraStreamUrl }; | ||
|
||
startSinricPro(sinricpro, callbacks); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2019 Sinric. All rights reserved. | ||
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA) | ||
* | ||
* This file is part of the Sinric Pro (https://github.com/sinricpro/) | ||
*/ | ||
const { UndefinedCallbackError, InvalidResponseError } = require("../errors/errors"); | ||
|
||
const CameraStreamController = async (payload, callbacks) => { | ||
if (payload.action === "getWebRTCAnswer" && callbacks.getWebRTCAnswer) { | ||
const data = await callbacks.getWebRTCAnswer(payload.deviceId, payload.value.offer); | ||
|
||
if (data.answer) { | ||
return data.answer; | ||
} | ||
throw new InvalidResponseError(" error"); | ||
} | ||
if (payload.action === "getWebRTCOffer" && callbacks.getWebRTCOffer) { | ||
const data = await callbacks.getWebRTCOffer(payload.deviceId); | ||
|
||
if (data.offer) { | ||
return data.offer; | ||
} | ||
throw new InvalidResponseError(" error"); | ||
} | ||
else if (payload.action === "getCameraStreamUrl" && callbacks.getCameraStreamUrl) { | ||
const data = await callbacks.getCameraStreamUrl(payload.deviceId, payload.value.protocol); | ||
if (data.url) { | ||
return data.url; | ||
} | ||
throw new InvalidResponseError("getCameraStreamUrl error"); | ||
} else { | ||
throw new UndefinedCallbackError("getCameraStreamUrl callback is undefined."); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
CameraStreamController, | ||
}; |
This file was deleted.
Oops, something went wrong.