Skip to content

Commit 5a20582

Browse files
authored
Merge pull request #2 from PeerRTC/update-branch
Update branch
2 parents 7da2171 + 567a3bf commit 5a20582

File tree

7 files changed

+92
-50
lines changed

7 files changed

+92
-50
lines changed

AndroidPeerRTC/src/main/assets/mediator/mediator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function sourceConnCreateAnswer(sdp){
181181
}
182182

183183

184-
function acceptDeclineConnectRequest(requestId, accept){
184+
function acceptDeclineConnectRequest(requestId, isAccept){
185185
const request = connectionRequests.get(requestId)
186186
if (request) {
187187
if (isAccept) {

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ dependencies {
4545
testImplementation 'junit:junit:4.13.2'
4646
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
4747
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
48-
implementation 'com.github.PeerRTC:AndroidPeerRTC:v1.0.3-beta'
48+
implementation 'com.github.PeerRTC:AndroidPeerRTC:v1.0.4-beta'
4949
}

app/src/main/java/shim/shim/app/MainActivity.kt

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ class MainActivity : AppCompatActivity() {
8888
val receivedVideoView = binding.receivedVideoView
8989

9090
ownVideoView.onMediaAvailable = {
91-
peer.start(isSecure = true)
91+
// prevent starting again if already started
92+
if (!peer.isConnectedToServer){
93+
peer.start(isSecure = true)
94+
}
95+
9296
}
9397
ownVideoView.onMediaNotAvailable = {
9498
Log.i(TAG, "Switched camera or stopped")
@@ -170,7 +174,7 @@ class MainActivity : AppCompatActivity() {
170174

171175
peer.onStart = {
172176
peer.pingServer(10000)
173-
binding.idDisplayView.text = "My id: ${peer.id}"
177+
binding.idDisplayView.text = peer.id
174178
}
175179

176180

@@ -293,22 +297,32 @@ class MainActivity : AppCompatActivity() {
293297
}
294298

295299
binding.sendMessageButton.setOnClickListener {
296-
val inputBox = binding.messageInputBox
297-
val message = inputBox.text.toString()
298-
inputBox.text = null
299-
addMessageToMessageBox(isSender = true, message = message)
300-
peer.sendText(text = message)
300+
if (peer.id == null){
301+
showMessage(message = "Not yet connected to anyone")
302+
} else{
303+
val inputBox = binding.messageInputBox
304+
val message = inputBox.text.toString()
305+
inputBox.text = null
306+
addMessageToMessageBox(isSender = true, message = message)
307+
peer.sendText(text = message)
308+
}
309+
301310
}
302311

303312
binding.endConnectionButton.setOnClickListener {
304313
peer.closeP2P()
305314
}
306315

307316
binding.sendFileButton.setOnClickListener {
308-
val intent = Intent(Intent.ACTION_GET_CONTENT)
309-
intent.type = "*/*"
310-
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
311-
newFileResult.launch(intent)
317+
if (peer.id == null) {
318+
showMessage(message = "Not yet connected to anyone")
319+
} else{
320+
val intent = Intent(Intent.ACTION_GET_CONTENT)
321+
intent.type = "*/*"
322+
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
323+
newFileResult.launch(intent)
324+
}
325+
312326

313327
}
314328

app/src/main/res/layout/activity_main.xml

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,32 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7+
android:background="@color/white"
78
android:orientation="vertical"
9+
android:padding="5dp"
810
tools:context=".MainActivity">
911

10-
<TextView
11-
android:id="@+id/idDisplayView"
12+
<LinearLayout
1213
android:layout_width="match_parent"
1314
android:layout_height="wrap_content"
14-
android:layout_margin="10dp" />
15+
android:gravity="center_vertical">
16+
17+
<TextView
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content"
20+
android:text="My Id:"
21+
android:textSize="17sp"
22+
android:textStyle="bold" />
23+
24+
<TextView
25+
android:id="@+id/idDisplayView"
26+
android:layout_width="0dp"
27+
android:layout_height="wrap_content"
28+
android:layout_margin="10dp"
29+
android:layout_weight="1"
30+
android:textIsSelectable="true"
31+
android:textSize="17sp" />
32+
</LinearLayout>
1533

1634
<LinearLayout
1735
android:id="@+id/incomingConnectRequestView"
@@ -31,12 +49,14 @@
3149
android:orientation="horizontal">
3250

3351
<Button
52+
style="@style/ButtonStyle"
3453
android:id="@+id/acceptRequestButton"
3554
android:layout_width="wrap_content"
3655
android:layout_height="wrap_content"
3756
android:text="Accept" />
3857

3958
<Button
59+
style="@style/ButtonStyle"
4060
android:id="@+id/declineRequestButton"
4161
android:layout_width="wrap_content"
4262
android:layout_height="wrap_content"
@@ -59,12 +79,14 @@
5979

6080
<Button
6181
android:id="@+id/connectToPeerButton"
82+
style="@style/ButtonStyle"
6283
android:layout_width="wrap_content"
6384
android:layout_height="wrap_content"
6485
android:text="Connect" />
6586

6687
<Button
6788
android:id="@+id/endConnectionButton"
89+
style="@style/ButtonStyle"
6890
android:layout_width="wrap_content"
6991
android:layout_height="wrap_content"
7092
android:text="End" />
@@ -81,47 +103,51 @@
81103
android:orientation="horizontal">
82104

83105
<LinearLayout
84-
android:orientation="vertical"
85106
android:layout_width="0dp"
86107
android:layout_height="wrap_content"
87-
android:layout_weight="1">
108+
android:layout_weight="1"
109+
android:orientation="vertical">
88110

89111
<shim.shim.androidpeerrtc.view.MediaSourceView
90112
android:id="@+id/ownVideoView"
91113
android:layout_width="match_parent"
92-
android:layout_height="200dp"
114+
android:layout_height="150dp"
93115
app:cameraType="back"
94116
app:mediaType="video" />
95117

96118
<Button
97119
android:id="@+id/switchCamButton"
120+
style="@style/ButtonStyle"
98121
android:layout_width="wrap_content"
99122
android:layout_height="wrap_content"
100-
android:text="Switch Cam"/>
123+
android:text="Switch Cam" />
101124
</LinearLayout>
102125

103126
<shim.shim.androidpeerrtc.view.MediaSourceView
104127
android:id="@+id/receivedVideoView"
105128
android:layout_width="0dp"
106-
android:layout_height="200dp"
129+
android:layout_height="150dp"
130+
android:layout_marginLeft="10dp"
107131
android:layout_weight="1"
108132
app:mediaType="video" />
109133

110134
</LinearLayout>
111135

136+
112137
<ScrollView
113138
android:layout_width="match_parent"
114139
android:layout_height="0dp"
115-
android:layout_weight="1">
140+
android:layout_weight="1"
141+
android:fillViewport="true">
116142

117143
<TextView
118144
android:id="@+id/messageBox"
119145
android:layout_width="match_parent"
120-
android:layout_height="wrap_content" />
146+
android:layout_height="wrap_content"
147+
android:background="@color/gray" />
121148

122149
</ScrollView>
123150

124-
125151
<LinearLayout
126152
android:layout_width="match_parent"
127153
android:layout_height="wrap_content"
@@ -132,32 +158,42 @@
132158
android:layout_width="0dp"
133159
android:layout_height="wrap_content"
134160
android:layout_weight="1"
161+
android:hint="Message"
135162
android:inputType="text" />
136163

137164
<Button
138165
android:id="@+id/sendMessageButton"
166+
style="@style/ButtonStyle"
139167
android:layout_width="wrap_content"
140168
android:layout_height="wrap_content"
141169
android:text="Send" />
142170

143171
<Button
144172
android:id="@+id/sendFileButton"
173+
style="@style/ButtonStyle"
145174
android:layout_width="wrap_content"
146175
android:layout_height="wrap_content"
147176
android:text="Send File" />
148177

149178

150179
</LinearLayout>
151180

181+
<TextView
182+
android:layout_width="wrap_content"
183+
android:layout_height="wrap_content"
184+
android:text="Incoming File:"
185+
android:textSize="17sp"
186+
android:textStyle="bold" />
187+
152188
<LinearLayout
153189
android:layout_width="match_parent"
154190
android:layout_height="wrap_content"
155191
android:orientation="horizontal">
156192

157193
<ImageView
158194
android:id="@+id/file_preview_bitmap"
159-
android:layout_width="100dp"
160-
android:layout_height="100dp" />
195+
android:layout_width="90dp"
196+
android:layout_height="90dp" />
161197

162198
<LinearLayout
163199
android:layout_width="match_parent"

app/src/main/res/values-night/themes.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
<color name="teal_700">#FF018786</color>
88
<color name="black">#FF000000</color>
99
<color name="white">#FFFFFFFF</color>
10+
<color name="gray">#C2C2C2</color>
1011
</resources>

app/src/main/res/values/themes.xml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
<style name="Theme.AndroidPeerRTC" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
44
<!-- Primary brand color. -->
55
<item name="colorPrimary">@color/purple_500</item>
6-
<item name="colorPrimaryVariant">@color/purple_700</item>
7-
<item name="colorOnPrimary">@color/white</item>
8-
<!-- Secondary brand color. -->
9-
<item name="colorSecondary">@color/teal_200</item>
10-
<item name="colorSecondaryVariant">@color/teal_700</item>
11-
<item name="colorOnSecondary">@color/black</item>
12-
<!-- Status bar color. -->
136
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
14-
<!-- Customize your theme here. -->
7+
8+
<item name="android:textColor">@color/black</item>
9+
<item name="android:editTextColor">@color/black</item>
10+
<item name="editTextStyle">@style/EditTextStyle</item>
1511
</style>
12+
13+
<style name="EditTextStyle" parent="Widget.AppCompat.EditText">
14+
<item name="backgroundTint">@color/black</item>
15+
<item name="android:textColorHint">@color/gray</item>
16+
</style>
17+
18+
19+
<style name="ButtonStyle" parent="Widget.AppCompat.Button">
20+
<item name="android:textColor">@color/white</item>
21+
</style>
22+
1623
</resources>

0 commit comments

Comments
 (0)