Skip to main content

Get started 🚀

Installation​

Thanks to CDN services like SkyPack you can use iframe library directly on your application.
caution

For the iframe to work you might need to acquire an API Key

ts
import { setup } from 'https://cdn.skypack.dev/@unionavatars/iframe@v0.3.1'
const iframe = document.querySelector('iframe#your-id')
const client = setup(iframe, { apiKey: '<your-api-key>' })
ts
import { setup } from 'https://cdn.skypack.dev/@unionavatars/iframe@v0.3.1'
const iframe = document.querySelector('iframe#your-id')
const client = setup(iframe, { apiKey: '<your-api-key>' })
caution

The client won't be properly set if the iframe is not yet loaded. If you have an Error about it not being loaded call setup on the onload event of the iframe

ts
import { type Eventer, setup } from '@unionavatars/iframe'
 
let client: Eventer
iframe.onload = () => {
client = setup(iframe, { apiKey: '<your-api-key>'})
let client: { on<O extends keyof Outputs = keyof Outputs, D extends Outputs = Outputs>(key: O, cb: Listener<D[O]>): void; once<O_1 extends keyof Outputs = keyof Outputs, D_1 extends Outputs = Outputs>(key: O_1, cb: Listener<...>): void; off<O_2 extends keyof Outputs = keyof Outputs, D_2 extends Outputs = Outputs>(key: O_2, cb: Listener<...>): void; request<K extends keyof Requests = keyof Requests, P extends unknown[] = Parameters<...>, R = ReturnType<...>>(key: K, ...params: P): Promise<...>; }
}
ts
import { type Eventer, setup } from '@unionavatars/iframe'
 
let client: Eventer
iframe.onload = () => {
client = setup(iframe, { apiKey: '<your-api-key>'})
let client: { on<O extends keyof Outputs = keyof Outputs, D extends Outputs = Outputs>(key: O, cb: Listener<D[O]>): void; once<O_1 extends keyof Outputs = keyof Outputs, D_1 extends Outputs = Outputs>(key: O_1, cb: Listener<...>): void; off<O_2 extends keyof Outputs = keyof Outputs, D_2 extends Outputs = Outputs>(key: O_2, cb: Listener<...>): void; request<K extends keyof Requests = keyof Requests, P extends unknown[] = Parameters<...>, R = ReturnType<...>>(key: K, ...params: P): Promise<...>; }
}

The variable client can be used to do plain requests, or to listen for events. For a more detailed list of what can be done you can refer to the API docs.

With that client you can do things like login, change the logo with set-logo, or list the avatars with avatars.

The calls are done with the request method of the client.

ts
const avatars = await client.request('avatars')
const avatars: { succeed: boolean; data?: Avatar[] | undefined; error?: Error | undefined; }
ts
const avatars = await client.request('avatars')
const avatars: { succeed: boolean; data?: Avatar[] | undefined; error?: Error | undefined; }

Examples​

Some more detailed examples are hosted here: https://github.com/LinkingRealities/iframe-examples

Getting to know more about the API​

More information on what can be done with the client inside the Api section.