Sfoglia il codice sorgente

feat: upgrade to Parcel@2

- smaller bundle
- better source maps
- improved bundler compatibility

Closes #845, #859, #552, #585

.
Jonas Gloning 3 anni fa
parent
commit
aae9d1fa37
16 ha cambiato i file con 3807 aggiunte e 3087 eliminazioni
  1. 1 1
      .github/workflows/prettier.yml
  2. 3 2
      .gitignore
  3. 1 1
      README.md
  4. 0 218
      index.d.ts
  5. 0 3
      lib/adapter.ts
  6. 1 1
      lib/dataconnection.ts
  7. 3 8
      lib/exports.ts
  8. 9 0
      lib/global.ts
  9. 1 1
      lib/mediaconnection.ts
  10. 21 0
      lib/optionInterfaces.ts
  11. 1 1
      lib/peer.ts
  12. 1 1
      lib/supports.ts
  13. 12 3
      lib/util.ts
  14. 3623 2819
      package-lock.json
  15. 127 27
      package.json
  16. 3 1
      tsconfig.json

+ 1 - 1
.github/workflows/prettier.yml

@@ -20,4 +20,4 @@ jobs:
             ${{ runner.os }}-npm-
       - name: Run prettier
         run: |-
-          npx prettier --check .
+          npx prettier --check .

+ 3 - 2
.gitignore

@@ -14,11 +14,12 @@ results
 demo
 bower.json
 node_modules
-.cache
+.parcel-cache
 .idea
 npm-debug.log
+.DS_STORE
 
 test/output
 .tscache
 test/public
-.vscode/
+.vscode/

+ 1 - 1
README.md

@@ -23,7 +23,7 @@ with yarn:
 
 ```js
 // The usage -
-import Peer from "peerjs";
+import { Peer } from "peerjs";
 ```
 
 **Create a Peer**

+ 0 - 218
index.d.ts

@@ -1,218 +0,0 @@
-// Type definitions for the PeerJS class module
-// Original definitions by Toshiya Nakakura <https://github.com/nakakura>
-// at https://github.com/DefinitelyTyped/DefinitelyTyped
-
-export = Peer;
-
-declare class Peer {
-	prototype: RTCIceServer;
-
-	/**
-	 * A peer can connect to other peers and listen for connections.
-	 * @param id Other peers can connect to this peer using the provided ID.
-	 *     If no ID is given, one will be generated by the brokering server.
-	 * @param options for specifying details about PeerServer
-	 */
-	constructor(id?: string, options?: Peer.PeerJSOption);
-
-	/**
-	 * A peer can connect to other peers and listen for connections.
-	 * @param options for specifying details about PeerServer
-	 */
-	constructor(options: Peer.PeerJSOption);
-
-	/**
-	 * Connects to the remote peer specified by id and returns a data connection.
-	 * @param id The brokering ID of the remote peer (their peer.id).
-	 * @param options for specifying details about Peer Connection
-	 */
-	connect(id: string, options?: Peer.PeerConnectOption): Peer.DataConnection;
-	/**
-	 * Calls the remote peer specified by id and returns a media connection.
-	 * @param id The brokering ID of the remote peer (their peer.id).
-	 * @param stream The caller's media stream
-	 * @param options Metadata associated with the connection, passed in by whoever initiated the connection.
-	 */
-	call(
-		id: string,
-		stream: MediaStream,
-		options?: Peer.CallOption,
-	): Peer.MediaConnection;
-	/**
-	 * Set listeners for peer events.
-	 * @param event Event name
-	 * @param cb Callback Function
-	 */
-	on(event: string, cb: () => void): void;
-	/**
-	 * Emitted when a connection to the PeerServer is established.
-	 * @param event Event name
-	 * @param cb id is the brokering ID of the peer
-	 */
-	on(event: "open", cb: (id: string) => void): void;
-	/**
-	 * Emitted when a new data connection is established from a remote peer.
-	 * @param event Event name
-	 * @param cb Callback Function
-	 */
-	on(
-		event: "connection",
-		cb: (dataConnection: Peer.DataConnection) => void,
-	): void;
-	/**
-	 * Emitted when a remote peer attempts to call you.
-	 * @param event Event name
-	 * @param cb Callback Function
-	 */
-	on(event: "call", cb: (mediaConnection: Peer.MediaConnection) => void): void;
-	/**
-	 * Emitted when the peer is destroyed and can no longer accept or create any new connections.
-	 * @param event Event name
-	 * @param cb Callback Function
-	 */
-	on(event: "close", cb: () => void): void;
-	/**
-	 * Emitted when the peer is disconnected from the signalling server
-	 * @param event Event name
-	 * @param cb Callback Function
-	 */
-	on(event: "disconnected", cb: () => void): void;
-	/**
-	 * Errors on the peer are almost always fatal and will destroy the peer.
-	 * @param event Event name
-	 * @param cb Callback Function
-	 */
-	on(event: "error", cb: (err: any) => void): void;
-	/**
-	 * Remove event listeners.(EventEmitter3)
-	 * @param {String} event The event we want to remove.
-	 * @param {Function} fn The listener that we need to find.
-	 * @param {Boolean} once Only remove once listeners.
-	 */
-	off(event: string, fn: Function, once?: boolean): void;
-	/**
-	 * Close the connection to the server, leaving all existing data and media connections intact.
-	 */
-	disconnect(): void;
-	/**
-	 * Attempt to reconnect to the server with the peer's old ID
-	 */
-	reconnect(): void;
-	/**
-	 * Close the connection to the server and terminate all existing connections.
-	 */
-	destroy(): void;
-
-	/**
-	 * Retrieve a data/media connection for this peer.
-	 * @param peerId
-	 * @param connectionId
-	 */
-	getConnection(
-		peerId: string,
-		connectionId: string,
-	): Peer.MediaConnection | Peer.DataConnection | null;
-
-	/**
-	 * Get a list of available peer IDs
-	 * @param callback
-	 */
-	listAllPeers(callback: (peerIds: Array<string>) => void): void;
-	/**
-	 * The brokering ID of this peer
-	 */
-	id: string;
-	/**
-	 * A hash of all connections associated with this peer, keyed by the remote peer's ID.
-	 */
-	connections: any;
-	/**
-	 * false if there is an active connection to the PeerServer.
-	 */
-	disconnected: boolean;
-	/**
-	 * true if this peer and all of its connections can no longer be used.
-	 */
-	destroyed: boolean;
-}
-
-declare namespace Peer {
-	interface PeerJSOption {
-		key?: string;
-		host?: string;
-		port?: number;
-		path?: string;
-		secure?: boolean;
-		token?: string;
-		config?: RTCConfiguration;
-		debug?: number;
-	}
-
-	interface PeerConnectOption {
-		label?: string;
-		metadata?: any;
-		serialization?: string;
-		reliable?: boolean;
-	}
-
-	interface CallOption {
-		metadata?: any;
-		sdpTransform?: Function;
-	}
-
-	interface AnswerOption {
-		sdpTransform?: Function;
-	}
-
-	interface DataConnection {
-		send(data: any): void;
-		close(): void;
-		on(event: string, cb: () => void): void;
-		on(event: "data", cb: (data: any) => void): void;
-		on(event: "open", cb: () => void): void;
-		on(event: "close", cb: () => void): void;
-		on(event: "error", cb: (err: any) => void): void;
-		off(event: string, fn: Function, once?: boolean): void;
-		dataChannel: RTCDataChannel;
-		label: string;
-		metadata: any;
-		open: boolean;
-		peerConnection: RTCPeerConnection;
-		peer: string;
-		reliable: boolean;
-		serialization: string;
-		type: string;
-		bufferSize: number;
-		stringify: (data: any) => string;
-		parse: (data: string) => any;
-	}
-
-	interface MediaConnection {
-		answer(stream?: MediaStream, options?: AnswerOption): void;
-		close(): void;
-		on(event: string, cb: () => void): void;
-		on(event: "stream", cb: (stream: MediaStream) => void): void;
-		on(event: "close", cb: () => void): void;
-		on(event: "error", cb: (err: any) => void): void;
-		off(event: string, fn: Function, once?: boolean): void;
-		open: boolean;
-		metadata: any;
-		peerConnection: RTCPeerConnection;
-		peer: string;
-		type: string;
-	}
-
-	interface UtilSupportsObj {
-		browser: boolean;
-		webRTC: boolean;
-		audioVideo: boolean;
-		data: boolean;
-		binaryBlob: boolean;
-		reliable: boolean;
-	}
-
-	interface util {
-		browser: string;
-		supports: UtilSupportsObj;
-	}
-}

+ 0 - 3
lib/adapter.ts

@@ -1,3 +0,0 @@
-import webRTCAdapter from "webrtc-adapter";
-
-export { webRTCAdapter };

+ 1 - 1
lib/dataconnection.ts

@@ -11,7 +11,7 @@ import { Peer } from "./peer";
 import { BaseConnection } from "./baseconnection";
 import { ServerMessage } from "./servermessage";
 import { EncodingQueue } from "./encodingQueue";
-import { DataConnection as IDataConnection } from "../index";
+import type { DataConnection as IDataConnection } from "./dataconnection";
 
 /**
  * Wraps a DataChannel between two Peers.

+ 3 - 8
lib/exports.ts

@@ -1,13 +1,8 @@
 import { util } from "./util";
 import { Peer } from "./peer";
 
-export const peerjs = {
-	Peer,
-	util,
-};
+export type { DataConnection } from "./dataconnection";
+export type { MediaConnection } from "./mediaconnection";
 
+export { Peer, util };
 export default Peer;
-
-(<any>window).peerjs = peerjs;
-/** @deprecated Should use peerjs namespace */
-(<any>window).Peer = Peer;

+ 9 - 0
lib/global.ts

@@ -0,0 +1,9 @@
+import { util } from "./util";
+import { Peer } from "./peer";
+
+(<any>window).peerjs = {
+	Peer,
+	util,
+};
+/** @deprecated Should use peerjs namespace */
+(<any>window).Peer = Peer;

+ 1 - 1
lib/mediaconnection.ts

@@ -9,7 +9,7 @@ import {
 import { Peer } from "./peer";
 import { BaseConnection } from "./baseconnection";
 import { ServerMessage } from "./servermessage";
-import { AnswerOption } from "..";
+import type { AnswerOption } from "./optionInterfaces";
 
 /**
  * Wraps the streaming interface between two Peers.

+ 21 - 0
lib/optionInterfaces.ts

@@ -0,0 +1,21 @@
+export interface AnswerOption {
+	sdpTransform?: Function;
+}
+
+export interface PeerJSOption {
+	key?: string;
+	host?: string;
+	port?: number;
+	path?: string;
+	secure?: boolean;
+	token?: string;
+	config?: RTCConfiguration;
+	debug?: number;
+}
+
+export interface PeerConnectOption {
+	label?: string;
+	metadata?: any;
+	serialization?: string;
+	reliable?: boolean;
+}

+ 1 - 1
lib/peer.ts

@@ -14,7 +14,7 @@ import {
 import { BaseConnection } from "./baseconnection";
 import { ServerMessage } from "./servermessage";
 import { API } from "./api";
-import { PeerConnectOption, PeerJSOption } from "..";
+import type { PeerConnectOption, PeerJSOption } from "./optionInterfaces";
 
 class PeerOptions implements PeerJSOption {
 	debug?: LogLevel; // 1: Errors, 2: Warnings, 3: All logs

+ 1 - 1
lib/supports.ts

@@ -1,4 +1,4 @@
-import { webRTCAdapter } from "./adapter";
+import webRTCAdapter from "webrtc-adapter";
 
 export const Supports = new (class {
 	readonly isIOS = ["iPad", "iPhone", "iPod"].includes(navigator.platform);

+ 12 - 3
lib/util.ts

@@ -1,6 +1,14 @@
 import * as BinaryPack from "peerjs-js-binarypack";
 import { Supports } from "./supports";
-import { UtilSupportsObj } from "..";
+
+interface UtilSupportsObj {
+	browser: boolean;
+	webRTC: boolean;
+	audioVideo: boolean;
+	data: boolean;
+	binaryBlob: boolean;
+	reliable: boolean;
+}
 
 const DEFAULT_CONFIG = {
 	iceServers: [
@@ -14,7 +22,7 @@ const DEFAULT_CONFIG = {
 	sdpSemantics: "unified-plan",
 };
 
-export const util = new (class {
+class Util {
 	noop(): void {}
 
 	readonly CLOUD_HOST = "0.peerjs.com";
@@ -157,4 +165,5 @@ export const util = new (class {
 	isSecure(): boolean {
 		return location.protocol === "https:";
 	}
-})();
+}
+export const util = new Util();

File diff suppressed because it is too large
+ 3623 - 2819
package-lock.json


+ 127 - 27
package.json

@@ -1,65 +1,165 @@
 {
 	"name": "peerjs",
-	"version": "1.3.2",
-	"description": "PeerJS client",
-	"main": "./dist/peerjs.min.js",
-	"homepage": "https://github.com/peers/peerjs#readme",
+	"version": "1.4.0-rc.0",
 	"keywords": [
 		"peerjs",
 		"webrtc",
 		"p2p",
 		"rtc"
 	],
+	"description": "PeerJS client",
+	"homepage": "https://peerjs.com",
+	"bugs": {
+		"url": "https://github.com/peers/peerjs/issues"
+	},
 	"repository": {
 		"type": "git",
-		"url": "git+https://github.com/peers/peerjs.git"
+		"url": "https://github.com/peers/peerjs"
 	},
-	"bugs": {
-		"url": "https://github.com/peers/peerjs/issues"
+	"license": "MIT",
+	"contributors": [
+		"Michelle Bu <michelle@michellebu.com>",
+		"afrokick <devbyru@gmail.com>",
+		"ericz <really.ez@gmail.com>",
+		"Jairo <kidandcat@gmail.com>",
+		"Jairo Caro-Accino Viciana <jairo@galax.be>",
+		"Carlos Caballero <carlos.caballero.gonzalez@gmail.com>",
+		"hc <hheennrryy@gmail.com>",
+		"Muhammad Asif <capripio@gmail.com>",
+		"PrashoonB <prashoonbhattacharjee@gmail.com>",
+		"Moritz Stückler <moritz.stueckler@gmail.com>",
+		"Harsh Bardhan Mishra <47351025+HarshCasper@users.noreply.github.com>",
+		"akotynski <aleksanderkotbury@gmail.com>",
+		"Jairooo <jairocaro@msn.com>",
+		"lmb <i@lmb.io>",
+		"Jonas Gloning <34194370+jonasgloning@users.noreply.github.com>",
+		"Simon <crydotsnakegithub@gmail.com>",
+		"Philipp Hancke <fippo@andyet.net>",
+		"Matthias Lohr <matthias@lohr.me>",
+		"Jess <jessachandler@gmail.com>",
+		"khankuan <khankuan@gmail.com>",
+		"Denis Lukov <denismassters@gmail.com>",
+		"Hans Oksendahl <hansoksendahl@gmail.com>",
+		"XiZhao <kwang1imsa@gmail.com>",
+		"DUODVK <kurmanov.work@gmail.com>",
+		"Sören Balko <Soeren.Balko@gmail.com>",
+		"Steve Blaurock <sblaurock@gmail.com>",
+		"Yemel Jardi <angel.jardi@gmail.com>",
+		"Yuki Ito <yuki@gnnk.net>",
+		"alxnull <alxnull@e.mail.de>",
+		"bob.barstead@exaptive.com <bob.barstead@exaptive.com>",
+		"chandika <chandika@gmail.com>",
+		"eddieherm <edhermoso@gmail.com>",
+		"emersion <contact@emersion.fr>",
+		"fresheneesz <bitetrudpublic@gmail.com>",
+		"jasonbarry <jasbarry@me.com>",
+		"jonnyf <github@jonathanfoss.co.uk>",
+		"=frank tree <=frnktrb@googlemail.com>",
+		"xizhao <kevin.wang@cloudera.com>",
+		"Alberto Torres <kungfoobar@gmail.com>",
+		"Alex Chuev <alex@chuev.com>",
+		"Andre Eckardt <aeckardt@outlook.com>",
+		"Arpit Solanki <solankiarpit1997@gmail.com>",
+		"Artur Zayats <zag2art@gmail.com>",
+		"Ben Parnell <benjaminparnell.94@gmail.com>",
+		"Benny Lichtner <bennlich@gmail.com>",
+		"Chris Cowan <agentme49@gmail.com>",
+		"Christopher Van <cvan@users.noreply.github.com>",
+		"Diwank Singh Tomer <singh@diwank.name>",
+		"Eduardo Pinho <enet4mikeenet@gmail.com>",
+		"Evandro Zanatta <ezanatta@tray.net.br>",
+		"Gardner Bickford <gardner@users.noreply.github.com>",
+		"Gian Luca <gianluca.cecchi@cynny.com>",
+		"Hizkia Felix <hizkifw@gmail.com>",
+		"Hristo Oskov <hristo.oskov@gmail.com>",
+		"Ilya Konanykhin <ilya.konanykhin@gmail.com>",
+		"Isaac Madwed <i.madwed@gmail.com>",
+		"Jefferson Felix <me@jsfelix.dev>",
+		"Jonathan Burke <jonathan.burke.1311@googlemail.com>",
+		"Jonathan Mayol <mayoljonathan@gmail.com>",
+		"JooYoung <qkdlql@naver.com>",
+		"Jordan Austin <jrax86@gmail.com>",
+		"Josh Hamit <josh.hamit@gmail.com>",
+		"Kevin Mai-Husan Chia <mhchia@users.noreply.github.com>",
+		"Kyrylo Shegeda <shegeda@ualberta.ca>",
+		"PatrickJS <github@gdi2290.com>",
+		"Pepijn de Vos <pepijndevos@gmail.com>",
+		"Rolf Erik Lekang <me@rolflekang.com>"
+	],
+	"funding": {
+		"type": "opencollective",
+		"url": "https://opencollective.com/peer"
+	},
+	"collective": {
+		"type": "opencollective",
+		"url": "https://opencollective.com/peer"
 	},
 	"files": [
-		"dist/*.js",
-		"dist/*.map",
-		"lib/",
-		"index.d.ts"
+		"dist/*"
 	],
-	"author": "Michelle Bu, Eric Zhang, Jairo Caro-Accino, Carlos Caballero",
-	"maintainers": [
-		"Alex Sosnovskiy <devbyru@gmail.com> (https://github.com/afrokick)"
+	"type": "module",
+	"sideEffects": [
+		"lib/global.ts",
+		"lib/supports.ts"
 	],
-	"license": "MIT",
+	"main": "dist/bundler.cjs",
+	"browser-minified": "dist/peerjs.min.cjs",
+	"browser-unminified": "dist/peerjs.cjs",
+	"types": "dist/types.d.ts",
+	"targets": {
+		"types": {
+			"source": "lib/exports.ts"
+		},
+		"main": {
+			"source": "lib/exports.ts"
+		},
+		"browser-minified": {
+			"includeNodeModules": true,
+			"context": "browser",
+			"optimize": true,
+			"engines": {
+				"browsers": "cover 99%, not dead"
+			},
+			"source": "lib/global.ts"
+		},
+		"browser-unminified": {
+			"includeNodeModules": true,
+			"context": "browser",
+			"optimize": false,
+			"engines": {
+				"browsers": "cover 99%, not dead"
+			},
+			"source": "lib/global.ts"
+		}
+	},
 	"scripts": {
-		"build": "parcel build lib/exports.ts --out-file peerjs.min.js",
-		"build-nonminified": "parcel build lib/exports.ts --out-file peerjs.js --no-minify",
+		"check": "tsc --noEmit",
+		"watch": "parcel watch",
+		"build": "rm -rf dist && parcel build && ln -s dist/peerjs.cjs dist/peerjs.js && ln -s dist/peerjs.min.cjs dist/peerjs.min.js",
 		"prepublishOnly": "npm run build",
 		"test": "mocha -r ts-node/register -r jsdom-global/register test/**/*.ts",
 		"format": "prettier --write ."
 	},
-	"release": {
-		"branch": "master"
-	},
-	"types": "./index.d.ts",
 	"devDependencies": {
+		"@parcel/packager-ts": "^2.5.0",
+		"@parcel/transformer-typescript-types": "^2.5.0",
 		"@types/chai": "^4.3.0",
 		"@types/mocha": "^9.1.0",
+		"@types/node": "^17.0.18",
 		"chai": "^4.3.6",
 		"jsdom": "^19.0.0",
 		"jsdom-global": "^3.0.2",
 		"mocha": "^9.2.0",
 		"mock-socket": "8.0.5",
-		"parcel-bundler": "^1.12.4",
+		"parcel": "^2.5.0",
 		"prettier": "^2.6.2",
+		"standard": "^16.0.4",
 		"ts-node": "^10.5.0",
 		"typescript": "^4.5.5"
 	},
 	"dependencies": {
-		"@types/node": "^17.0.18",
 		"eventemitter3": "^3.1.2",
 		"peerjs-js-binarypack": "1.0.1",
 		"webrtc-adapter": "^7.7.1"
-	},
-	"collective": {
-		"type": "opencollective",
-		"url": "https://opencollective.com/peer"
 	}
 }

+ 3 - 1
tsconfig.json

@@ -5,6 +5,8 @@
 		"downlevelIteration": true,
 		"noUnusedLocals": true,
 		"noUnusedParameters": true,
-		"skipLibCheck": true
+		"skipLibCheck": true,
+		"isolatedModules": true,
+		"lib": ["es2020", "dom"]
 	}
 }

Some files were not shown because too many files changed in this diff