Skip to content

About library

Jacek W edited this page Dec 11, 2023 · 2 revisions

About

TikTokLive java was created because TikTok dose not provide offical API for lives. That means library itself will be never up to date with tiktok and might interprete some things differently

How does library works?

We can divide working of library to 4 important parts

  • Getting info about live from TikTok. Library is making 3 https requests

    • first for getting live Room_ID
    • second for getting more specific live metadata such as live title, host name...
    • third to Sign API that returns access token that is later use for connecting to TikTok websocket
  • Connecting to TikTok websocket (PushServer)

    After successful connection to TikTok, pushServer starts to send ProtocolBuffer messages in binary format. This is very important to understand ProtocolBuffer. Don't worry it is not complicated :). All the proto files are included under API/src/main/proto After using Maven compile command on project, java classes are generated from those files. so then we can easily map incoming bytes to classes, for examples WebcastGiftMessage message = WebcastGiftMessage.parseFrom(incomingBytesArray)

  • Mapping TikTok data to events

    At this point we have TikTok data inside protocol-buffer classes now we want to map it to events. Why? because protocol-buffer classes might be changed at any point, but we want to keep library code structure consistent across versions. so for example WebcastGiftMessage is mapped to TikTokGiftEvent

  • trigger events

    When the events objects are done last step is to trigger them. And that's it! tikTokEventObserver.publish(liveClient, tiktokGiftEvent)

Clone this wiki locally