Skip to content

Latest commit

 

History

History
52 lines (39 loc) · 1.69 KB

README.md

File metadata and controls

52 lines (39 loc) · 1.69 KB

Project Lighthouse SDK for Swift

Build Docs

A modern async wrapper around the Project Lighthouse API for Swift, e.g. to build games and other clients. Runs on Linux and Apple platforms (macOS, iOS, ...).

Example

// Prepare connection
let auth = Authentication(username: username, token: token)
let lh = Lighthouse(authentication: auth, url: url)

// Connect to the lighthouse server
try await lh.connect()
log.info("Connected to the lighthouse")

// Handle incoming input events
Task {
    let stream = try await lh.streamModel()
    for await message in stream {
        if case let .inputEvent(input) = message.payload {
            log.info("Got input \(input)")
        }
    }
}

// Repeatedly send colored frames to the lighthouse
while true {
    log.info("Sending frame")
    try await lh.putModel(frame: Frame(fill: .random()))
    try await Task.sleep(for: .seconds(1))
}

For more details, check out the LighthouseDemo source code.

Usage

First make sure to have a login at lighthouse.uni-kiel.de and to have your credentials defined as environment variables:

export LIGHTHOUSE_USER=[your username]
export LIGHTHOUSE_TOKEN=[your api token]

Running the example is now as easy as invoking

swift run LighthouseDemo