mirror of
https://codeberg.org/Schoumi/PeerTubeLive.git
synced 2025-01-15 12:06:02 +01:00
Merge pull request 'Add Replay Settings support' (#49) from replay_5_2 into master
Add Replay Settings support Change forms-data to json format in live stream initiation Reviewed-on: https://codeberg.org/Schoumi/PeerTubeLive/pulls/49
This commit is contained in:
commit
f55b579139
@ -91,7 +91,7 @@ object InstanceManager {
|
||||
if(oauthData.expires < Calendar.getInstance().timeInMillis) {
|
||||
refreshToken(context,url,oauthData,object: InstanceListener {
|
||||
override fun onSuccess(args: Bundle?) {
|
||||
val oauth: OAuthData? = args?.getParcelable(InstanceManager.EXTRA_DATA)
|
||||
val oauth: OAuthData? = args?.getParcelable(EXTRA_DATA)
|
||||
if (oauth != null) {
|
||||
DatabaseManager.updateCredentials(context,oauth)
|
||||
listener.onUpdateOAuthData(oauth)
|
||||
@ -148,25 +148,32 @@ object InstanceManager {
|
||||
// val comments: Boolean, val download: Boolean, val nsfw: Boolean, val saveReplay: Boolean
|
||||
val createLiveUrl = url + BASE_API_ENDPOINT + CREATE_LIVE_ENDPOINT
|
||||
val data = Bundle()
|
||||
val boundary = "45fcc22"
|
||||
var formData: String = prepareFormData(boundary,"channelId",streamSettings.channel.toString(),false)
|
||||
formData += prepareFormData(boundary,"name",streamSettings.title,false)
|
||||
formData += prepareFormData(boundary,"privacy",streamSettings.privacy.toString(),false)
|
||||
val formData = JSONObject()
|
||||
formData.put("channelId",streamSettings.channel)
|
||||
formData.put("name",streamSettings.title)
|
||||
formData.put("privacy",streamSettings.privacy)
|
||||
if(streamSettings.category != null)
|
||||
formData += prepareFormData(boundary,"category",streamSettings.category.toString(),false)
|
||||
formData.put("category",streamSettings.category)
|
||||
if(streamSettings.language != null)
|
||||
formData += prepareFormData(boundary,"language",streamSettings.language.toString(),false)
|
||||
formData.put("language",streamSettings.language.toString())
|
||||
if(streamSettings.description != null)
|
||||
formData += prepareFormData(boundary,"description",streamSettings.description.toString(),false)
|
||||
formData.put("description",streamSettings.description)
|
||||
if(streamSettings.licence != null)
|
||||
formData += prepareFormData(boundary,"licence",streamSettings.licence.toString(),false)
|
||||
formData += prepareFormData(boundary,"commentsEnabled",streamSettings.comments.toString(),false)
|
||||
formData += prepareFormData(boundary,"nsfw",streamSettings.nsfw.toString(),false)
|
||||
formData += prepareFormData(boundary,"downloadEnabled",streamSettings.download.toString(),streamSettings.saveReplay == null)
|
||||
if (streamSettings.saveReplay != null)
|
||||
formData += prepareFormData(boundary,"saveReplay",streamSettings.saveReplay.toString(),true)
|
||||
data.putString(CONTENT_TYPE,"multipart/form-data; boundary=$boundary")
|
||||
data.putString(CONTENT_DATA,formData)
|
||||
formData.put("licence",streamSettings.licence)
|
||||
formData.put("commentsEnabled",streamSettings.comments.toString())
|
||||
formData.put("nsfw",streamSettings.nsfw.toString())
|
||||
formData.put("downloadEnabled",streamSettings.download.toString())
|
||||
if (streamSettings.saveReplay != null) {
|
||||
formData.put("saveReplay",streamSettings.saveReplay.toString())
|
||||
val privacyReplay = JSONObject()
|
||||
privacyReplay.put("privacy",streamSettings.privacy)
|
||||
formData.put("replaySettings",privacyReplay)
|
||||
}
|
||||
|
||||
data.putString(CONTENT_TYPE,"application/json")
|
||||
data.putString(CONTENT_DATA,formData.toString())
|
||||
println(formData.toString())
|
||||
|
||||
val internalListener = object: InstanceListener {
|
||||
override fun onSuccess(args: Bundle?) {
|
||||
val response = args?.getString(EXTRA_DATA, null)
|
||||
@ -500,6 +507,7 @@ object InstanceManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun <T> extractMapData(response: String, type: T): HashMap<String,T>? {
|
||||
return try {
|
||||
val json = JSONObject(response)
|
||||
@ -517,21 +525,6 @@ object InstanceManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun prepareFormData(boundary: String, propertyName: String, property: String, lastData: Boolean): String {
|
||||
val crlf = "\r\n"
|
||||
var formData = "--$boundary$crlf"
|
||||
formData+="Content-Disposition: form-data; name=\"$propertyName\"$crlf$crlf"
|
||||
formData+="$property$crlf"
|
||||
|
||||
if(lastData) {
|
||||
formData += "--$boundary--$crlf"
|
||||
}
|
||||
|
||||
return formData
|
||||
}
|
||||
|
||||
|
||||
interface InstanceListener{
|
||||
fun onSuccess(args: Bundle?)
|
||||
fun onError(error: String?)
|
||||
|
Loading…
Reference in New Issue
Block a user