Skip to content

Commit

Permalink
add support for custom room server url
Browse files Browse the repository at this point in the history
  • Loading branch information
ashiqursuperfly committed Nov 15, 2020
1 parent 3be67a8 commit f9581f5
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions app/src/main/java/com/ashiqurrahman/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.util.Log
import android.view.View
import android.widget.Toast
import com.ashiqurrahman.easyvidchat.VidChat
import com.ashiqurrahman.easyvidchat.data.CustomTURNSTUNConfig
import com.ashiqurrahman.easyvidchat.data.VidChatConfig
import kotlinx.android.synthetic.main.activity_main.*

Expand All @@ -35,6 +36,16 @@ class MainActivity : AppCompatActivity() {
Toast.makeText(this, "Clicked Custom button", Toast.LENGTH_LONG).show()
}

val customTURNSTUNConfig = CustomTURNSTUNConfig(
turnServerUrl = "turn:103.147.168.11:3478",
stunServerUrl = "stun:103.147.168.11:3478",
username = "askdoctorbd",
credential = "swot24434"
)

VidChatConfig.customRoomServerUrl = "https://103.147.168.11:8081"
VidChatConfig.customTURNSTUNConfig = customTURNSTUNConfig

VidChat.requestVideoChatPermissions(this, PERMISSION_REQUEST_CODE)

btn_call.setOnClickListener {
Expand Down
14 changes: 10 additions & 4 deletions easyvidchat/src/main/java/com/ashiqurrahman/easyvidchat/VidChat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object VidChat {
roomID: String
): Intent {

val roomUrl = VidChatConsts.ROOM_BASE_URL
val roomUrl = if (VidChatConfig.customRoomServerUrl == null) "https://appr.tc" else VidChatConfig.customRoomServerUrl.toString()

// Video call enabled flag.
val videoCallEnabled = VidChatConfig.videoCallEnabled
Expand Down Expand Up @@ -159,7 +159,10 @@ object VidChat {
intent.putExtra(VidChatConsts.EXTRA_FLEXFEC_ENABLED, flexfecEnabled)
intent.putExtra(VidChatConsts.EXTRA_NOAUDIOPROCESSING_ENABLED, noAudioProcessing)
intent.putExtra(VidChatConsts.EXTRA_AECDUMP_ENABLED, aecDump)
intent.putExtra(VidChatConsts.EXTRA_SAVE_INPUT_AUDIO_TO_FILE_ENABLED, saveInputAudioToFile)
intent.putExtra(
VidChatConsts.EXTRA_SAVE_INPUT_AUDIO_TO_FILE_ENABLED,
saveInputAudioToFile
)
intent.putExtra(VidChatConsts.EXTRA_OPENSLES_ENABLED, useOpenSLES)
intent.putExtra(VidChatConsts.EXTRA_DISABLE_BUILT_IN_AEC, disableBuiltInAEC)
intent.putExtra(VidChatConsts.EXTRA_DISABLE_BUILT_IN_AGC, disableBuiltInAGC)
Expand All @@ -171,7 +174,10 @@ object VidChat {
intent.putExtra(VidChatConsts.EXTRA_TRACING, tracing)
intent.putExtra(VidChatConsts.EXTRA_ENABLE_RTCEVENTLOG, rtcEventLogEnabled)
intent.putExtra(VidChatConsts.EXTRA_CMDLINE, VidChatConfig.isDebug)
intent.putExtra(VidChatConsts.EXTRA_RUNTIME, if (VidChatConfig.isDebug) VidChatConsts.DEFAULT_DEBUG_RUNTIME else 0)
intent.putExtra(
VidChatConsts.EXTRA_RUNTIME,
if (VidChatConfig.isDebug) VidChatConsts.DEFAULT_DEBUG_RUNTIME else 0
)
intent.putExtra(VidChatConsts.EXTRA_DATA_CHANNEL_ENABLED, dataChannelEnabled)
if (dataChannelEnabled) {
intent.putExtra(VidChatConsts.EXTRA_ORDERED, ordered)
Expand All @@ -186,7 +192,7 @@ object VidChat {
return intent
}

fun requestVideoChatPermissions(activity: Activity,requestCode: Int) {
fun requestVideoChatPermissions(activity: Activity, requestCode: Int) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
// Dynamic permissions are not required before Android M.
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ object VidChatConfig {

// configurable custom turn and stun server url.
var customTURNSTUNConfig: CustomTURNSTUNConfig? = null
var customRoomServerUrl: String? = null

const val speakerPhone = "auto"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.ashiqurrahman.easyvidchat.data

import android.Manifest
import com.ashiqurrahman.easyvidchat.data.VidChatConfig.customRoomServerUrl

/* Created by ashiq.buet16 **/

object VidChatConsts {

const val DEFAULT_DEBUG_RUNTIME = 10*60*1000

const val ROOM_BASE_URL = "https://appr.tc"

const val EXTRA_VIDEO_CALL = "org.appspot.apprtc.VIDEO_CALL"
const val EXTRA_ROOMID = "org.appspot.apprtc.ROOMID"
const val EXTRA_URLPARAMETERS = "org.appspot.apprtc.URLPARAMETERS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Asynchronous http requests implementation.
*/
public class AsyncHttpURLConnection {
private static final String HTTP_ORIGIN = "https://appr.tc";
private static final String HTTP_ORIGIN = (VidChatConfig.INSTANCE.getCustomRoomServerUrl() == null) ? "https://appr.tc" : VidChatConfig.INSTANCE.getCustomRoomServerUrl();
private final String method;
private final String url;
private final String message;
Expand Down Expand Up @@ -90,7 +90,7 @@ private void sendHttpMessage() {
// Get response.
int responseCode = connection.getResponseCode();
if (responseCode != 200) {
events.onHttpError("Non-200 ("+ responseCode +") response to " + method + " to URL: " + url + " : "
events.onHttpError("Non-200 (" + responseCode + ") response to " + method + " to URL: " + url + " : "
+ connection.getHeaderField(null));
connection.disconnect();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void roomHttpResponseParse(String response) {
Log.d(TAG, "Initiator: " + initiator);
Log.d(TAG, "WSS url: " + wssUrl);
Log.d(TAG, "WSS POST url: " + wssPostUrl);
List<PeerConnection.IceServer> iceServers = iceServersFromPCConfigJSON(roomJson.getString("pc_config"));
List<PeerConnection.IceServer> iceServers = (VidChatConfig.INSTANCE.getCustomRoomServerUrl() == null)?iceServersFromPCConfigJSON(roomJson.getString("pc_config")):iceServersFromPCConfigJSONCustom(roomJson.getString("pc_config"));

if (VidChatConfig.INSTANCE.getCustomTURNSTUNConfig() != null) {
// Request TURN servers.
Expand Down Expand Up @@ -190,7 +190,7 @@ private List<PeerConnection.IceServer> requestTurnServers(String url)
Log.d(TAG, "Request TURN from: " + url);
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("REFERER", "https://appr.tc");
connection.setRequestProperty("REFERER", (VidChatConfig.INSTANCE.getCustomRoomServerUrl() == null)?"https://appr.tc":VidChatConfig.INSTANCE.getCustomRoomServerUrl());
connection.setConnectTimeout(TURN_HTTP_TIMEOUT_MS);
connection.setReadTimeout(TURN_HTTP_TIMEOUT_MS);
int responseCode = connection.getResponseCode();
Expand Down Expand Up @@ -242,6 +242,26 @@ private List<PeerConnection.IceServer> iceServersFromPCConfigJSON(String pcConfi
return ret;
}

private List<PeerConnection.IceServer> iceServersFromPCConfigJSONCustom(String pcConfig)
throws JSONException {
JSONObject json = new JSONObject(pcConfig);
JSONArray servers = json.getJSONArray("iceServers");
List<PeerConnection.IceServer> ret = new ArrayList<>();
for (int i = 0; i < servers.length(); ++i) {
JSONObject server = servers.getJSONObject(i);
String url = server.getString("urls");
String credential = server.has("credential") ? server.getString("credential") : "";
String username = server.has("username") ? server.getString("username") : "";
PeerConnection.IceServer turnServer = PeerConnection.IceServer.builder(url).setTlsCertPolicy(PeerConnection.TlsCertPolicy.TLS_CERT_POLICY_SECURE)
.setPassword(credential)
.setUsername(username)
.createIceServer();
ret.add(turnServer);
Log.d(TAG, "TURN Server In list: " + turnServer);
}
return ret;
}

// Return the contents of an InputStream as a String.
private static String drainStream(InputStream in) {
Scanner s = new Scanner(in, "UTF-8").useDelimiter("\\A");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.webrtc.SessionDescription;

/**
* Negotiates signaling for chatting with https://appr.tc "rooms".
* Negotiates signaling for chatting with https://appr.tc (or customRoomServerUrl) "rooms".
* Uses the client<->server specifics of the apprtc AppEngine webapp.
*
* <p>To use: create an instance of this object (registering a message handler) and
Expand Down

0 comments on commit f9581f5

Please sign in to comment.