import {Config} from "../config.js";
import {http} from "../utils/http/index.js"
/**
*
* @class Whiteboard
* This is an experimental API.
*
*/
export class Whiteboard {
constructor(meetingId, meetingToken) {
this.meetingId = meetingId
this.meetingToken = meetingToken
}
/**
*
* @async
* @param {object} param0
* @param {string} param0.image
* @param {data} param0.type
* @returns {string}
*/
async saveImage({ image, type }) {
type = type || ""
switch (type.toLowerCase()) {
case "jpeg":
type = "IMAGE_JPEG"
break
case "webp":
type = "IMAGE_WEBP"
break
default:
type = ""
break
}
let headers = {
"Content-Type": "image/jpeg",
Accept: "application/json",
"x-jibb-meeting-jwt": this.meetingToken,
}
let body = {
image: image,
type: type,
}
let response = await http.post(
`${Config.apiBaseURL}/v1/meetings/${this.meetingId}/whiteboard/images`,
body,
headers
)
return response.data.imageName
}
/**
*
* @async
* @returns {array}
*/
async getImageList() {
let headers = {
"Content-Type": "application/json",
Accept: "application/json",
"x-jibb-meeting-jwt": this.meetingToken,
}
let response = await http.get(`${Config.apiBaseURL}/v1/meetings/${this.meetingId}/whiteboard/images`, headers)
return response.data.imagesName
}
/**
*
* @async
* @param {string} imageName
* @returns {data}
*/
async getImage(imageName) {
let headers = {
"Content-Type": "application/json",
Accept: "image/jpeg",
"x-jibb-meeting-jwt": this.meetingToken,
}
let url = `${Config.apiBaseURL}/v1/meetings/${this.meetingId}/whiteboard/images/${imageName}`
let response = await http.get(url, headers, { responseType: "arraybuffer" })
return response.data
}
/**
*
* @async
* @returns {array}
*/
async getImages() {
let imageList = []
let imageNameList = await this.getImageList()
for (const imageName of imageNameList) {
let headers = {
"Content-Type": "application/json",
Accept: "application/json",
"x-jibb-meeting-jwt": this.meetingToken,
}
let response = await http.get(
`${Config.apiBaseURL}/v1/meetings/${this.meetingId}/whiteboard/images/${imageName}`,
{
headers,
}
)
imageList.push({ imageName: imageName, data: response.data })
}
return imageList
}
/**
*
* @param {string} imageName
* @returns - http result
*/
async deleteImage(imageName) {
let headers = {
"Content-Type": "application/json",
Accept: "application/json",
"x-jibb-meeting-jwt": this.meetingToken,
}
return http.delete(`${Config.apiBaseURL}/v1/meetings/${this.meetingId}/whiteboard/images/${imageName}`, headers)
}
/**
*
* @async
* @param {string} board
* @returns {}
*/
async saveBoard(board) {
let headers = {
"Content-Type": "application/json",
Accept: "application/json",
"x-jibb-meeting-jwt": this.meetingToken,
}
let body = { board: board }
let response = await http.post(`${Config.apiBaseURL}/v1/meetings/${this.meetingId}/whiteboard`, body, headers)
return response.data
}
/**
*
* @async
* @returns {string}
*/
async getBoard() {
let headers = {
"Content-Type": "application/json",
Accept: "image/jpeg",
"x-jibb-meeting-jwt": this.meetingToken,
}
let response = await http.get(`${Config.apiBaseURL}/v1/meetings/${this.meetingId}/whiteboard`, headers)
return response.data
}
/**
*
* @async
* @returns - http result
*/
async deleteBoard() {
let headers = {
"Content-Type": "application/json",
Accept: "application/json",
"x-jibb-meeting-jwt": this.meetingToken,
}
return http.delete(`${Config.apiBaseURL}/v1/meetings/${this.meetingId}/whiteboard`, headers)
}
}