Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
Expand Down
44 changes: 44 additions & 0 deletions res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:keepScreenOn="true" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:id="@+id/name"
android:text="@string/default_name" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:keepScreenOn="true" >
<CheckBox
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/privacy"
android:text="@string/privacy_setting" />
<ToggleButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/cameraFacing"
android:textOff="back camera"
android:textOn="front camera"/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/link"
android:text="@string/link" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/stream"
android:onClick="stream"/>
</LinearLayout>
4 changes: 4 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AndroidRTC</string>
<string name="default_name">android_test</string>
<string name="stream">Stream</string>
<string name="privacy_setting">Private</string>
<string name="link">link</string>
</resources>
48 changes: 37 additions & 11 deletions src/fr/pchab/AndroidRTC/RTCActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Toast;
import android.widget.*;
import org.appspot.apprtc.VideoStreamsView;
import org.webrtc.MediaStream;
import org.webrtc.PeerConnectionFactory;
Expand All @@ -14,42 +15,67 @@
public class RTCActivity extends Activity implements RTCClient.RTCListener{
private static final String HOST = "http://54.214.218.3:3000/";
private VideoStreamsView vsv;
private RTCClient client;
private EditText nameView;
private CheckBox privacySetting;
private TextView linkView;
private ToggleButton cameraFacingView;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

nameView = (EditText) findViewById(R.id.name);
privacySetting = (CheckBox) findViewById(R.id.privacy);
linkView = (TextView) findViewById(R.id.link);
cameraFacingView = (ToggleButton) findViewById(R.id.cameraFacing);

PeerConnectionFactory.initializeAndroidGlobals(this);

// Camera display view
Point displaySize = new Point();
getWindowManager().getDefaultDisplay().getSize(displaySize);
vsv = new VideoStreamsView(this, displaySize);
setContentView(vsv);

PeerConnectionFactory.initializeAndroidGlobals(this);
client = new RTCClient(this, HOST);
}

RTCClient client = new RTCClient(this, HOST);
// button action
public void stream(View view) {
setContentView(vsv);

// Settings
client.setName("android_test");
client.setCamera("back", "320", "240");
client.setName(String.valueOf(nameView.getText()));
client.setPrivacy(privacySetting.isChecked());
String cameraFacing = cameraFacingView.isChecked() ? "front" : "back";
client.setCamera(cameraFacing, "320", "240");

client.start();
}

@Override
public void onCallReady(String callId) {
Intent msg = new Intent(Intent.ACTION_SEND);
msg.putExtra(Intent.EXTRA_TEXT, HOST + callId);
msg.putExtra(Intent.EXTRA_TEXT, linkView.getText());
msg.setType("text/plain");
startActivity(Intent.createChooser(msg, "Call someone :"));
}

@Override
public void onCallReady(final String callId) {
runOnUiThread(new Runnable() {
@Override
public void run() {
linkView.setText(HOST + callId);
}
});
}

@Override
public void onStatusChanged(final String newStatus) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), newStatus, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), newStatus, Toast.LENGTH_SHORT).show();
}
});
}
Expand Down
42 changes: 28 additions & 14 deletions src/fr/pchab/AndroidRTC/RTCClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class RTCClient {
private String name;
private String callId;
private boolean privacy;
private PeerConnectionFactory factory;
private HashMap<String, Peer> peers = new HashMap<String, Peer>();
private LinkedList<PeerConnection.IceServer> iceServers = new LinkedList<PeerConnection.IceServer>();
Expand All @@ -39,6 +39,13 @@ private interface Command{
void execute(String peerId, JSONObject payload) throws JSONException;
}

private class CreateOfferCommand implements Command{
public void execute(String peerId, JSONObject payload) throws JSONException {
Peer peer = peers.get(peerId);
peer.pc.createOffer(peer, pcConstraints);
}
}

private class SetRemoteSDPCommand implements Command{
public void execute(String peerId, JSONObject payload) throws JSONException {
Peer peer = peers.get(peerId);
Expand Down Expand Up @@ -77,6 +84,7 @@ private class MessageHandler {

public MessageHandler() {
this.commandMap = new HashMap<String, Command>();
commandMap.put("init", new CreateOfferCommand());
commandMap.put("offer", new SetRemoteSDPCommand());
commandMap.put("answer", new SetRemoteSDPCommand());
commandMap.put("candidate", new AddIceCandidateCommand());
Expand All @@ -85,7 +93,10 @@ public MessageHandler() {
public void handle(JSONObject json) throws JSONException {
String from = json.getString("from");
String type = json.getString("type");
JSONObject payload = json.getJSONObject("payload");
JSONObject payload = null;
if(!type.equals("init")) {
payload = json.getJSONObject("payload");
}

// if peer is unknown, add him
if(!peers.containsKey(from)) {
Expand All @@ -106,7 +117,7 @@ public void onCreateSuccess(final SessionDescription sdp) {
JSONObject payload = new JSONObject();
payload.put("type", sdp.type.canonicalForm());
payload.put("sdp", sdp.description);
sendMessage(id, "answer", payload);
sendMessage(id, sdp.type.canonicalForm(), payload);
pc.setLocalDescription(Peer.this, sdp);
} catch (JSONException e) {
e.printStackTrace();
Expand All @@ -115,7 +126,6 @@ public void onCreateSuccess(final SessionDescription sdp) {

@Override
public void onSetSuccess() {
pc.createAnswer(Peer.this, pcConstraints);
}

@Override
Expand Down Expand Up @@ -182,11 +192,14 @@ public void onConnect() {
}

@Override
public void on(final String event, final JSONArray arguments) {
public void on(String event, JSONArray arguments) {
try {
if(event.equals("id")) callId = arguments.getString(0);
JSONObject json = arguments.getJSONObject(0);
messageHandler.handle(json);
if(event.equals("id")) {
mListener.onCallReady(arguments.getString(0));
} else {
JSONObject json = arguments.getJSONObject(0);
messageHandler.handle(json);
}
} catch (JSONException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -225,6 +238,10 @@ public void setName(String name){
this.name = name;
}

public void setPrivacy(boolean privacy){
this.privacy = privacy;
}

public void setCamera(String cameraFacing, String height, String width){
this.cameraFacing = cameraFacing;
MediaConstraints videoConstraints = new MediaConstraints();
Expand All @@ -236,21 +253,17 @@ public void setCamera(String cameraFacing, String height, String width){
VideoTrack videoTrack = factory.createVideoTrack("ARDAMSv0", videoSource);
lMS.addTrack(videoTrack);
lMS.addTrack(factory.createAudioTrack("ARDAMSa0"));

mListener.onLocalStream(lMS);
}

public void start(){
JSONObject message = new JSONObject();
try {
JSONObject message = new JSONObject();
message.put("name", name);
message.put("privacy", true);
message.put("privacy", privacy);
client.emit("readyToStream", new JSONArray().put(message));
} catch (JSONException e) {
e.printStackTrace();
}

mListener.onCallReady(callId);
}

/*
Expand All @@ -276,6 +289,7 @@ private VideoCapturer getVideoCapturer() {
private void addPeer(String id) {
Peer peer = new Peer(id);
peer.pc.addStream(lMS, new MediaConstraints());
mListener.onLocalStream(lMS);
peers.put(id, peer);
}

Expand Down