Skip to content

Commit

Permalink
fix: using private signaling server on fly.io
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Nov 20, 2023
1 parent c1f2225 commit 25e3b94
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 9 deletions.
6 changes: 3 additions & 3 deletions desktop/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { invoke } from "@tauri-apps/api/tauri";
import { useLocalStorage } from "@uidotdev/usehooks";
import { DataConnection, Peer } from "peerjs";
import { useEffect, useRef, useState } from "react";
import { v4 as uuidv4 } from 'uuid';
import successSvg from "./assets/success.svg";
import { BASE_URL } from "./config";
import { BASE_URL, PEERJS_OPTIONS } from "./config";
import { createQR } from "./qr";
import { useLocalStorage } from "@uidotdev/usehooks";


enum Action {
Expand All @@ -27,7 +27,7 @@ function App() {
const [id, ] = useLocalStorage('id', uuidv4())
console.log('localstorage id => ', id)
const [loading, setLoading] = useState(true);
const [peer, ] = useState(new Peer(id, { pingInterval: 2000 , host: '0.peerjs.com', debug: 3}));
const [peer, ] = useState(new Peer(id, PEERJS_OPTIONS));
const [conn, setConn] = useState<DataConnection | null>(null);
const qrDiv = useRef<HTMLDivElement>(null);

Expand Down
11 changes: 10 additions & 1 deletion desktop/src/config.ts
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
export const BASE_URL = 'https://thewh1teagle.github.io/mobslide/'
import {PeerOptions} from 'peerjs'
export const BASE_URL = 'https://thewh1teagle.github.io/mobslide/'
export const PEERJS_OPTIONS: PeerOptions = {
host: 'mobslide-signaling.fly.dev',
port: 443,
path: '/',
pingInterval: 2000,
secure: true,
debug: 3
}
24 changes: 24 additions & 0 deletions web/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
5 changes: 5 additions & 0 deletions web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM peerjs/peerjs-server

# Expose port 9000
EXPOSE 9000
ENTRYPOINT ["node", "peerjs.js", "--host", "0.0.0.0", "--port", "9000"]
17 changes: 17 additions & 0 deletions web/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# fly.toml app configuration file generated for mobslide-signaling on 2023-11-20T04:36:58+02:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "mobslide-signaling"
primary_region = "mad"

[build]
dockerfile = "Dockerfile"

[http_service]
internal_port = 9000
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
7 changes: 2 additions & 5 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from "react";
import { useLongPress } from "use-long-press";

import Peer, { DataConnection } from "peerjs";
import { PEERJS_OPTIONS } from "./config";

const noSleep = new NoSleep();
enum Action {
Expand Down Expand Up @@ -68,11 +69,7 @@ function App() {
async function createConnection() {
return new Promise<void>((resolve, reject) => {
console.log("connecting to ", addressRef.current);
peerRef.current = new Peer({
host: "0.peerjs.com",
debug: 3,
pingInterval: 2000,
});
peerRef.current = new Peer(PEERJS_OPTIONS);
peerRef.current.on("open", () => {
if (addressRef.current) {
peerRef?.current?.on("error", (error) => reject(error));
Expand Down
10 changes: 10 additions & 0 deletions web/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {PeerOptions} from 'peerjs'

export const PEERJS_OPTIONS: PeerOptions = {
host: 'mobslide-signaling.fly.dev',
port: 443,
path: '/',
pingInterval: 2000,
secure: true,
debug: 3
}

0 comments on commit 25e3b94

Please sign in to comment.