github.com/quickfeed/quickfeed@v0.0.0-20240507093252-ed8ca812a09c/public/src/overmind/effects.tsx (about)

     1  import { ConnectError, createConnectTransport } from "@bufbuild/connect-web"
     2  import { QuickFeedService } from "../../proto/qf/quickfeed_connectweb"
     3  import { StreamService } from "../streamService"
     4  import { ResponseClient, createResponseClient } from "../client"
     5  
     6  
     7  export class ApiClient {
     8      client: ResponseClient<typeof QuickFeedService>
     9  
    10      /**
    11       * init initializes a client with the provided error handler.
    12       * Must be called before accessing the client.
    13       * @param errorHandler A function that is called when an error occurs.
    14       */
    15      public init(errorHandler: (payload?: { method: string; error: ConnectError; } | undefined) => void) {
    16          this.client = createResponseClient(QuickFeedService, createConnectTransport({
    17              baseUrl: `https://${window.location.host}`
    18          }), errorHandler)
    19      }
    20  }
    21  
    22  export const api = new ApiClient()
    23  
    24  export const streamService = new StreamService()