Commit 81ab871b authored by MozLando's avatar MozLando
Browse files

Merge #5288



5288: Add peer-to-peer communication r=jonalmeida a=espertus

Add feature-p2p


Co-authored-by: default avatarEllen Spertus <ellen.spertus@gmail.com>
parents ca13af07 4862cfb7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -64,6 +64,10 @@ projects:
    path: components/feature/media
    description: 'Feature component for website media related features.'
    publish: true
  feature-p2p:
    path: components/feature/p2p
    description: 'Feature used for peer-to-peer communication.'
    publish: true
  feature-webnotifications:
    path: components/feature/webnotifications
    description: 'Feature component for Web Notifications.'
+2 −0
Original line number Diff line number Diff line
@@ -134,6 +134,8 @@ _Combined components to implement feature-specific use cases._

* 🔴 [**Progressive Web Apps (PWA)**](components/feature/pwa/README.md) - A component that provides functionality for supporting Progressive Web Apps (PWA).

* 🔴 [**P2P**](components/feature/p2p/README.md) - A component that provides peer-to-peer communication.

* 🔴 [**Reader View**](components/feature/readerview/README.md) - A component that provides Reader View functionality.

*[**QR**](components/feature/qr/README.md) - A component that provides functionality for scanning QR codes.
+47 −0
Original line number Diff line number Diff line
# [Android Components](../../../README.md) > Feature > P2P

A feature that enables sharing of URLs and web pages through peer-to-peer wifi
connections. Because this does not inline external references to images and CSS,
the page on the recipient device will lack those features unless connected to the Internet.
It works best in conjunction with [`feature-readerview`](../readerview).

## Usage

### Setting up the dependency

Use Gradle to download the library from [maven.mozilla.org](https://maven.mozilla.org/) ([Setup repository](../../../README.md#maven-repository)):

```Groovy
implementation "org.mozilla.components:feature-p2p:{latest-version}"
```

### Sample usage

The P2P toolbar has been integrated into [`samples/browser`](../../../samples/browser). Key files are:

* [`BaseBrowserFragment`](../../../samples/browser/src/main/java/org/mozilla/samples/browser/BaseBrowserFragment.kt),
which instantiates `P2PIntegration` and supports permission granting.
* [`P2PIntegration`](../../../samples/browser/src/main/java/org/mozilla/samples/browser/integration/P2PIntegration.kt),
which instantiates `P2PFeature` and contains code to launch and close the toolbar.
* [`DefaultComponents`](../../../samples/browser/src/main/java/org/mozilla/samples/browser/DefaultComponents.kt), which lazily provides a 
[NearbyConnection](../../components/lib/nearby/src/main/java/mozilla/components/lib/nearby/NearbyConnection.kt) and adds the toolbar to the settings menu.
* [`fragment_browser.xml`](../../../samples/browser/src/main/res/layout/fragment_browser.xml), which includes the `P2PBar` widget.

## Structure

The structure of the feature is shown in this block diagram:

![block diagram](docs/feature-p2p-block-diagram.png)

## "Freeze-drying" a web page

An [experimental fork](https://github.com/espertus/android-components/tree/p2p-freeze-dry) uses the 
external library [`freeze-dry`](https://github.com/WebMemex/freeze-dry) to package up the entire 
web page. This version was not checked in to this repository because reviewing all of the JavaScript 
code was infeasible. Performance was also an issue.

## License

    This Source Code Form is subject to the terms of the Mozilla Public
    License, v. 2.0. If a copy of the MPL was not distributed with this
    file, You can obtain one at http://mozilla.org/MPL/2.0/
+53 −0
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion config.compileSdkVersion

    defaultConfig {
        minSdkVersion config.minSdkVersion
        targetSdkVersion config.targetSdkVersion
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions.freeCompilerArgs += [
            "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi"
    ]
}

dependencies {
    implementation project(':browser-session')
    implementation project(':browser-state')
    implementation project(':concept-engine')
    implementation project(':feature-tabs')
    implementation project(':lib-nearby')
    implementation project(':support-webextensions')
    implementation project(':support-ktx')
    implementation project(':ui-icons')

    implementation Dependencies.kotlin_stdlib
    implementation Dependencies.androidx_constraintlayout

    testImplementation Dependencies.androidx_test_core
    testImplementation Dependencies.androidx_test_junit
    testImplementation Dependencies.testing_coroutines
    testImplementation Dependencies.testing_robolectric
    testImplementation Dependencies.testing_mockito
    testImplementation project(':support-test')
}

apply from: '../../../publish.gradle'
ext.configurePublish(config.componentsGroupId, archivesBaseName, project.ext.description)
+18.6 KiB
Loading image diff...
Loading