Skip to content

Commit

Permalink
Peer server env config
Browse files Browse the repository at this point in the history
  • Loading branch information
paulstraw committed Nov 12, 2023
1 parent d2ca563 commit f8c08a9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"trailingComma": "all",
"semi": false,
"printWidth": 80,
"plugins": ["prettier-plugin-svelte"],
Expand Down
27 changes: 20 additions & 7 deletions src/lib/stores/peerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,7 +33,7 @@ class PeerStore extends EventEmitter {
subscribe: (
this: void,
run: Subscriber<PeerStoreData>,
invalidate?: Invalidator<PeerStoreData>
invalidate?: Invalidator<PeerStoreData>,
) => Unsubscriber

constructor() {
Expand All @@ -35,7 +42,7 @@ class PeerStore extends EventEmitter {
this.writable = writable({
peerId: null,
isConnecting: false,
peerConnections: {}
peerConnections: {},
})

this.subscribe = this.writable.subscribe
Expand All @@ -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)

Expand Down Expand Up @@ -139,7 +152,7 @@ class PeerStore extends EventEmitter {
toastStore.addToast(
'Error connecting to peer server',
`${err.message} - ${err.type}`,
ToastLevel.Warning
ToastLevel.Warning,
)
}
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '0.0.1'
export const version = '0.1.0'

0 comments on commit f8c08a9

Please sign in to comment.