Giter Site home page Giter Site logo

losfarmosctl / swift-twitch-client Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 3.0 186 KB

WIP - A Swift library for interacting with Twitch Chat, API and Pub-/EventSub

License: MIT License

Swift 100.00%
eventsub helix irc pubsub swift twitch twitch-api twitch-chat helix-api twitch-eventsub

swift-twitch-client's Introduction

swift-twitch-client

CI

Swift native client to access various 3rd party twitch elements like the API and Chat.

Caution

The developement of this library is still very much in progress, APIs may be incomplete or change without any notice!

I do not recommend to use this in any projects until I've finalized the design.

This is the current idea for how the usage might look in the end (not at all final, if I find something that feels better right now I will just change it):

Helix

let twitch = TwitchClient(with: credentials)

// Completion Handlers

twitch.helixTask(for: .doSomething(param1: "forsen")) { result, error in
}

// Async/Await
let result = try await twitch.helix(endpoint: .doSomething(param1: "forsen"))

// Combine
twitch.helixPublisher(for: .doSomething(param1: "forsen")).sink(
  receiveCompletion: { error in

  },
  receiveValue: { result in

  })

Chat (IRC)

let twitch = TwitchClient(with: credentials)

let irc = try await twitch.ircClient(.authenticated)

try await irc.join(to: "forsen")
try await irc.part(from: "forsen")

// Using callbacks

irc.listener { result in
  switch result {
  case .success(let message): print(message)
  case .failure(let error): print(error)
  }
}

// Using AsyncStream

let stream = irc.stream()
for try await message in stream {
  if case .privateMessage(let privMsg) = message {
    try await client.send("Received message: \(privMsg.message)", in: "forsen")
  }
}

// Using Combine

let publisher = irc.publisher()

irc.publisher().sink(
  receiveCompletion: {
    // handle error
  },
  receiveValue: {
    // handle msg
  })

EventSub

// WIP

swift-twitch-client's People

Contributors

benedictst avatar losfarmosctl avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

swift-twitch-client's Issues

handle rate limit headers returned by Helix

Helix returns Ratelimit-Limit, Ratelimit-Remaining and Ratelimit-Reset as response headers. Those should be returned with every result (and applicable errors, most importantly a 429 response code).

anonymous IRC connections require credentials to be provided

When creating a TwitchClient, passing in credentials is mandatory. This makes sense for Helix and EventSub, since every endpoint will require some form of authentication, but it is a bit annoying if you only want to connect to IRC anonymously, right now you'd have to pass in some empty dummy credentials anyways.

Since IRC is treated a bit different by Twitch anyways (requiring neither ClientID or OAuth), it would make sense to just extract the IRC client from the main TwitchClient. It's already pretty much separate, with the main TwitchClient just returning a new TwitchIRCClient object.

differentiate between app and user access tokens

Some API endpoints do not necessarily require a user access token, but can work with just an app access token as well. Right now, the credentials required by the TwitchClient contain a mandatory user ID, which would not be applicable for app access tokens.

There should be a differentiation between endpoints that require user access tokens and ones that do not (should be possible using generics?) and an option to create a TwitchClient with an app access token, that accepts a limited number of endpoints.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.