-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tuya webrtc support #1379
base: master
Are you sure you want to change the base?
Add tuya webrtc support #1379
Conversation
This is awesome! @romasku, perhaps you can also add your new source instructions/information to the README? I want to give it a try. |
@felipecrs I've updated Readme to include an example, it's the same parameters as for Tuya's demo. |
@romasku it works! Awesome! One issue though, it only works the first time. If I stop the stream and try to access it again, it fails with: To make it work again, I have to restart go2rtc. |
@pergolafabio I think you should try your famous pet feeder against this. |
Hmm, looks interesting, though, I never got the camera stream working with that webrtc-demo-go app... I have now a working stream through the tuna cloud integration... But gonna try this one indeed!! |
is there an easy way to test this as an addon? or better wait to get merged in master? |
In my case I cloned the repo and built the executable, and ran it in my machine, not in HA. |
hmm, build the binary too, add the stream url with correct params, but i got black screen, and this is my log:
|
@pergolafabio, try a different Tuya camera if you have, just in case. It also didn't work for one of mine. |
i only have one :) |
Lucky you!!! Tuya is trash 😅 |
Hey @romasku , i see you added a new commit, is that helpfull for me? i have some issues getting the stream, see the logs above... thnx for looking into it! |
Hi, I've fixed the "uid not exist" issue (hopefully). Also, the current code uses global variables (the same as the original Tuya code), which can lead to issues if you try to open multiple streams at once. I'll try to work on this part later. @pergolafabio |
hmm, i was testing on http , since i just used the compiled binary, is https maybe needed? for the browser? |
If you use |
ok, i check later |
btw, i remember testing the webrtc-demo-go app , i never got that working either, also black screen |
As I see from logs, HA Tuya Cloud uses RTSP stream (AFAIK), so it is a different API. But you can check if this official Tuya web app works: https://protect-eu.ismartlife.me/login (maybe select a different region), as it uses WebRTC the same way as the webrtc-demo-go app. |
Tested that link, and i see the stream there, so thats already a good sign :-) |
tested again, with new version, i dont hear any audio either, strange that the other link does work?
|
@pergolafabio, if this doesn't work for you but HA does, then the following options would also work: |
Thanks! As I remember, |
hey @romasku , is this maybe related? |
@AlexxIT, for your information, I tried compiling both master and this PR, and this is the comparison:
The uncompressed binaries:
If that's too big, maybe you'll have a need for |
These are unexpectedly good results. Anyway, I'll look into this PR when I have time. |
internal/webrtc/tuya/mqtt.go
Outdated
t.mqttDispatch(rmqtt) | ||
} | ||
|
||
// 分发从mqtt服务器接受到的消息 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should cleanup these comments in Chinese. Or at least translate them, if they are important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry, I originally planned to cleanup it, but missed it.
internal/webrtc/tuya/types.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use copilot or chatgpt to help you translate this
@romasku really good job, this PR will be a game changer for some people, which will allow to better use existing hardware instead of throwing them away and buying new ones. I would never recommend people buy Tuya-based cameras or doorbells, but most of the time it's too late: they already bought. Please signal here once you are done cleaning it up and testing it, and you believe it's ready for @AlexxIT to review it. |
There's also this, in case you are willing to implement it in the same PR. :)
But I'd see no problem if you prefer to leave it for a future PR. |
Sure, I'll re-check my code more thoroughly this weekend and then ping for a review. However, I have to mention that this will likely be a half-measure for some devices. On my device, Tuya's own panel only provides only SD-quality video with no support for two-way audio. I had to hack and replace the camera firmware itself to make it work with Home Assistant. Regarding quality selection—since my device only has SD quality available via Tuya's WebRTC, I can't properly test it, so I'll have to leave it out. |
Got it. It makes sense. And yeah, not all Tuya devices support WebRTC properly. Unfortunately, we have to live with it. |
hi @romasku , i tried again, but i still see a black screen, what i notice, when i press on info, it gives me :
But when testing on this page: https://protect-eu.ismartlife.me/playback |
for the moment i still use @felipecrs his hack: https://github.com/felipecrs/get-tuya-webrtc-configs/blob/master/get_tuya_stream_url.sh that one works, i also i the stream, it uses h265 , so maybe the codec is the issue? how can i force/test using h265 ?
|
I don't think it's a "hack", lol. I think it's the proper way. BTW here is the new version of that tool: https://github.com/felipecrs/hass-expose-camera-stream-source/blob/master/README.md (scroll to the end). |
@pergolafabio, if your camera codec is H265 then it won't support WebRTC indeed. |
Yeah. For now at least. But Chrome has a launch option to enable H265 nowadays. |
i tried below, but still same :-(
its still forced to h264 probably |
Maybe we can explore your case after, but I would say this PR should not wait for it to be merged. |
@felipecrs @AlexxIT |
Also, Tuya finally fixed their site, and now I can properly select HD/SD, so I managed to reverse it. Moreover, I had some success with 2-way audio, but unfortunately, it works in the playground demo project but not in go2rtc. If I manage to get it working, I'll open a separate PR. |
Hello,
I ported https://github.com/tuya/webrtc-demo-go to go2rtc to add direct support for Tuya cameras.
It worked for me (I could see the video feed through the go2rtc web interface), but I'm a complete newbie to Golang, so I need help to make this code clean enough. Please guide me, I'll try to do my best.
Also, another major problem I encountered is that ICE sessions should be
pion.ICERoleControlled
even though it's incorrect according to the standard. So I had to hack my way around this issue usingSDPTypePranswer
. Do you have any suggestions on how to handle this situation properly?I guess these issues are related: