JohnXLivingston / peertube-plugin-livechat

GNU Affero General Public License v3.0
86 stars 26 forks source link

Custom fields not handle during video creation only on updates #400

Closed Schoumi closed 2 weeks ago

Schoumi commented 4 weeks ago

Describe the bug I'm looking to add LiveChat in PeerTube Live but when i do enable/disable LiveChat options by sending pluginData[livechat-active] true/false. The video created have always the pluginData[livechat-active] set to true when I look into settings on PeerTube.

PeerTube web create live video with two step when the app make it just in one step. It create the live video with some settings and then update the video created with more settings if you click on update settings button. Only then you have livechat settings set not before.

To Reproduce

  1. Create a live video
  2. Don't click on update
  3. Go to the live video directly

You'll see no chat open and if you look into settings retreived for this video you'll find

    "id": 90,
    ...
    "channel": {...},
    "pluginData": {},
    ...
}

If you have clicked on Update during step 2, the same requests gives (false or true depends on what you select in the process): { "id": 90, ... "channel": {...}, "pluginData": { "livechat-active": false }, ... }

Expected behavior

When I create a live video i want to be able to give the settings in one-step not two no matter of if use the App or the Web App

Additional context

As I search for where the problem is, I found that some hook are made here on API Calls, I think it should have one when the video is created too and not only when updated: https://github.com/JohnXLivingston/peertube-plugin-livechat/blob/decc13ec5a047b8d4f22b8b4eada80e54970e89d/server/lib/custom-fields.ts#L15

JohnXLivingston commented 4 weeks ago

Thanks for the feedback. The plugin custom field documentation is not very clear on how to handle storage for such data. I was aware that there can be such issues.

I'll check that in the coming days (or maybe next week).

PS: i saw a few days ago on Mastodon that you are working on this integration, and i'm very happy with that :). If you have any issue, don't hesitate to ask for a meeting (for the record, i'm french too).

Schoumi commented 4 weeks ago

Great! I'll have some work to do by then on my own. If you need me to test some things, i'll be happy to help.

JohnXLivingston commented 3 weeks ago

@Schoumi : does this PR looks good for you?

You don't plan to ask the streamer if they want to enable/disable the chat?

NB: the action:api.live-video.created hook does not receive the request body as parameter, so i can't use any value you pass on your first API request. So i enable the chat by default, and if you want to disable it you should call the video update API.

Schoumi commented 3 weeks ago

Hum @Chocobozzz said that you should have the body with fields there: https://github.com/Chocobozzz/PeerTube/issues/6441#issuecomment-2162266767

JohnXLivingston commented 3 weeks ago

Hum @Chocobozzz said that you should have the body with fields there: Chocobozzz/PeerTube#6441 (comment)

Ok, my bad.

So, to be clear, you are passing true to body.pluginData['livechat-active']? And if so, i must enable the chat. Right?

Do you offer the choice to the user? (having a chat or not) In this case, do you read the plugin settings? It is possible to enable chat for each live, without using this field. In such case, you don't have to add this field.

Schoumi commented 3 weeks ago

I pass true to body.pluginData['livechat-active'] if the user choose to during the live creation. It's a user choice. I can get the default settings but I prefer let the user choose even if it's a default settings on the instance.

JohnXLivingston commented 3 weeks ago

I pass true to body.pluginData['livechat-active'] if the user choose to during the live creation. It's a user choice. I can get the default settings but I prefer let the user choose even if it's a default settings on the instance.

what i mean is that the chat-all-lives settings is enabled, their will be a chat, even if you pass false.

Schoumi commented 3 weeks ago

oh, ok. In this case, I should hide the settings or at least block user from editing it but showing that it is enabled by default.

JohnXLivingston commented 3 weeks ago

oh, ok. In this case, I should hide the settings or at least block user from editing it but showing that it is enabled by default.

Yes.

If you currently don't check plugin settings, the previous PR could maybe be enough?

What it would do:

Are you displaying the chat in the app?

JohnXLivingston commented 3 weeks ago

If you want us to have a quick call tomorrow (in french?), just tell me.

JohnXLivingston commented 2 weeks ago

@Schoumi : Done in commit https://github.com/JohnXLivingston/peertube-plugin-livechat/pull/413/commits/9e8e2a2572ac4f1afc5fc1fa01f86673bb306dac !

As discussed today, i finally read the pluginData['livechat-active'] parameter on the create live API.

I only read it if the chat-per-live-video settings is true (as discussed).

I tested it with following curl command:

curl 'http://p1.localhost:9001/api/v1/videos/live/' -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: fr,en;q=0.8,fr-FR;q=0.6,en-US;q=0.4,de-DE;q=0.2' -H 'Accept-Encoding: gzip, deflate, br, zstd' -H 'Authorization: Bearer ************' -H 'Content-Type: application/json' -H 'Origin: http://p1.localhost:9001' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Referer: http://p1.localhost:9001/videos/upload' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-origin' -H 'Priority: u=0' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' --data-raw '{"pluginData":{"livechat-active": true}, "name":"Live","privacy":3,"nsfw":false,"waitTranscoding":true,"permanentLive":false,"latencyMode":1,"saveReplay":true,"replaySettings":{"privacy":3},"channelId":18}'

Here is a human-readable version of the data:

{
  "pluginData": {
    "livechat-active": true
  },
  "name": "Live",
  "privacy": 3,
  "nsfw": false,
  "waitTranscoding": true,
  "permanentLive": false,
  "latencyMode": 1,
  "saveReplay": true,
  "replaySettings": {
    "privacy": 3
  },
  "channelId": 18
}

This will be available in livechat v10.1.0. Should be released next week.

JohnXLivingston commented 2 weeks ago

@Schoumi , plugin v10.1.0 was released.