डोरबेल डिवाइस टाइप को दो ट्रेट का इस्तेमाल करके लागू किया जाता है:
PushAvStreamTransport,
यह पुश-आधारित प्रोटोकॉल का इस्तेमाल करके, ऑडियो और वीडियो स्ट्रीम को ट्रांसफ़र करता है. साथ ही,
WebRtcLiveView,
यह लाइव स्ट्रीम को कंट्रोल करने और टॉकबैक की सुविधा देता है.
किसी भी सुविधा का इस्तेमाल करने या एट्रिब्यूट अपडेट करने से पहले, हमेशा यह जांच करें कि डिवाइस के लिए एट्रिब्यूट और कमांड काम करती हैं या नहीं. ज़्यादा जानकारी के लिए, Androidपर डिवाइसों को कंट्रोल करना लेख पढ़ें.
| Home APIs डिवाइस टाइप | विशेषताएं | Kotlin सैंपल ऐप्लिकेशन | इस्तेमाल का उदाहरण |
|---|---|---|---|
दरवाज़े की घंटी
यह दरवाज़े के बाहर मौजूद एक बटन से चालू होने वाला डिवाइस है. इससे सुनाई देने वाला और/या दिखने वाला सिग्नल मिलता है. इसका इस्तेमाल दरवाज़े के दूसरी ओर मौजूद व्यक्ति का ध्यान खींचने के लिए किया जाता है. डोरबेल में, लाइव स्ट्रीम को ऐक्सेस करने की सुविधा, दोनों ओर से बातचीत करने की सुविधा या गतिविधि का पता लगाने की सुविधा हो सकती है. |
ज़रूरी ट्रेट google PushAvStreamTransport google WebRtcLiveView |
डोरबेल |
लाइव स्ट्रीम शुरू करना
लाइव स्ट्रीम शुरू करने के लिए, Session Description Protocol (SDP) स्ट्रिंग को WebRtcLiveView ट्रेट के startLiveView() तरीके पर भेजें. इससे WebRtcLiveViewTrait.StartLiveViewCommand.Response मिलता है, जिसमें ये तीन वैल्यू होती हैं:
- सेशन के लिए एसडीपी.
- सत्र की अवधि, सेकंड में.
- यह सेशन आईडी है. इसका इस्तेमाल सेशन को बढ़ाने या खत्म करने के लिए किया जा सकता है.
suspend fun getWebRtcLiveViewTrait(cameraDevice: HomeDevice) { return cameraDevice.type(GoogleDoorbellDevice).trait(WebRtcLiveView).first { it?.metadata?.sourceConnectivity?.connectivityState == ConnectivityState.ONLINE } } // Start the live view suspend fun startCameraStream(trait: WebRtcLiveView, offerSdp: String) { val response = trait.startLiveView(offerSdp) // Response contains three fields (see below) return response } ... // This is used to manage the WebRTC connection val peerConnection: RTCPeerConnection = ... ... val startResponse = startCameraStream(sdp) val answerSdp = startResponse?.answerSdp val sessionDuration = startResponse?.liveSessionDurationSeconds val mediaSessionId = startResponse?.mediaSessionId peerConnection.setRemoteDescription(SessionDescription.Type.ANSWER, answerSdp)
लाइव स्ट्रीम की अवधि बढ़ाना
लाइव स्ट्रीम की अवधि पहले से तय होती है. इसके बाद, वे खत्म हो जाती हैं. चालू स्ट्रीम की अवधि बढ़ाने के लिए, WebRtcLiveView.extendLiveView() तरीके का इस्तेमाल करके, अवधि बढ़ाने का अनुरोध करें:
// Assuming camera stream has just been started suspend fun scheduleExtension(trait: WebRtcLiveView, mediaSessionId: String, liveSessionDurationSeconds: UShort ) { delay(liveSessionDurationSeconds - BUFFER_SECONDS * 1000) val response = trait.extendLiveView(mediaSessionId) // returns how long the session will be live for return response.liveSessionDurationSeconds }
TalkBack को चालू और बंद करना
TalkBack की सुविधा शुरू करने के लिए, WebRtcLiveView
ट्रेट के startTalkback()
तरीके को कॉल करें. इसे बंद करने के लिए, stopTalkback() का इस्तेमाल करें.
// Make sure camera stream is on suspend fun setTalkback(isOn: Boolean, trait: WebRtcLiveView, mediaSessionId: String) { if(isOn) { trait.startTalkback(mediaSessionId) } else { trait.stopTalkback(mediaSessionId) } }
रिकॉर्डिंग की सुविधा को चालू और बंद करना
कैमरे की रिकॉर्डिंग की सुविधा चालू करने के लिए, PushAvStreamTransport ट्रेट के setTransportStatus() तरीके में TransportStatusEnum.Active पास करें. रिकॉर्डिंग की सुविधा बंद करने के लिए, इसे TransportStatusEnum.Inactive पर सेट करें.
यहां दिए गए उदाहरण में, हमने इन कॉल को एक ही कॉल में रैप किया है. इसमें रिकॉर्डिंग की सुविधा को टॉगल करने के लिए, Boolean का इस्तेमाल किया गया है:
// Start or stop recording for all connections. suspend fun setCameraRecording(isOn: Boolean) { val pushAvStreamTransport = getPushAvStreamTransport if(isOn) { pushAvStreamTransport.setTransportStatus(TransportStatusEnum.Active) } else { pushAvStreamTransport.setTransportStatus(TransportStatusEnum.Inactive) } }
कैमरे की रिकॉर्डिंग की सुविधा को चालू या बंद करने का मतलब है कि कैमरे का वीडियो चालू या बंद करना. जब कैमरे का वीडियो चालू होता है, तब वह रिकॉर्डिंग कर रहा होता है. ऐसा इवेंट और उनसे जुड़ी क्लिप के लिए किया जाता है.
जब रिकॉर्डिंग की सुविधा बंद हो (कैमरे का वीडियो बंद हो):
connectivityStateके हिसाब से, कैमरा अब भी ऑनलाइन दिख सकता है डिवाइस टाइप.- लाइव स्ट्रीम को ऐक्सेस नहीं किया जा सकता. साथ ही, कैमरा किसी भी क्लाउड इवेंट का पता नहीं लगाता.
देखें कि रिकॉर्डिंग की सुविधा चालू है या नहीं
यह पता लगाने के लिए कि कैमरे की रिकॉर्डिंग की सुविधा चालू है या नहीं, देखें कि कोई कनेक्शन चालू है या नहीं. यहां दिए गए उदाहरण में, ऐसा करने के लिए दो फ़ंक्शन तय किए गए हैं:
// Get the on/off state suspend fun onOffState(cameraDevice: HomeDevice, cameraDeviceType) { // Query the device for pushAvStreamTransport val pushAvTrait = getPushAvStreamTransport() return pushAvTrait.recordModeActive() } // Check if the camera's recording capability is enabled fun PushAvStreamTransport.recordModeActive(): Boolean { return currentConnections?.any { it.transportStatus == TransportStatusEnum.Active } ?: false }
जांच करने का एक और तरीका है. इसके लिए, प्रेडिकेट के साथ findTransport() फ़ंक्शन का इस्तेमाल करें:
// Fetch the current connections suspend fun queryRecordModeState(cameraDevice: HomeDevice, cameraDeviceType) { val pushAvStreamTransport = getPushAvStreamTransport() return pushAvStreamTransport.findTransport().let { it.transportConfigurations.any { it.transportStatus == TransportStatusEnum.Active } }
ऑडियो सेटिंग
Home APIs की मदद से, कैमरे की ऑडियो सेटिंग को कंट्रोल किया जा सकता है.
माइक्रोफ़ोन चालू या बंद करना
डिवाइस के माइक्रोफ़ोन को चालू या बंद करने के लिए, setMicrophoneMuted Kotlin फ़ंक्शन का इस्तेमाल करके, CameraAvStreamManagement ट्रेट के microphoneMuted एट्रिब्यूट को अपडेट करें:
// Turn the device's microphone on or off suspend fun turnOffMicrophone(disableMicrophone: Boolean, trait: CameraAvStreamManagement) { trait.update { setMicrophoneMuted(disableMicrophone) } }
ऑडियो रिकॉर्डिंग की सुविधा चालू या बंद करना
डिवाइस के लिए ऑडियो रिकॉर्डिंग की सुविधा चालू या बंद करने के लिए, CameraAvStreamManagement ट्रेट के recordingMicrophoneMuted एट्रिब्यूट को अपडेट करें. इसके लिए, setRecordingMicrophoneMuted Kotlin फ़ंक्शन का इस्तेमाल करें:
// Turn audio recording on or off for the device suspend fun turnOffAudioRecording(disableAudioRecording: Boolean, trait: CameraAvStreamManagement) { trait.update { setRecordingMicrophoneMuted(disableAudioRecording) } }
स्पीकर की आवाज़ कम या ज़्यादा करना
डिवाइस के स्पीकर का वॉल्यूम घटाने या बढ़ाने के लिए, CameraAvStreamManagement ट्रेट के speakerVolumeLevel एट्रिब्यूट को अपडेट करें. इसके लिए, setSpeakerVolumeLevel Kotlin फ़ंक्शन का इस्तेमाल करें:
// Adjust the camera speaker volume suspend fun adjustSpeakerVolume(volume: Int, trait: CameraAvStreamManagement) { trait.update { setSpeakerVolumeLevel(volume.toUbyte()) } }
अन्य सेटिंग
Home API की मदद से, कैमरे की अन्य सेटिंग को कंट्रोल किया जा सकता है.
नाइट विज़न मोड को चालू या बंद करना
कैमरे के लिए नाइट विज़न की सुविधा चालू या बंद करने के लिए, TriStateAutoEnum का इस्तेमाल करके, CameraAvStreamManagement ट्रेट के nightVision एट्रिब्यूट को अपडेट करें. इसके लिए, setNightVision Kotlin फ़ंक्शन का इस्तेमाल करें:
// Turn night vision on cameraAvStreamManagement.update { setNightVision(CameraAvStreamManagementTrait.TriStateAutoEnum.On) } // Turn night vision off CameraAvStreamManagement.update { setNightVision(CameraAvStreamManagementTrait.TriStateAutoEnum.Off) }
स्टेटस एलईडी की चमक बदलना
स्टेटस एलईडी की चमक बदलने के लिए, ThreeLevelAutoEnum का इस्तेमाल करें. इससे CameraAvStreamManagement ट्रेट के statusLightBrightness एट्रिब्यूट को अपडेट किया जा सकता है. इसके लिए, setStatusLightBrightness Kotlin फ़ंक्शन का इस्तेमाल करें:
// Set the LED brightness to high cameraAvStreamManagement.update { setStatusLightBrightness(CameraAvStreamManagementTrait.ThreeLevelAutoEnum.High) } // Set the LED brightness to low cameraAvStreamManagement.update { setStatusLightBrightness(CameraAvStreamManagementTrait.ThreeLevelAutoEnum.Low) }
कैमरे का व्यूपोर्ट बदलना
कैमरे का व्यू पोर्ट, Nest Cam के वीडियो को ज़ूम और बेहतर बनाएं सहायता लेख में बताई गई ज़ूम और क्रॉप करने की सुविधा की तरह ही होता है.
व्यूपोर्ट को ViewportStruct में तय किया जाता है. इसमें चार वैल्यू होती हैं. इनका इस्तेमाल व्यूपोर्ट के निर्देशांकों के तौर पर किया जाता है. कोऑर्डिनेट को इस तरह से तय किया जाता है:
(x1,y1) -- (x2,y1) | | (x1,y2) -- (x2,y2)
ViewportStruct के लिए वैल्यू तय करना, ऐप्लिकेशन के यूज़र इंटरफ़ेस (यूआई) और कैमरे को लागू करने के तरीके पर निर्भर करता है. कैमरे के वीडियो का व्यूपोर्ट सेट करने के लिए, CameraAvStreamManagement ट्रेट के viewport एट्रिब्यूट को ViewportStruct से अपडेट करें. इसके लिए, बिल्ट-इन setViewport Kotlin फ़ंक्शन का इस्तेमाल करें:
cameraAvStreamManagement .update { setViewport( CameraAvStreamManagementTrait.ViewportStruct( x1 = horizontalRange.rangeStart.roundToInt().toUShort(), x2 = horizontalRange.rangeEnd.roundToInt().toUShort(), y1 = verticalRange.rangeStart.roundToInt().toUShort(), y2 = verticalRange.rangeEnd.roundToInt().toUShort(), ) ) }
डिवाइस के वेक-अप होने की सेंसिटिविटी को अडजस्ट करना
डिवाइस के वेक-अप सेंसर की संवेदनशीलता का इस्तेमाल, बैटरी बचाने के लिए किया जाता है. इसके लिए, डिवाइस की गतिविधि का पता लगाने की रेंज को कम किया जाता है. साथ ही, गतिविधि का पता चलने के बाद डिवाइस के वेक अप होने के समय को बढ़ाया जाता है.
Home API में, इसे डिवाइस के transportOptions में मौजूद triggerOptions की motionSensitivity प्रॉपर्टी का इस्तेमाल करके सेट किया जा सकता है. ये विकल्प, हर डिवाइस के लिए PushAvStreamTransport ट्रेट में तय किए जाते हैं.
डिवाइस को जगाने की सुविधा के लिए, संवेदनशीलता को सिर्फ़ इन वैल्यू पर सेट किया जा सकता है:
- 1 = कम
- 5 = मीडियम
- 10 = ज़्यादा
अपडेट करने के लिए, findTransport कमांड का इस्तेमाल करके, चालू रिकॉर्डिंग स्ट्रीम के लिए ट्रांसपोर्ट कॉन्फ़िगरेशन ढूंढें. इसके बाद, modifyPushTransport कमांड का इस्तेमाल करके, कॉन्फ़िगरेशन में नई संवेदनशीलता वैल्यू डालें:
// Create a struct with the new wake-up sensitivity val toUpdate = TransportOptionsStruct( triggerOptions = TransportTriggerOptionsStruct( motionSensitivity = OptionalValue.present(wakeUpSensitivity.toUByte()) ) ) // Get the configurations for active connections val connections = pushAvStreamTransport.findTransport().transportConfigurations // Update all recording streams with the new transport options. for (connection in connections) { if (connection.transportOptions.getOrNull()?.streamUsage == StreamUsageEnum.Recording) { trait.modifyPushTransport( connectionId = connection.connectionId, transportOptions = toUpdate, ) } }
इवेंट की ज़्यादा से ज़्यादा अवधि में बदलाव करना
इवेंट की ज़्यादा से ज़्यादा अवधि का मतलब है कि कैमरा किसी इवेंट के लिए कितने समय तक क्लिप रिकॉर्ड करेगा. होम एपीआई के ज़रिए, इसे हर डिवाइस के लिए कॉन्फ़िगर किया जा सकता है. इसके लिए, Google Home app (GHA) के बराबर समयसीमा तय की जा सकती है. यह समयसीमा सेकंड के हिसाब से तय की जाती है:
- 10 सेकंड
- 15 सेकंड
- 30 सेकंड
- 60 सेकंड (एक मिनट)
- 120 सेकंड (दो मिनट)
- 180 सेकंड (3 मिनट)
Home API में, इसे डिवाइस के transportOptions में मौजूद triggerOptions की motionTimeControl प्रॉपर्टी का इस्तेमाल करके सेट किया जा सकता है. ये विकल्प, हर डिवाइस के लिए PushAvStreamTransport ट्रेट में तय किए जाते हैं.
अपडेट करने के लिए, findTransport कमांड का इस्तेमाल करके, चालू रिकॉर्डिंग स्ट्रीम के लिए ट्रांसपोर्ट कॉन्फ़िगरेशन ढूंढें. इसके बाद, modifyPushTransport कमांड का इस्तेमाल करके, कॉन्फ़िगरेशन में इवेंट की नई अवधि की वैल्यू में बदलाव करें:
// Create a struct with the new max event length // where maxDuration is the length in seconds val toUpdate = TransportOptionsStruct( triggerOptions = TransportTriggerOptionsStruct( motionTimeControl = OptionalValue.present( TransportMotionTriggerTimeControlStruct(maxDuration = it.toUInt()) ) ) ) // Get the configurations for active connections val connections = pushAvStreamTransport.findTransport().transportConfigurations // Update all recording streams with the new transport options. for (connection in connections) { if (connection.transportOptions.getOrNull()?.streamUsage == StreamUsageEnum.Recording) { trait.modifyPushTransport( connectionId = connection.connectionId, transportOptions = toUpdate, ) } }
घंटी की सेटिंग
Home API की मदद से, डोरबेल की आवाज़ से जुड़ी अलग-अलग सेटिंग को कंट्रोल किया जा सकता है.
घंटी की आवाज़ बदलना
डोरबेल की आवाज़ बदलने के लिए, सबसे पहले डिवाइस में इंस्टॉल की गई आवाज़ों की सूची पाएं. इसके लिए, Chime ट्रेट के installedChimeSounds एट्रिब्यूट का इस्तेमाल करें:
// Get a list of chimes and identify the currently selected one private val doorbellChimeTraitFlow: Flow= device.traitFromType(Chime, GoogleDoorbellDevice) val chimeSounds = doorbellChimeTraitFlow.first().installedChimeSounds ?: emptyList()
इसके बाद, setSelectedChime Kotlin फ़ंक्शन का इस्तेमाल करके, Chime ट्रेट के selectedChime एट्रिब्यूट को अपडेट करें:
// Set the chime using the chimeId from the installed list chimeSounds.firstOrNull { it.name == name }?.let { setSelectedChime(it.chimeId) }
बाहरी चाइम का इस्तेमाल करना
डोरबेल को इस तरह कॉन्फ़िगर किया जा सकता है कि वह घर के अंदर लगी मैकेनिकल बेल जैसे बाहरी चाइम का इस्तेमाल करे. दरवाज़े की घंटी इंस्टॉल करते समय इसे कॉन्फ़िगर किया जाना चाहिए, ताकि बाहरी चाइम को संभावित नुकसान से बचाया जा सके.
किस तरह का बाहरी चाइम इंस्टॉल किया गया है, यह बताने के लिए ExternalChimeType का इस्तेमाल करें. इससे Chime ट्रेट के externalChime एट्रिब्यूट को अपडेट किया जा सकता है. इसके लिए, बिल्ट-इन setExternalChime Kotlin फ़ंक्शन का इस्तेमाल करें:
// Indicate the external chime is mechanical chime.update { setExternalChime(ChimeTrait.ExternalChimeType.Mechanical) }
बाहरी घंटी बजने की अवधि बदलना
बाहरी डिवाइस पर घंटी बजने की अवधि को Home API के ज़रिए कॉन्फ़िगर किया जा सकता है. यह अवधि सेकंड में होती है. अगर बाहरी डिवाइस पर सूचना की अवधि सेट करने की सुविधा उपलब्ध है, तो उपयोगकर्ता इसे कॉन्फ़िगर कर सकता है.
यहां सेट की गई वैल्यू, बाहरी घंटी के स्पेसिफ़िकेशन और घंटी बजने की सुझाई गई अवधि पर निर्भर करती है.
बाहरी घंटी बजने की अवधि बदलने के लिए, Chime ट्रेट के externalChimeDurationSeconds एट्रिब्यूट को अपडेट करें. इसके लिए, बिल्ट-इन setExternalChimeDurationSeconds Kotlin फ़ंक्शन का इस्तेमाल करें:
// Change the external chime duration chime.update { setExternalChimeDurationSeconds(newDuration.toUShort()) }