📜 ⬆️ ⬇️

How does chromecast work?

Introduction

I recently caught fire on the choice of a wireless adapter for video transmission. I watched Chinese adapters with Miracast / DLNA and, of course, did not bypass my side and Chromecast. If with technologies such as WiDi, Miracast and dongles like AIRTAME everything is clear (no support from the software is needed, the system sees it as another monitor), how is the Chromecast inside I was not completely sure, as I wasn’t sure he is to me However, I found the open-source project of the Chromecast LeapCast emulator, and decided to try it out and study the protocol.

Installation and use

Installation on ArchLinux is quite simple - just install the leapcast-git package from AUR. You must also install Google Chrome or Chromium, because it is not in dependencies.

Run the program and see the following picture:
Hidden text
INFO:root:Starting SSDP server INFO:root:Starting LEAP server INFO:root:Loading Config-JSON from Google-Server INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): clients3.google.com INFO:root:Parsing Config-JSON INFO:root:Added edaded98-5119-4c8a-afc1-de722da03562 app INFO:root:Added PlayMovies app INFO:root:Added 00000000-0000-0000-0000-000000000000 app INFO:root:Added 1812335e-441c-4e1e-a61a-312ca1ead90e app INFO:root:Added 06ee44ee-e7e3-4249-83b6-f5d0b6f07f34 app INFO:root:Added 2be788b9-b7e0-4743-9069-ea876d97ac20 app INFO:root:Added GoogleSantaTracker app INFO:root:Added 06ee44ee-e7e3-4249-83b6-f5d0b6f07f34_1 app INFO:root:Added Pandora_App app INFO:root:Added aa35235e-a960-4402-a87e-807ae8b2ac79 app INFO:root:Added YouTube app INFO:root:Added HBO_App app INFO:root:Added TicTacToe app INFO:root:Added Revision3_App app INFO:root:Added Songza_App app INFO:root:Added a7f3283b-8034-4506-83e8-4e79ab1ad794_2 app WARNING:root:Didn't add Netflix because it has no URL! INFO:root:Added GoogleMusic app INFO:root:Added 18a8aeaa-8e3d-4c24-b05d-da68394a3476_1 app INFO:root:Added Post_TV_App app INFO:root:Added ChromeCast app INFO:root:Added Hulu_Plus app INFO:root:Added GoogleCastSampleApp app INFO:root:Added GoogleCastPlayer app INFO:root:Added Fling app 

Open any application on your Android-smartphone, supporting Chromecast (for example, YouTube), and we can connect to Leapcast:
image
At the same time in the log:
Hidden text
 INFO:tornado.access:200 GET /ssdp/device-desc.xml (192.168.0.105) 2.22ms INFO:tornado.access:200 GET /apps/YouTube (192.168.0.105) 3.18ms INFO:tornado.access:200 GET /apps/YouTube (192.168.0.105) 3.67ms INFO:tornado.access:201 POST /apps/YouTube (192.168.0.105) 5.29ms INFO:root:Channel for app set to <leapcast.services.websocket.ServiceChannel object at 0x195f690> 

Wow, it works! How does it work?
')
Protocol

For searching and initial control (launching the desired application, receiving parameters), the DIAL protocol is used - a kind of SSDP symbiosis for searching and HTTP REST + XML for management. SSDP may be familiar to you if you used UPnP and DLNA, and the REST part is quite simple.

  1. When you start LeapCast, it connects to a Google server in order to get a list of officially supported applications in json format . This file describes all the parameters for each application: by what link to send a request, with what parameters to run, and so on.
  2. LeapCast announces itself via SSDP.
  3. The Android client (in my case YouTube) finds LeapCast over SSDP, gets information about it (by accessing /ssdp/device-desc.xml ), then makes sure that the device works with YouTube (requesting / apps / YouTube ), connects to the server YouTube, takes the pairing token from him, sends it to LeapCast in a POST request (for all the same / apps / YouTube ).
  4. LeapCast launches Chrome / Chromium application via www.youtube.com/tv ? $ {POST_DATA}
  5. Further, for communication between Android and LeapCast, the RAMP protocol is used (Google removed the specification from its site). It describes the interaction between devices by sending json messages inside a WebSocket.
  6. To complete the interaction, Android sends a DELETE request to Leapcast at the same URL.

In the case of YouTube, as I understand it, WebSocket rises on the side of YouTube servers, however, other applications (for example, Google Music) require LeapCast to create a WebSocket, and management occurs already within your wireless network.

It should be noted that if the application that Chromecast supports is not approved by Google (and, accordingly, there is no record of it in json), then users will be able to use it only by entering the developer mode and downloading information about it. Sad enough.

Conclusion

In general, with LeapCast, you can turn any device capable of running Python + Chrome into an almost full-fledged analogue of Chromecast, if, for some reason, you cannot buy a cheap device. And I never thought to buy it, because does not work without the Internet, approval of applications of Google is required, and in general.

Source: https://habr.com/ru/post/210742/


All Articles