Owncast support added

This commit is contained in:
Luxferre
2024-09-15 10:01:42 +03:00
parent f5d17720b3
commit 17b60c3303
4 changed files with 23 additions and 8 deletions
+2 -3
View File
@@ -191,7 +191,7 @@ As of now, nothing needs to be done except setting the `yt_backend_enabled` fiel
The following procedure needs to be only done once: The following procedure needs to be only done once:
1. Go to the admin panel of your Owncast server. Open the "Integrations" - "Access tokens" menu item. 1. Go to the admin panel of your Owncast server. Open the "Integrations" - "Access Tokens" menu item.
2. Create a new access token with the "Can perform administrative actions such as moderation, get server statuses, etc" permission. 2. Create a new access token with the "Can perform administrative actions such as moderation, get server statuses, etc" permission.
3. Copy the token string generated in the admin panel and paste it into the `oc-token.txt` file in the `auth` subdirectory in the application directory. 3. Copy the token string generated in the admin panel and paste it into the `oc-token.txt` file in the `auth` subdirectory in the application directory.
4. Save the file. The Owncast connection should now work and fetch messages whenever you start a livestream. 4. Save the file. The Owncast connection should now work and fetch messages whenever you start a livestream.
@@ -265,8 +265,7 @@ Additionally, YouTube does not have its own chat emote API as of now, so the emo
### Owncast (internal) ### Owncast (internal)
Work in progress. Work in progress. Need additional testing. Basic messages work as expected.
## FAQ ## FAQ
+1 -1
View File
@@ -9,7 +9,7 @@
"yt_api_root_url": "https://yt.lemnoslife.com/noKey", "yt_api_root_url": "https://yt.lemnoslife.com/noKey",
"yt_api_poll_timeout": 3, "yt_api_poll_timeout": 3,
"yt_channel": "@foxyshadow", "yt_channel": "@foxyshadow",
"oc_backend_enabled": false, "oc_backend_enabled": true,
"oc_server": "https://streams.luxferre.top", "oc_server": "https://streams.luxferre.top",
"oc_api_poll_timeout": 2 "oc_api_poll_timeout": 2
} }
+18 -4
View File
@@ -60,15 +60,22 @@ func oc_api_get(endpoint string) []interface{} {
return respbody return respbody
} }
/*
[{"timestamp":"2024-09-15T06:37:36.022049086Z","type":"CHAT","id":"PrBY39eSg","user":{"createdAt":"2024-09-14T11:51:52.135597747Z","id":"SmcN3l6Ig","displayName":"inspiring-joliot","previousNames":["inspiring-joliot"],"scopes":[""],"displayColor":0,"isBot":false,"authenticated":false},"body":"\u003cp\u003etest\u003c/p\u003e"},
{"timestamp":"2024-09-15T06:38:20.410448447Z","type":"CHAT","id":"lIgyqr6Sg","user":{"createdAt":"2024-09-14T11:51:52.135597747Z","id":"SmcN3l6Ig","displayName":"inspiring-joliot","previousNames":["inspiring-joliot"],"scopes":[""],"displayColor":0,"isBot":false,"authenticated":false},"body":"\u003cp\u003exlol\u003c/p\u003e"}]
*/
/* main message procesing function */ /* main message procesing function */
func oc_process_message(rawmsg map[string]interface{}) { func oc_process_message(rawmsg map[string]interface{}) {
/* if the message came from a real user, this is the one we should process */ /* if the message came from a real user, this is the one we should process */
if rawmsg["type"] == "UserMessage" { if rawmsg["type"] == "CHAT" {
if !slices.Contains(oc_msg_id_cache, rawmsg["id"].(string)) { /* we have a fresh message here */ if !slices.Contains(oc_msg_id_cache, rawmsg["id"].(string)) { /* we have a fresh message here */
author := rawmsg["user"].(map[string]interface{}) author := rawmsg["user"].(map[string]interface{})
/* convert the timestamp - TODO determine the correct format */ /* convert the timestamp */
sent_dt, _ := time.Parse("2006-01-02T15:04:05.000000-07:00", rawmsg["timestamp"].(string)) sent_dt, _ := time.Parse("2006-01-02T15:04:05.000000000Z", rawmsg["timestamp"].(string))
/* prepare output message */ /* prepare output message */
out_message := ChatMessage { out_message := ChatMessage {
@@ -79,6 +86,10 @@ func oc_process_message(rawmsg map[string]interface{}) {
Icon: "", Icon: "",
} }
/* remove starting and ending <p> tag from the message */
out_message.Text = strings.ReplaceAll(out_message.Text, "\u003cp\u003e", "")
out_message.Text = strings.ReplaceAll(out_message.Text, "\u003c/p\u003e", "")
/* check for authenticated role */ /* check for authenticated role */
if _, ok := author["authenticated"]; ok && author["authenticated"].(bool) == true { if _, ok := author["authenticated"]; ok && author["authenticated"].(bool) == true {
out_message.Type += "-authenticated" out_message.Type += "-authenticated"
@@ -90,7 +101,10 @@ func oc_process_message(rawmsg map[string]interface{}) {
} }
/* add display color hint */ /* add display color hint */
out_message.Type += fmt.Sprintf("-occolor%d", int(author["displayColor"].(float64))) dcolor := int(author["displayColor"].(float64))
if dcolor > 0 {
out_message.Type += fmt.Sprintf("-occolor%d", dcolor)
}
/* finally, send it to the message broker via the message_transport channel */ /* finally, send it to the message broker via the message_transport channel */
message_transport <- out_message message_transport <- out_message
+2
View File
@@ -89,6 +89,8 @@ html, body {
width: 16px; width: 16px;
background-size: 16px; background-size: 16px;
background-repeat no-repeat; background-repeat no-repeat;
position: relative;
top: 2px;
} }
.timestamp { .timestamp {