From f8c08a91bba44d7289704b7a5383ac4d75630c2c Mon Sep 17 00:00:00 2001 From: Paul Straw Date: Sun, 12 Nov 2023 15:58:01 -0800 Subject: [PATCH] Peer server env config --- .prettierrc | 2 +- src/lib/stores/peerStore.ts | 27 ++++++++++++++++++++------- src/lib/version.ts | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.prettierrc b/.prettierrc index 4a25148..168e441 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,7 +1,7 @@ { "useTabs": true, "singleQuote": true, - "trailingComma": "none", + "trailingComma": "all", "semi": false, "printWidth": 80, "plugins": ["prettier-plugin-svelte"], diff --git a/src/lib/stores/peerStore.ts b/src/lib/stores/peerStore.ts index 7f827c1..904aa44 100644 --- a/src/lib/stores/peerStore.ts +++ b/src/lib/stores/peerStore.ts @@ -6,11 +6,18 @@ import { type Writable, type Subscriber, type Invalidator, - get + get, } from 'svelte/store' import { ToastLevel, toastStore } from './toastStore' import { EventEmitter } from '$lib/util/EventEmitter' import { leftPad } from '$lib/util/string' +import { + PUBLIC_PEERJS_SERVER_HOST, + PUBLIC_PEERJS_SERVER_KEY, + PUBLIC_PEERJS_SERVER_PATH, + PUBLIC_PEERJS_SERVER_PORT, + PUBLIC_PEERJS_SERVER_SECURE, +} from '$env/static/public' interface PeerStoreData { peerId: string | null @@ -26,7 +33,7 @@ class PeerStore extends EventEmitter { subscribe: ( this: void, run: Subscriber, - invalidate?: Invalidator + invalidate?: Invalidator, ) => Unsubscriber constructor() { @@ -35,7 +42,7 @@ class PeerStore extends EventEmitter { this.writable = writable({ peerId: null, isConnecting: false, - peerConnections: {} + peerConnections: {}, }) this.subscribe = this.writable.subscribe @@ -45,7 +52,13 @@ class PeerStore extends EventEmitter { initializePeer() { const peerId = this.getRandomPeerId() console.log(`[PeerStore] Attempting to connect as ${peerId}`) - this.peer = new Peer(peerId) + this.peer = new Peer(peerId, { + host: PUBLIC_PEERJS_SERVER_HOST, + port: parseInt(PUBLIC_PEERJS_SERVER_PORT, 10), + secure: PUBLIC_PEERJS_SERVER_SECURE === 'true', + path: PUBLIC_PEERJS_SERVER_PATH, + key: PUBLIC_PEERJS_SERVER_KEY, + }) this.setIsConnecting(true) @@ -139,7 +152,7 @@ class PeerStore extends EventEmitter { toastStore.addToast( 'Error connecting to peer server', `${err.message} - ${err.type}`, - ToastLevel.Warning + ToastLevel.Warning, ) } } @@ -162,12 +175,12 @@ class PeerStore extends EventEmitter { | 'message-too-big' | 'negotiation-failed' | 'connection-closed' - > + >, ) { toastStore.addToast( `Peer conn error ${err.type}`, err.message, - ToastLevel.Warning + ToastLevel.Warning, ) this.removePeerConn(conn) diff --git a/src/lib/version.ts b/src/lib/version.ts index 6af1fbc..6ccd2f1 100644 --- a/src/lib/version.ts +++ b/src/lib/version.ts @@ -1 +1 @@ -export const version = '0.0.1' +export const version = '0.1.0'