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
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ dependencies {
implementation 'androidx.core:core:1.6.0'
implementation 'org.java-websocket:Java-WebSocket:1.5.4'
implementation 'com.google.zxing:core:3.3.3'
implementation('com.journeyapps:zxing-android-embedded:3.6.0') {
exclude group: 'com.android.support'
}

testImplementation 'junit:junit:4.13.2'
}
24 changes: 23 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
<uses-permission android:name="android.permission.CAMERA" />

<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:name="android.software.leanback"
android:required="false" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />

<application
android:allowBackup="true"
Expand All @@ -20,7 +29,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.LibreCast">
<activity
android:name=".MainActivity"
android:name=".HomeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -29,9 +38,22 @@
</intent-filter>
</activity>

<activity
android:name=".MainActivity"
android:exported="false" />

<activity
android:name=".SenderActivity"
android:exported="false" />

<service
android:name=".ReceiverService"
android:exported="false" />

<service
android:name=".ScreenCaptureService"
android:exported="false"
android:foregroundServiceType="mediaProjection" />
</application>

</manifest>
35 changes: 35 additions & 0 deletions app/src/main/java/com/m5dev/librecast/HomeActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.m5dev.librecast;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

public class HomeActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);

Button btnReceive = findViewById(R.id.btn_receive);
Button btnSend = findViewById(R.id.btn_send);

btnReceive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(HomeActivity.this, MainActivity.class);
startActivity(intent);
}
});

btnSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(HomeActivity.this, SenderActivity.class);
startActivity(intent);
}
});
}
}
96 changes: 96 additions & 0 deletions app/src/main/java/com/m5dev/librecast/LibreCastClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.m5dev.librecast;

import android.util.Log;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;

import java.net.URI;

public class LibreCastClient extends WebSocketClient {

private static final String TAG = "LibreCastClient";

public interface ClientListener {
void onConnected();
void onDisconnected();
void onError(Exception ex);
}

private ClientListener listener;

public LibreCastClient(URI serverUri) {
super(serverUri);
}

public LibreCastClient(URI serverUri, ClientListener listener) {
super(serverUri);
this.listener = listener;
}

public void setListener(ClientListener listener) {
this.listener = listener;
}

@Override
public void onOpen(ServerHandshake handshakedata) {
logI(TAG, "WebSocket connected to " + getURI());
if (listener != null) {
listener.onConnected();
}
}

@Override
public void onMessage(String message) {
logD(TAG, "Received message: " + message);
}

@Override
public void onClose(int code, String reason, boolean remote) {
logI(TAG, "WebSocket closed: " + reason + " (code: " + code + ")");
if (listener != null) {
listener.onDisconnected();
}
}

@Override
public void onError(Exception ex) {
logE(TAG, "WebSocket error", ex);
if (listener != null) {
listener.onError(ex);
}
}

public void sendFrame(byte[] data) {
if (isOpen() && data != null && data.length > 0) {
try {
send(data);
} catch (Exception e) {
logE(TAG, "Error sending frame over WebSocket", e);
}
}
}

private static void logI(String tag, String msg) {
try {
Log.i(tag, msg);
} catch (Throwable t) {
System.out.println("[" + tag + "] " + msg);
}
}

private static void logD(String tag, String msg) {
try {
Log.d(tag, msg);
} catch (Throwable t) {
System.out.println("[" + tag + "] " + msg);
}
}

private static void logE(String tag, String msg, Throwable t) {
try {
Log.e(tag, msg, t);
} catch (Throwable ignored) {
System.err.println("[" + tag + "] " + msg);
}
}
}
Loading
Loading