mirror of
https://codeberg.org/Schoumi/PeerTubeLive.git
synced 2025-01-28 18:20:44 +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) {
|
if(oauthData.expires < Calendar.getInstance().timeInMillis) {
|
||||||
refreshToken(context,url,oauthData,object: InstanceListener {
|
refreshToken(context,url,oauthData,object: InstanceListener {
|
||||||
override fun onSuccess(args: Bundle?) {
|
override fun onSuccess(args: Bundle?) {
|
||||||
val oauth: OAuthData? = args?.getParcelable(InstanceManager.EXTRA_DATA)
|
val oauth: OAuthData? = args?.getParcelable(EXTRA_DATA)
|
||||||
if (oauth != null) {
|
if (oauth != null) {
|
||||||
DatabaseManager.updateCredentials(context,oauth)
|
DatabaseManager.updateCredentials(context,oauth)
|
||||||
listener.onUpdateOAuthData(oauth)
|
listener.onUpdateOAuthData(oauth)
|
||||||
@ -148,25 +148,32 @@ object InstanceManager {
|
|||||||
// val comments: Boolean, val download: Boolean, val nsfw: Boolean, val saveReplay: Boolean
|
// val comments: Boolean, val download: Boolean, val nsfw: Boolean, val saveReplay: Boolean
|
||||||
val createLiveUrl = url + BASE_API_ENDPOINT + CREATE_LIVE_ENDPOINT
|
val createLiveUrl = url + BASE_API_ENDPOINT + CREATE_LIVE_ENDPOINT
|
||||||
val data = Bundle()
|
val data = Bundle()
|
||||||
val boundary = "45fcc22"
|
val formData = JSONObject()
|
||||||
var formData: String = prepareFormData(boundary,"channelId",streamSettings.channel.toString(),false)
|
formData.put("channelId",streamSettings.channel)
|
||||||
formData += prepareFormData(boundary,"name",streamSettings.title,false)
|
formData.put("name",streamSettings.title)
|
||||||
formData += prepareFormData(boundary,"privacy",streamSettings.privacy.toString(),false)
|
formData.put("privacy",streamSettings.privacy)
|
||||||
if(streamSettings.category != null)
|
if(streamSettings.category != null)
|
||||||
formData += prepareFormData(boundary,"category",streamSettings.category.toString(),false)
|
formData.put("category",streamSettings.category)
|
||||||
if(streamSettings.language != null)
|
if(streamSettings.language != null)
|
||||||
formData += prepareFormData(boundary,"language",streamSettings.language.toString(),false)
|
formData.put("language",streamSettings.language.toString())
|
||||||
if(streamSettings.description != null)
|
if(streamSettings.description != null)
|
||||||
formData += prepareFormData(boundary,"description",streamSettings.description.toString(),false)
|
formData.put("description",streamSettings.description)
|
||||||
if(streamSettings.licence != null)
|
if(streamSettings.licence != null)
|
||||||
formData += prepareFormData(boundary,"licence",streamSettings.licence.toString(),false)
|
formData.put("licence",streamSettings.licence)
|
||||||
formData += prepareFormData(boundary,"commentsEnabled",streamSettings.comments.toString(),false)
|
formData.put("commentsEnabled",streamSettings.comments.toString())
|
||||||
formData += prepareFormData(boundary,"nsfw",streamSettings.nsfw.toString(),false)
|
formData.put("nsfw",streamSettings.nsfw.toString())
|
||||||
formData += prepareFormData(boundary,"downloadEnabled",streamSettings.download.toString(),streamSettings.saveReplay == null)
|
formData.put("downloadEnabled",streamSettings.download.toString())
|
||||||
if (streamSettings.saveReplay != null)
|
if (streamSettings.saveReplay != null) {
|
||||||
formData += prepareFormData(boundary,"saveReplay",streamSettings.saveReplay.toString(),true)
|
formData.put("saveReplay",streamSettings.saveReplay.toString())
|
||||||
data.putString(CONTENT_TYPE,"multipart/form-data; boundary=$boundary")
|
val privacyReplay = JSONObject()
|
||||||
data.putString(CONTENT_DATA,formData)
|
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 {
|
val internalListener = object: InstanceListener {
|
||||||
override fun onSuccess(args: Bundle?) {
|
override fun onSuccess(args: Bundle?) {
|
||||||
val response = args?.getString(EXTRA_DATA, null)
|
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>? {
|
private fun <T> extractMapData(response: String, type: T): HashMap<String,T>? {
|
||||||
return try {
|
return try {
|
||||||
val json = JSONObject(response)
|
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{
|
interface InstanceListener{
|
||||||
fun onSuccess(args: Bundle?)
|
fun onSuccess(args: Bundle?)
|
||||||
fun onError(error: String?)
|
fun onError(error: String?)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user