dev
This commit is contained in:
parent
4201a3d23b
commit
8471ee3649
@ -37,6 +37,15 @@ func CreateWidget(widgetService model.WidgetService, authClient model.AuthClient
|
|||||||
return request.JSON(http.StatusInternalServerError, err.Error())
|
return request.JSON(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if authData.StreamerID == 0 {
|
||||||
|
slog.Error("Unauthorized account")
|
||||||
|
return request.JSON(http.StatusUnauthorized, "Unauthorized")
|
||||||
|
}
|
||||||
|
if authData.StreamerID == -1 {
|
||||||
|
slog.Error("Expired token")
|
||||||
|
return request.JSON(http.StatusUnauthorized, "Expired token")
|
||||||
|
}
|
||||||
|
|
||||||
widgetID, err := widgetService.CreateWidget(
|
widgetID, err := widgetService.CreateWidget(
|
||||||
ctx,
|
ctx,
|
||||||
model.StreamerID(authData.StreamerID),
|
model.StreamerID(authData.StreamerID),
|
||||||
|
@ -41,16 +41,17 @@ func GetTemplate1(
|
|||||||
`, backgroundUrl)
|
`, backgroundUrl)
|
||||||
|
|
||||||
script := fmt.Sprintf(`
|
script := fmt.Sprintf(`
|
||||||
let baseUrl = 'http://147.45.237.174:8002/api'
|
let widgetUrl = 'http://147.45.237.174:8002/api/widget'
|
||||||
|
let ttsUrl = 'http://147.45.237.174:8005/api/tts'
|
||||||
|
|
||||||
async function getDonatInfo(streamerID) {
|
async function getDonatInfo(streamerID) {
|
||||||
let response = await fetch(baseUrl + '/widget/donat/get/' + String(streamerID));
|
let response = await fetch(widgetUrl + '/donat/get/' + String(streamerID));
|
||||||
let donat = await response.json();
|
let donat = await response.json();
|
||||||
return donat
|
return donat
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getWidgetInfo(widgetID) {
|
async function getWidgetInfo(widgetID) {
|
||||||
let response = await fetch(baseUrl + '/widget/info/' + widgetID);
|
let response = await fetch(widgetUrl + '/info/' + widgetID);
|
||||||
let widget = await response.json();
|
let widget = await response.json();
|
||||||
return widget
|
return widget
|
||||||
}
|
}
|
||||||
@ -67,12 +68,22 @@ function addText(text) {
|
|||||||
contentDiv.appendChild(p);
|
contentDiv.appendChild(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addAudio(audioUrl) {
|
function playAudio(audioUrl) {
|
||||||
audio = document.createElement('audio');
|
const audio = new Audio(audioUrl);
|
||||||
audio.src = audioUrl;
|
audio.play()
|
||||||
audio.autoplay = true;
|
await delay(5000);
|
||||||
audio.controls = false;
|
audio.pause();
|
||||||
contentDiv.appendChild(audio);
|
audio.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
function playSpeech(text) {
|
||||||
|
const audio = new Audio(ttsUrl + '/generate, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
text: text,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
audio.play()
|
||||||
}
|
}
|
||||||
|
|
||||||
function delay(ms) {
|
function delay(ms) {
|
||||||
@ -87,7 +98,7 @@ async function endDonat(donatID) {
|
|||||||
while (contentDiv.firstChild) {
|
while (contentDiv.firstChild) {
|
||||||
contentDiv.removeChild(contentDiv.firstChild);
|
contentDiv.removeChild(contentDiv.firstChild);
|
||||||
}
|
}
|
||||||
let response = await fetch(baseUrl + '/widget/donat/view/' + String(donatID), {method: 'POST'});
|
let response = await fetch(widgetUrl + '/donat/view/' + String(donatID), {method: 'POST'});
|
||||||
}
|
}
|
||||||
|
|
||||||
let audio;
|
let audio;
|
||||||
@ -114,8 +125,11 @@ async function widgetView() {
|
|||||||
if (widget.ImageUrl != "") {
|
if (widget.ImageUrl != "") {
|
||||||
addImage(widget.ImageUrl)
|
addImage(widget.ImageUrl)
|
||||||
}
|
}
|
||||||
|
if (widget.AudioUrl) {
|
||||||
|
playAudio(widget.AudioUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
addAudio(widget.AudioUrl)
|
|
||||||
addText(donat.Text + " " + donat.Amount)
|
addText(donat.Text + " " + donat.Amount)
|
||||||
|
|
||||||
await delay(widget.Duration * 1000);
|
await delay(widget.Duration * 1000);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user