Skip to content

Commit bab2bdc

Browse files
committed
new demo
1 parent bcc0597 commit bab2bdc

5 files changed

Lines changed: 96 additions & 19 deletions

File tree

AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<uses-feature android:name="android.hardware.camera" />
88
<uses-feature android:name="android.hardware.camera.autofocus" />
9-
<uses-sdk android:minSdkVersion="17"/>
9+
<uses-sdk android:minSdkVersion="9"/>
1010

1111
<uses-permission android:name="android.permission.CAMERA" />
1212
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

res/layout/main.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:orientation="vertical"
5+
android:layout_width="fill_parent"
6+
android:layout_height="fill_parent"
7+
android:keepScreenOn="true" >
8+
<EditText
9+
android:layout_width="fill_parent"
10+
android:layout_height="wrap_content"
11+
android:inputType="textNoSuggestions"
12+
android:id="@+id/name"
13+
android:text="@string/default_name" />
14+
<LinearLayout
15+
xmlns:android="http://schemas.android.com/apk/res/android"
16+
android:orientation="horizontal"
17+
android:layout_width="fill_parent"
18+
android:layout_height="wrap_content"
19+
android:keepScreenOn="true" >
20+
<CheckBox
21+
android:layout_width="fill_parent"
22+
android:layout_height="wrap_content"
23+
android:layout_weight="1"
24+
android:id="@+id/privacy"
25+
android:text="@string/privacy_setting" />
26+
<ToggleButton
27+
android:layout_width="fill_parent"
28+
android:layout_height="wrap_content"
29+
android:layout_weight="1"
30+
android:id="@+id/cameraFacing"
31+
android:textOff="back camera"
32+
android:textOn="front camera"/>
33+
</LinearLayout>
34+
<TextView
35+
android:layout_width="fill_parent"
36+
android:layout_height="wrap_content"
37+
android:id="@+id/link"
38+
android:text="@string/link" />
39+
<Button
40+
android:layout_width="fill_parent"
41+
android:layout_height="wrap_content"
42+
android:text="@string/stream"
43+
android:onClick="stream"/>
44+
</LinearLayout>

res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<string name="app_name">AndroidRTC</string>
4+
<string name="default_name">android_test</string>
5+
<string name="stream">Stream</string>
6+
<string name="privacy_setting">Private</string>
7+
<string name="link">link</string>
48
</resources>

src/fr/pchab/AndroidRTC/RTCActivity.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import android.content.Intent;
55
import android.graphics.Point;
66
import android.os.Bundle;
7+
import android.view.View;
78
import android.view.Window;
8-
import android.widget.Toast;
9+
import android.widget.*;
910
import org.appspot.apprtc.VideoStreamsView;
1011
import org.webrtc.MediaStream;
1112
import org.webrtc.PeerConnectionFactory;
@@ -15,37 +16,60 @@ public class RTCActivity extends Activity implements RTCClient.RTCListener{
1516
private static final String HOST = "http://54.214.218.3:3000/";
1617
private VideoStreamsView vsv;
1718
private RTCClient client;
19+
private EditText nameView;
20+
private CheckBox privacySetting;
21+
private TextView linkView;
22+
private ToggleButton cameraFacingView;
1823

1924
@Override
2025
public void onCreate(Bundle savedInstanceState) {
2126
super.onCreate(savedInstanceState);
2227
requestWindowFeature(Window.FEATURE_NO_TITLE);
28+
setContentView(R.layout.main);
29+
30+
nameView = (EditText) findViewById(R.id.name);
31+
privacySetting = (CheckBox) findViewById(R.id.privacy);
32+
linkView = (TextView) findViewById(R.id.link);
33+
cameraFacingView = (ToggleButton) findViewById(R.id.cameraFacing);
34+
35+
PeerConnectionFactory.initializeAndroidGlobals(this);
2336

2437
// Camera display view
2538
Point displaySize = new Point();
2639
getWindowManager().getDefaultDisplay().getSize(displaySize);
2740
vsv = new VideoStreamsView(this, displaySize);
28-
setContentView(vsv);
29-
30-
PeerConnectionFactory.initializeAndroidGlobals(this);
3141

3242
client = new RTCClient(this, HOST);
43+
}
44+
45+
// button action
46+
public void stream(View view) {
47+
setContentView(vsv);
3348

3449
// Settings
35-
client.setName("android_test");
36-
client.setCamera("back", "320", "240");
50+
client.setName(String.valueOf(nameView.getText()));
51+
client.setPrivacy(privacySetting.isChecked());
52+
String cameraFacing = cameraFacingView.isChecked() ? "front" : "back";
53+
client.setCamera(cameraFacing, "320", "240");
3754

3855
client.start();
39-
}
4056

41-
@Override
42-
public void onCallReady(String callId) {
4357
Intent msg = new Intent(Intent.ACTION_SEND);
44-
msg.putExtra(Intent.EXTRA_TEXT, HOST + callId);
58+
msg.putExtra(Intent.EXTRA_TEXT, linkView.getText());
4559
msg.setType("text/plain");
4660
startActivity(Intent.createChooser(msg, "Call someone :"));
4761
}
4862

63+
@Override
64+
public void onCallReady(final String callId) {
65+
runOnUiThread(new Runnable() {
66+
@Override
67+
public void run() {
68+
linkView.setText(HOST + callId);
69+
}
70+
});
71+
}
72+
4973
@Override
5074
public void onStatusChanged(final String newStatus) {
5175
runOnUiThread(new Runnable() {

src/fr/pchab/AndroidRTC/RTCClient.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
public class RTCClient {
1414
private String name;
15-
private String callId;
15+
private boolean privacy;
1616
private PeerConnectionFactory factory;
1717
private HashMap<String, Peer> peers = new HashMap<String, Peer>();
1818
private LinkedList<PeerConnection.IceServer> iceServers = new LinkedList<PeerConnection.IceServer>();
@@ -192,11 +192,14 @@ public void onConnect() {
192192
}
193193

194194
@Override
195-
public void on(final String event, final JSONArray arguments) {
195+
public void on(String event, JSONArray arguments) {
196196
try {
197-
if(event.equals("id")) callId = arguments.getString(0);
198-
JSONObject json = arguments.getJSONObject(0);
199-
messageHandler.handle(json);
197+
if(event.equals("id")) {
198+
mListener.onCallReady(arguments.getString(0));
199+
} else {
200+
JSONObject json = arguments.getJSONObject(0);
201+
messageHandler.handle(json);
202+
}
200203
} catch (JSONException e) {
201204
e.printStackTrace();
202205
}
@@ -235,6 +238,10 @@ public void setName(String name){
235238
this.name = name;
236239
}
237240

241+
public void setPrivacy(boolean privacy){
242+
this.privacy = privacy;
243+
}
244+
238245
public void setCamera(String cameraFacing, String height, String width){
239246
this.cameraFacing = cameraFacing;
240247
MediaConstraints videoConstraints = new MediaConstraints();
@@ -252,13 +259,11 @@ public void start(){
252259
try {
253260
JSONObject message = new JSONObject();
254261
message.put("name", name);
255-
message.put("privacy", false);
262+
message.put("privacy", privacy);
256263
client.emit("readyToStream", new JSONArray().put(message));
257264
} catch (JSONException e) {
258265
e.printStackTrace();
259266
}
260-
261-
mListener.onCallReady(callId);
262267
}
263268

264269
/*

0 commit comments

Comments
 (0)