Skip to content

Commit 12251fa

Browse files
committed
Init
0 parents  commit 12251fa

File tree

6 files changed

+5631
-0
lines changed

6 files changed

+5631
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
peerjs/
2+
dist/
3+
node_modules/
4+

build.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
exec 2>&1
4+
5+
git clone https://github.com/peers/peerjs peerjs
6+
cd peerjs
7+
git apply ../decoupling.diff
8+
../node_modules/.bin/parcel build --no-source-maps lib/exports.ts -d ../dist --out-file peerjs.min.js
9+
cd ../
10+
cat imports.js dist/peerjs.min.js > dist/react-native-peerjs.js
11+
rm dist/peerjs.min.js
12+
13+
echo "Done. dist/react-native-peerjs.js"
14+

decoupling.diff

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
diff --git a/lib/dataconnection.ts b/lib/dataconnection.ts
2+
index ab58d6c..dfbf3b2 100644
3+
--- a/lib/dataconnection.ts
4+
+++ b/lib/dataconnection.ts
5+
@@ -56,7 +56,7 @@ export class DataConnection extends BaseConnection {
6+
this.options.connectionId || DataConnection.ID_PREFIX + util.randomToken();
7+
8+
this.label = this.options.label || this.connectionId;
9+
- this.serialization = this.options.serialization || SerializationType.Binary;
10+
+ this.serialization = this.options.serialization || SerializationType.JSON;
11+
this.reliable = !!this.options.reliable;
12+
13+
if (this.options._payload) {
14+
diff --git a/lib/exports.ts b/lib/exports.ts
15+
index 5772d02..07fc457 100644
16+
--- a/lib/exports.ts
17+
+++ b/lib/exports.ts
18+
@@ -8,6 +8,3 @@ export const peerjs = {
19+
20+
export default Peer;
21+
22+
-(<any>window).peerjs = peerjs;
23+
-/** @deprecated Should use peerjs namespace */
24+
-(<any>window).Peer = Peer;
25+
diff --git a/lib/peer.ts b/lib/peer.ts
26+
index 66a3412..78ac6cf 100644
27+
--- a/lib/peer.ts
28+
+++ b/lib/peer.ts
29+
@@ -111,11 +111,6 @@ export class Peer extends EventEmitter {
30+
};
31+
this._options = options;
32+
33+
- // Detect relative URL host.
34+
- if (this._options.host === "/") {
35+
- this._options.host = window.location.hostname;
36+
- }
37+
-
38+
// Set path correctly.
39+
if (this._options.path) {
40+
if (this._options.path[0] !== "/") {
41+
diff --git a/lib/supports.ts b/lib/supports.ts
42+
index 1801188..8bb163e 100644
43+
--- a/lib/supports.ts
44+
+++ b/lib/supports.ts
45+
@@ -1,5 +1,3 @@
46+
-import { webRTCAdapter } from './adapter';
47+
-
48+
export const Supports = new class {
49+
readonly isIOS = ['iPad', 'iPhone', 'iPod'].includes(navigator.platform);
50+
readonly supportedBrowsers = ['firefox', 'chrome', 'safari'];
51+
@@ -28,36 +26,15 @@ export const Supports = new class {
52+
}
53+
54+
getBrowser(): string {
55+
- return webRTCAdapter.browserDetails.browser;
56+
+ return 'chrome';
57+
}
58+
59+
getVersion(): number {
60+
- return webRTCAdapter.browserDetails.version || 0;
61+
+ return this.minChromeVersion;
62+
}
63+
64+
isUnifiedPlanSupported(): boolean {
65+
- const browser = this.getBrowser();
66+
- const version = webRTCAdapter.browserDetails.version || 0;
67+
-
68+
- if (browser === 'chrome' && version < 72) return false;
69+
- if (browser === 'firefox' && version >= 59) return true;
70+
- if (!window.RTCRtpTransceiver || !('currentDirection' in RTCRtpTransceiver.prototype)) return false;
71+
-
72+
- let tempPc: RTCPeerConnection;
73+
- let supported = false;
74+
-
75+
- try {
76+
- tempPc = new RTCPeerConnection();
77+
- tempPc.addTransceiver('audio');
78+
- supported = true;
79+
- } catch (e) { }
80+
- finally {
81+
- if (tempPc) {
82+
- tempPc.close();
83+
- }
84+
- }
85+
-
86+
- return supported;
87+
+ return false;
88+
}
89+
90+
toString(): string {

imports.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {
2+
RTCPeerConnection,
3+
RTCIceCandidate,
4+
RTCSessionDescription,
5+
} from 'react-native-webrtc';
6+

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "react-native-peerjs",
3+
"version": "1.0.0",
4+
"description": "react-native-webrtc + peerjs",
5+
"repository": "https://github.com/Zemke/react-native-peerjs",
6+
"author": "Zemke <florian@zemke.io>",
7+
"license": "MIT",
8+
"scripts": {
9+
"build": "./build.sh",
10+
"prepare": "./build.sh"
11+
},
12+
"main": "dist/react-native-peerjs.js",
13+
"devDependencies": {
14+
"parcel": "^1.12.3",
15+
"peerjs": "1.1.0"
16+
}
17+
}

0 commit comments

Comments
 (0)