浏览代码

refactor: export `CborPeer` and `MsgPackPeer`

Jonas Gloning 1 年之前
父节点
当前提交
e98f04ac6f
共有 4 个文件被更改,包括 25 次插入2 次删除
  1. 9 0
      lib/cborPeer.ts
  2. 6 1
      lib/exports.ts
  3. 9 0
      lib/msgPackPeer.ts
  4. 1 1
      lib/peer.ts

+ 9 - 0
lib/cborPeer.ts

@@ -0,0 +1,9 @@
+import { Peer, SerializerMapping } from "./peer";
+import { Cbor } from "./dataconnection/StreamConnection/Cbor";
+
+export class CborPeer extends Peer {
+	override _serializers: SerializerMapping = {
+		Cbor,
+		default: Cbor,
+	};
+}

+ 6 - 1
lib/exports.ts

@@ -1,5 +1,8 @@
 export { util, type Util } from "./util";
 import { Peer } from "./peer";
+import { CborPeer } from "./cborPeer";
+import { MsgPackPeer } from "./msgPackPeer";
+
 export type { PeerEvents, PeerError, PeerOptions } from "./peer";
 
 export type {
@@ -24,6 +27,8 @@ export { BufferedConnection } from "./dataconnection/BufferedConnection/Buffered
 export { StreamConnection } from "./dataconnection/StreamConnection/StreamConnection";
 export { Cbor } from "./dataconnection/StreamConnection/Cbor";
 export { MsgPack } from "./dataconnection/StreamConnection/MsgPack";
+export type { SerializerMapping } from "./peer";
+
+export { Peer, MsgPackPeer, CborPeer };
 
-export { Peer };
 export default Peer;

+ 9 - 0
lib/msgPackPeer.ts

@@ -0,0 +1,9 @@
+import { Peer, SerializerMapping } from "./peer";
+import { MsgPack } from "./exports";
+
+export class MsgPackPeer extends Peer {
+	override _serializers: SerializerMapping = {
+		MsgPack,
+		default: MsgPack,
+	};
+}

+ 1 - 1
lib/peer.ts

@@ -126,7 +126,7 @@ export type PeerEvents = {
 export class Peer extends EventEmitter<PeerEvents> {
 	private static readonly DEFAULT_KEY = "peerjs";
 
-	private readonly _serializers: SerializerMapping = {
+	protected readonly _serializers: SerializerMapping = {
 		raw: Raw,
 		json: Json,
 		binary: BinaryPack,