wdesimini / TVCommanderKit

Client SDK for controlling Samsung Smart TVs
MIT License
9 stars 8 forks source link

How can I connect? #34

Open CT4TuEI3 opened 1 week ago

CT4TuEI3 commented 1 week ago

I don't quite understand how to connect to the TV. In the search, the TV finds and displays correctly. When I connect to it, writing the address, it gives the status Allowed, but when sending the command it gives an error. And I still don't quite understand what to write to the token. I expected that a four-digit code would be called on the TV as in similar applications. I entered both an arbitrary token and a uuid there - the status always fell allowed, but it gave an error when sending. Tell me, what could be the matter?

wdesimini commented 4 days ago

Let me clarify a few things that might help resolve your issue:

Let me know if that helps, or if you can share more about the errors you're seeing when sending commands!

CT4TuEI3 commented 2 days ago

Case 1

My TV model name is: UE65JU6000 If I do a search and find my TV, meaning its ip address and click connect, then I get an error in didEncounterError Here console log after po error:

▿ TVCommanderError
  ▿ noTokenInAuthResponse : TVResponse<TVAuthResponseBody>
    ▿ data : Optional<TVAuthResponseBody>
      ▿ some : TVAuthResponseBody
        ▿ clients : 3 elements
          ▿ 0 : TVClient
            ▿ attributes : Attributes
              ▿ name : Optional<String>
                - some : "W1RWXSBVRTY1SlU2MDAw"
              - token : nil
            - connectTime : 1728046628525
            - deviceName : "W1RWXSBVRTY1SlU2MDAw"
            - id : "29fd85d0-8250-11ef-9047-b7faf7110f59"
            - isHost : false
          ▿ 1 : TVClient
            ▿ attributes : Attributes
              ▿ name : Optional<String>
                - some : "c2FtcGxlX2FwcA=="
              - token : nil
            - connectTime : 1728046907668
            - deviceName : "c2FtcGxlX2FwcA=="
            - id : "d05f3630-8250-11ef-9047-b7faf7110f59"
            - isHost : false
          ▿ 2 : TVClient
            ▿ attributes : Attributes
              ▿ name : Optional<String>
                - some : "c2FtcGxlX2FwcA=="
              - token : nil
            - connectTime : 1728287783308
            - deviceName : "c2FtcGxlX2FwcA=="
            - id : "a5712cc0-8481-11ef-9047-b7faf7110f59"
            - isHost : false
        - id : "a5712cc0-8481-11ef-9047-b7faf7110f59"
        - token : nil
    - event : TVCommanderKit.TVChannelEvent.connect

After this method, didUpdateAuthState is called and if I print authStatus in the console, then the same status TVCommanderKit.TVAuthStatus.allowed will be printed to me. And log po tvCommander.tvConfig here:

▿ TVConnectionConfiguration
  - id : nil
  - app : "sample_app"
  - path : "/api/v2/channels/samsung.remote.control"
  - ipAddress : "172.16.15.146"
  - port : 8002
  - scheme : "wss"
  - token : nil

Since I don't quite understand what needs to be transferred to the token, I got such a case with an error but at the same time with the allowed status

Case 2

Here is the second case of my tests. In addition to entering the IP address of my TV, I passed its name and token (I didn't quite understand where to get it from, but I put the uuid of my TV there), there was no error when connecting, here is the log of the po tvCommander.tvConfig console in the didUpdateAuthState method:

▿ TVConnectionConfiguration
  - id : nil
  - app : "[TV] UE65JU6000"
  - path : "/api/v2/channels/samsung.remote.control"
  - ipAddress : "172.16.15.146"
  - port : 8002
  - scheme : "wss"
  ▿ token : Optional<String>
    - some : "*MY_UUID_HERE*"

After that, I also get the allowed status, but if I try to send a command, I will encounter an error and didEncounterError will tell me:

TVCommanderKit.TVCommanderError.packetDataParsingFailed

Below is the command I tried to send:

▿ TVRemoteCommand
  - method : TVCommanderKit.TVRemoteCommand.Method.control
  ▿ params : Params
    - cmd : TVCommanderKit.TVRemoteCommand.Params.Command.click
    - dataOfCmd : TVCommanderKit.TVRemoteCommand.Params.ControlKey.mute
    - option : false
    - typeOfRemote : TVCommanderKit.TVRemoteCommand.Params.ControlType.remoteKey

PS

I need to implement a TV connection based on the principle of authorization via a four-digit code. I don't quite understand how it works and was looking for information on this topic in Samsung's SmartView documentation and this implementation on Github. I found this repository and found some similarities. The key difference that I found in contrast to your repository is that this user implements the createApplication method, which is described in the documentation. How do you think the implementation of this user differs and what can help me in implementing my task with code authorization?