Skip to content

Commit

Permalink
chore: implement custom ICE server configuration support
Browse files Browse the repository at this point in the history
  • Loading branch information
psanders committed Dec 22, 2023
1 parent 3b4162d commit 093975d
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ OWNER_PASSWORD=changeme
# PeerJs Server config
SIGNALING_HOST=localhost
SIGNALING_PORT=9000
# Ucomment to enable ICE servers
# ICE_SERVERS_CONFIG='[{"urls": "stun:stun.l.google.com:19302"}, {"urls": "turn:turn.bistri.com:80", "username": "homeo", "credential": "homeo"}]'

# SMTP config
SMTP_HOST=localhost
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ OWNER_PASSWORD=changeme
# PeerJs Server config
SIGNALING_HOST=localhost
SIGNALING_PORT=9000
# Ucomment to use custom ICE servers
# ICE_SERVERS_CONFIG='[{"url": "stun:stun.l.google.com:19302"}, {"url": "turn:turn.bistri.com:80", "username": "homeo", "credential": "homeo"}]'

# SMTP config
SMTP_HOST=localhost
Expand Down
4 changes: 4 additions & 0 deletions docs/docs/self-hosting/deploy-with-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ OWNER_PASSWORD=changeme
# PeerJs Server config
SIGNALING_HOST=localhost
SIGNALING_PORT=9000
# Ucomment to use custom ICE servers
# ICE_SERVERS_CONFIG='[{"url": "stun:stun.l.google.com:19302"}, {"url": "turn:us-turn4.xirsys.com:80?transport=udp", "username": "xirsys", "credential": "xirsys"}]'

# SMTP config
SMTP_HOST=localhost
Expand All @@ -57,6 +59,8 @@ Few important things to note:
- The `SIGNALLING_PORT` must be the port where the signaling server will be accessible. For example, if you are running the application locally, you can use `9000`. If you are running the application on a server, you can use, for example, `443`
- You must point your SMTP variables to a valid SMTP server
- Goodtok will use the `OWNER_EMAIL` and `OWNER_PASSWORD` variables to create the first user. The server will create a new owner if the email does not exist. Goodtok will update the password if the email exists. You can use any email address and password for this purpose.
- The `CLOAK_ENCRYPTION_KEY` must be a valid encryption key. You can use [Cloack](https://cloack.47ng.com) to generate a new key.
- Uncomment the `ICE_SERVERS_CONFIG` variable to enable ICE servers. You can use [Xirsys](https://xirsys.com) to get a free account.

Finally, run the following command to start the application:

Expand Down
11 changes: 9 additions & 2 deletions mods/apiserver/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
JWT_SIGN_OPTIONS,
JWT_SECURITY_SALT,
SIGNALING_HOST,
SIGNALING_PORT
SIGNALING_PORT,
ICE_SERVERS_CONFIG
} from "./envs";
import jwt from "jsonwebtoken";

Expand Down Expand Up @@ -53,7 +54,8 @@ export async function createContext(opts: ContextOptions) {
jwtSecuritySalt: JWT_SECURITY_SALT,
jwtSignOptions: JWT_SIGN_OPTIONS,
signalingHost: SIGNALING_HOST,
signalingPort: SIGNALING_PORT
signalingPort: SIGNALING_PORT,
iceServersConfig: ICE_SERVERS_CONFIG
}
};
}
Expand All @@ -68,5 +70,10 @@ export type Context = {
jwtSignOptions: jwt.SignOptions;
signalingHost: string;
signalingPort: string;
iceServersConfig?: {
urls: string | string[];
username?: string;
credential?: string;
}[];
};
};
3 changes: 3 additions & 0 deletions mods/apiserver/src/envs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export const JWT_SIGN_OPTIONS = e.JWT_SIGN_OPTIONS
// PeerJS server configurations
export const SIGNALING_HOST = e.SIGNALING_HOST;
export const SIGNALING_PORT = e.SIGNALING_PORT ?? "443";
export const ICE_SERVERS_CONFIG = e.ICE_SERVERS_CONFIG
? JSON.parse(e.ICE_SERVERS_CONFIG)
: [{ urls: "stun:stun.l.google.com:19302" }];

// SMTP configurations
export const SMTP_HOST = e.SMTP_HOST;
Expand Down
1 change: 1 addition & 0 deletions mods/apiserver/src/tokens/createAnonymousToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export async function createAnonymousToken(
ref: ref,
signalingHost: ctx.config.signalingHost,
signalingPort: ctx.config.signalingPort,
iceServers: ctx.config.iceServersConfig,
// Use the same ref as the customerId (only for annonymous users)
customerId: ref,
workspaceId,
Expand Down
3 changes: 2 additions & 1 deletion mods/apiserver/src/tokens/createToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export async function createToken(
customerId: input.customerId,
workspaceId: workspaceId,
signalingHost: ctx.config.signalingHost,
signalingPort: ctx.config.signalingPort
signalingPort: ctx.config.signalingPort,
iceServers: ctx.config.iceServersConfig
};

return jwt.sign(
Expand Down
1 change: 1 addition & 0 deletions mods/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
export type ConnectionObject = {
signalingHost: string;
signalingPort: number;
iceServers: { urls: string | string[]; username?: string; credential?: string }[];
customerId: string;
workspaceId: string;
calendarUrl: string;
Expand Down
4 changes: 3 additions & 1 deletion mods/frontoffice/src/containers/ChatContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ function ChatContainer() {
const peer = new Peer(undefined!, {
host: connectionObject.signalingHost,
port: connectionObject.signalingPort,
debug: 3
config: {
iceServers: connectionObject.iceServers
}
});

setConnectionObject(connectionObject);
Expand Down
5 changes: 4 additions & 1 deletion mods/widget/src/GoodtokUA.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ const GoodtokUA = () => {

const peer = new Peer(connectionObject.customerId, {
host: connectionObject.signalingHost,
port: connectionObject.signalingPort
port: connectionObject.signalingPort,
config: {
iceServers: connectionObject.iceServers
}
});

setPeer(peer);
Expand Down

0 comments on commit 093975d

Please sign in to comment.