Skip to content

Commit 5e30731

Browse files
committed
WebRTC Peer Connection
1 parent 01bbf40 commit 5e30731

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1479
-2
lines changed
Binary file not shown.
Binary file not shown.
1 Byte
Binary file not shown.
17 Bytes
Binary file not shown.
369 KB
Binary file not shown.
17 Bytes
Binary file not shown.
18.4 KB
Binary file not shown.

.gradle/5.4.1/gc.properties

Whitespace-only changes.
959 KB
Binary file not shown.
17 Bytes
Binary file not shown.
45 KB
Binary file not shown.
1 Byte
Binary file not shown.
18.3 KB
Binary file not shown.
17 Bytes
Binary file not shown.

.gradle/5.6.4/gc.properties

Whitespace-only changes.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#Wed Apr 08 16:40:51 PKT 2020
2+
gradle.version=5.6.4

.gradle/vcs-1/gc.properties

Whitespace-only changes.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ I will start explaining the following Process in very specific detail. So first
217217

218218
**Basic Terminologies:**
219219

220-
- Peer-A <--> `Caller` <--> Bill Gates (Steve) The Person who initiate PeerConnection
221-
- Peer-A <--> `Callee` <--> Steve Jobs (Bill) The Person who accepts PeerConnection
220+
- Peer-A <--> `Caller` <--> Steve Jobs (Steve) The Person who initiate PeerConnection
221+
- Peer-A <--> `Callee` <--> Bill Gates (Bill) The Person who accepts PeerConnection
222222

223223
**PeerConnection** is the API used by the WebRTC Android Application to create connection between peers and communicate `audio` and `video`.
224224
PeerConnection has two tasks to initialize the Process such as:

app/.gitignore

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Built application files
2+
*.apk
3+
*.ap_
4+
*.aab
5+
# Files for the ART/Dalvik VM
6+
*.dex
7+
# Java class files
8+
*.class
9+
# Generated files
10+
bin/
11+
gen/
12+
out/
13+
# Uncomment the following line in case you need and you don't have the release build type files in your app
14+
# release/
15+
# Gradle files
16+
.gradle/
17+
build/
18+
# Local configuration file (sdk path, etc)
19+
local.properties
20+
# Proguard folder generated by Eclipse
21+
proguard/
22+
# Log Files
23+
*.log
24+
# Android Studio Navigation editor temp files
25+
.navigation/
26+
# Android Studio captures folder
27+
captures/
28+
# IntelliJ
29+
*.iml
30+
.idea/workspace.xml
31+
.idea/tasks.xml
32+
.idea/gradle.xml
33+
.idea/assetWizardSettings.xml
34+
.idea/dictionaries
35+
.idea/libraries
36+
# Android Studio 3 in .gitignore file.
37+
.idea/caches
38+
.idea/modules.xml
39+
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
40+
.idea/navEditor.xml
41+
# Keystore files
42+
# Uncomment the following lines if you do not want to check your keystore files in.
43+
#*.jks
44+
#*.keystore
45+
# External native build folder generated in Android Studio 2.2 and later
46+
.externalNativeBuild
47+
app/.cxx/
48+
# Google Services (e.g. APIs or Firebase)
49+
# google-services.json
50+
# Freeline
51+
freeline.py
52+
freeline/
53+
freeline_project_description.json
54+
# fastlane
55+
fastlane/report.xml
56+
fastlane/Preview.html
57+
fastlane/screenshots
58+
fastlane/test_output
59+
fastlane/readme.md
60+
# Version control
61+
vcs.xml
62+
# lint
63+
lint/intermediates/
64+
lint/generated/
65+
lint/outputs/
66+
lint/tmp/
67+
# lint/reports/
68+
Collapse
69+
70+
71+

app/build.gradle

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'com.google.gms.google-services'
3+
4+
android {
5+
compileSdkVersion 29
6+
buildToolsVersion "29.0.2"
7+
defaultConfig {
8+
applicationId "com.example.webrtc"
9+
minSdkVersion 21
10+
targetSdkVersion 29
11+
versionCode 1
12+
versionName "1.0"
13+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14+
}
15+
// buildTypes {
16+
// release {
17+
// minifyEnabled false
18+
// proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
19+
// }
20+
// }
21+
22+
buildTypes {
23+
release {
24+
minifyEnabled false
25+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26+
}
27+
}
28+
}
29+
30+
repositories {
31+
mavenCentral()
32+
}
33+
34+
dependencies {
35+
implementation fileTree(dir: 'libs', include: ['*.jar'])
36+
implementation 'androidx.appcompat:appcompat:1.1.0'
37+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
38+
implementation 'io.pristine:libjingle:11139@aar'
39+
implementation 'com.google.code.gson:gson:2.8.6'
40+
implementation 'com.android.volley:volley:1.1.1'
41+
42+
implementation 'com.google.firebase:firebase-database:19.2.1'
43+
testImplementation 'junit:junit:4.12'
44+
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
45+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
46+
47+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/src/main/AndroidManifest.xml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.example.webrtc">
5+
6+
<uses-feature android:name="android.hardware.camera" />
7+
<uses-feature android:name="android.hardware.camera.autofocus" />
8+
<uses-feature
9+
android:glEsVersion="0x00020000"
10+
android:required="true" />
11+
12+
<uses-permission android:name="android.permission.CAMERA" />
13+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
14+
<uses-permission android:name="android.permission.INTERNET" />
15+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
16+
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
17+
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
18+
19+
<application
20+
android:allowBackup="true"
21+
android:icon="@mipmap/ic_launcher"
22+
android:label="@string/app_name"
23+
android:roundIcon="@mipmap/ic_launcher_round"
24+
android:supportsRtl="true"
25+
android:theme="@style/AppTheme"
26+
tools:ignore="GoogleAppIndexingWarning">
27+
<activity android:name="com.example.webrtc.MainActivity">
28+
<intent-filter>
29+
<action android:name="android.intent.action.MAIN" />
30+
31+
<category android:name="android.intent.category.LAUNCHER" />
32+
</intent-filter>
33+
</activity>
34+
</application>
35+
36+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.example.webrtc;
2+
3+
import android.annotation.TargetApi;
4+
import android.media.AudioAttributes;
5+
import android.media.AudioFormat;
6+
import android.media.AudioRecord;
7+
import android.media.AudioTrack;
8+
import android.media.MediaRecorder;
9+
import android.os.Build;
10+
import android.util.Log;
11+
12+
public class Audio {
13+
14+
private static final String TAG = "Audio";
15+
16+
public static final int SAMPLE_RATE = 16000;
17+
18+
private AudioRecord audioRecord;
19+
private AudioTrack audioTrack;
20+
private int minBufferSizeInBytes;
21+
private byte[] byteData;
22+
23+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
24+
public void inititalize(){
25+
26+
minBufferSizeInBytes = AudioRecord.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
27+
Log.e(TAG, "MIN BUFFER SIZE: " + minBufferSizeInBytes);
28+
// minBufferSizeInShort = minBufferSizeInBytes / 2;
29+
30+
audioRecord = new AudioRecord(MediaRecorder.AudioSource.VOICE_COMMUNICATION, SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, minBufferSizeInBytes);
31+
32+
audioTrack = new AudioTrack(new AudioAttributes.Builder()
33+
.setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED)
34+
.setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
35+
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
36+
.build()
37+
, new AudioFormat.Builder()
38+
.setChannelMask(AudioFormat.CHANNEL_OUT_MONO)
39+
.setSampleRate(SAMPLE_RATE)
40+
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
41+
.build()
42+
, minBufferSizeInBytes, AudioTrack.MODE_STREAM, audioRecord.getAudioSessionId());
43+
44+
byteData = new byte[minBufferSizeInBytes];
45+
}
46+
47+
public void startRecording(){
48+
audioRecord.startRecording();
49+
}
50+
51+
public byte[] getRecordedData(){
52+
audioRecord.read(byteData,0, minBufferSizeInBytes);
53+
return byteData;
54+
}
55+
56+
public void startPlaying(){
57+
audioTrack.play();
58+
}
59+
60+
public void playBytes(byte[] byteData){
61+
audioTrack.write(byteData,0,byteData.length);
62+
}
63+
}
64+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.example.webrtc;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.Button;
8+
import android.widget.EditText;
9+
10+
import com.example.webrtc.webRTCModules.WebRTCConnection;
11+
12+
public class MainActivity extends AppCompatActivity{
13+
14+
private static final String TAG = "MainActivity";
15+
16+
private Button btnSend, btnReceive, btnSendMessage;
17+
18+
private WebRTCConnection connect;
19+
private EditText meetingId_et, username_et, callTo_et;
20+
21+
22+
@Override
23+
protected void onCreate(Bundle savedInstanceState) {
24+
super.onCreate(savedInstanceState);
25+
setContentView(R.layout.activity_main);
26+
27+
btnSend = findViewById(R.id.btn_send);
28+
btnReceive = findViewById(R.id.btn_receive);
29+
btnSendMessage = findViewById(R.id.btn_send_message);
30+
meetingId_et = findViewById(R.id.meetingId);
31+
username_et = findViewById(R.id.username);
32+
callTo_et = findViewById(R.id.callingTo);
33+
34+
}
35+
36+
@Override
37+
protected void onStart() {
38+
super.onStart();
39+
40+
btnSend.setOnClickListener(new View.OnClickListener() {
41+
@Override
42+
public void onClick(View view) {
43+
if (!meetingId_et.getText().toString().equals("") && !username_et.getText().toString().equals("") && !callTo_et.getText().toString().equals("")) {
44+
connect = new WebRTCConnection(getApplicationContext(), meetingId_et.getText().toString(), username_et.getText().toString(), callTo_et.getText().toString(), true);
45+
connect.playAudio();
46+
}
47+
}
48+
});
49+
50+
btnReceive.setOnClickListener(new View.OnClickListener() {
51+
@Override
52+
public void onClick(View view) {
53+
if (!meetingId_et.getText().toString().equals("") && !username_et.getText().toString().equals("") && !callTo_et.getText().toString().equals("")) {
54+
connect = new WebRTCConnection(getApplicationContext(), meetingId_et.getText().toString(), username_et.getText().toString(), callTo_et.getText().toString(), false);
55+
connect.playAudio();
56+
}
57+
}
58+
});
59+
60+
btnSendMessage.setOnClickListener(new View.OnClickListener() {
61+
@Override
62+
public void onClick(View v) {
63+
64+
connect.startSend();
65+
}
66+
});
67+
68+
69+
}
70+
71+
72+
}

0 commit comments

Comments
 (0)