diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index 53896014f..992e0d4e1 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -318,9 +318,11 @@ char* dc_get_blobdir (const dc_context_t* context); * The library uses the `media_quality` setting to use different defaults * for recoding images sent with type DC_MSG_IMAGE. * If needed, recoding other file types is up to the UI. - * - `webrtc_instance` = address to webrtc instance to use for videochats, - * eg. a server as of https://github.com/cracker0dks/basicwebrtc. - * Format: https://example.com/subdir#roomname=$ROOM + * - `webrtc_instance` = webrtc instance to use for videochats in the form + * `[basicwebrtc:]https://example.com/subdir#roomname=$ROOM` + * if the url is prefixed by `basicwebrtc`, the server is assumed to be of the type + * https://github.com/cracker0dks/basicwebrtc which some UIs have native support for. + * If no type is prefixed, the videochat is handled completely in a browser. * * If you want to retrieve a value, use dc_get_config(). * diff --git a/src/chat.rs b/src/chat.rs index 09b9764e8..e1483128b 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1619,22 +1619,24 @@ pub async fn send_videochat_invitation(context: &Context, chat_id: ChatId) -> Re chat_id ); - let url = if let Some(webrtc_instance) = context.get_config(Config::WebrtcInstance).await { - webrtc_instance + let instance = if let Some(instance) = context.get_config(Config::WebrtcInstance).await { + instance } else { bail!("webrtc_instance not set"); }; let room = dc_create_id(); - let url = if url.contains("$ROOM") { - url.replace("$ROOM", &room) + let instance = if instance.contains("$ROOM") { + instance.replace("$ROOM", &room) } else { - format!("{}{}", url, room) + format!("{}{}", instance, room) }; + let url = instance.replace("basicwebrtc:", ""); + let mut msg = Message::new(Viewtype::VideochatInvitation); - msg.param.set(Param::VideochatUrl, &url); + msg.param.set(Param::WebrtcInstance, &instance); msg.text = Some( context .stock_string_repl_str(StockMessage::VideochatInviteMsgBody, url) diff --git a/src/headerdef.rs b/src/headerdef.rs index a3b079fe0..482a47ada 100644 --- a/src/headerdef.rs +++ b/src/headerdef.rs @@ -35,7 +35,7 @@ pub enum HeaderDef { ChatContent, ChatDuration, ChatDispositionNotificationTo, - ChatVideochatUrl, + ChatWebrtcInstance, Autocrypt, AutocryptSetupMessage, SecureJoin, diff --git a/src/message.rs b/src/message.rs index e8b3f6148..affdfa2c1 100644 --- a/src/message.rs +++ b/src/message.rs @@ -640,16 +640,20 @@ impl Message { pub async fn get_videochat_url(&self) -> Option { if self.viewtype == Viewtype::VideochatInvitation { - self.param.get(Param::VideochatUrl).map(|s| s.to_string()) - } else { - None + if let Some(instance) = self.param.get(Param::WebrtcInstance) { + return Some(instance.replace("basicwebrtc:", "")); + } } + None } pub fn is_basic_videochat(&self) -> bool { - // currently, all videochat-urls are of type basic-webrtc - self.viewtype == Viewtype::VideochatInvitation - && self.param.get(Param::VideochatUrl).is_some() + if self.viewtype == Viewtype::VideochatInvitation { + if let Some(instance) = self.param.get(Param::WebrtcInstance) { + return instance.starts_with("basicwebrtc:"); + } + } + false } pub fn set_text(&mut self, text: Option) { diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 822f3ab97..7558ef523 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -881,10 +881,10 @@ impl<'a, 'b> MimeFactory<'a, 'b> { "videochat-invitation".into(), )); protected_headers.push(Header::new( - "Chat-Videochat-Url".into(), + "Chat-Webrtc-Instance".into(), self.msg .param - .get(Param::VideochatUrl) + .get(Param::WebrtcInstance) .unwrap_or_default() .into(), )); diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 5f3338804..7dc3e5766 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -245,10 +245,11 @@ impl MimeMessage { fn parse_videochat_headers(&mut self) { if let Some(value) = self.get(HeaderDef::ChatContent).cloned() { if value == "videochat-invitation" { - let url = self.get(HeaderDef::ChatVideochatUrl).cloned(); + let instance = self.get(HeaderDef::ChatWebrtcInstance).cloned(); if let Some(part) = self.parts.first_mut() { part.typ = Viewtype::VideochatInvitation; - part.param.set(Param::VideochatUrl, url.unwrap_or_default()); + part.param + .set(Param::WebrtcInstance, instance.unwrap_or_default()); } } } @@ -1473,7 +1474,7 @@ mod tests { assert_eq!( mimeparser.parts[0] .param - .get(Param::VideochatUrl) + .get(Param::WebrtcInstance) .unwrap_or_default(), "https://example.org/p2p/?roomname=6HiduoAn4xN" ); diff --git a/src/param.rs b/src/param.rs index 8ccfd8bfc..f3681ebc3 100644 --- a/src/param.rs +++ b/src/param.rs @@ -69,7 +69,7 @@ pub enum Param { AttachGroupImage = b'A', /// For Messages - VideochatUrl = b'V', + WebrtcInstance = b'V', /// For Messages: space-separated list of messaged IDs of forwarded copies. /// diff --git a/test-data/message/videochat_invitation.eml b/test-data/message/videochat_invitation.eml index 2851dc319..9b4e35031 100644 --- a/test-data/message/videochat_invitation.eml +++ b/test-data/message/videochat_invitation.eml @@ -5,7 +5,7 @@ Date: Mon, 20 Jul 2020 14:28:30 +0000 X-Mailer: Delta Chat Core 1.40.0/CLI Chat-Version: 1.0 Chat-Content: videochat-invitation -Chat-Videochat-Url: https://example.org/p2p/?roomname=6HiduoAn4xN +Chat-Webrtc-Instance: https://example.org/p2p/?roomname=6HiduoAn4xN To: From: "=?utf-8?q??="