Skip to content

Commit

Permalink
feat : https->http 로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jsilver01 committed Sep 23, 2024
1 parent 86c2c37 commit a8e5836
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
4 changes: 2 additions & 2 deletions config.example.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
listenIp: '0.0.0.0',
listenPort: 3000,
sslCrt: '/etc/ssl/certs/ssl-cert-snakeoil.pem',
sslKey: '/etc/ssl/private/ssl-cert-snakeoil.key',
// sslCrt: '/etc/ssl/certs/ssl-cert-snakeoil.pem',
// sslKey: '/etc/ssl/private/ssl-cert-snakeoil.key',
mediasoup: {
// Worker settings
worker: {
Expand Down
8 changes: 4 additions & 4 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
listenIp: '0.0.0.0',
listenPort: 3000,
sslKey: '/Users/jungrlo/Linkode_Media/config/_wildcard.exampel.dev+3-key.pem',
sslCrt: '/Users/jungrlo/Linkode_Media/config/_wildcard.exampel.dev+3.pem',
// sslKey: '/Users/jungrlo/Linkode_Media/config/_wildcard.exampel.dev+3-key.pem',
// sslCrt: '/Users/jungrlo/Linkode_Media/config/_wildcard.exampel.dev+3.pem',
mediasoup: {
// Worker settings
worker: {
Expand Down Expand Up @@ -48,8 +48,8 @@ module.exports = {
webRtcTransport: {
listenIps: [
{
ip: '13.209.220.22',
announcedIp: 'www.linkodemedia.shop',
ip: '127.0.0.1',
announcedIp: null,
}
],
maxIncomingBitrate: 1500000,
Expand Down
49 changes: 26 additions & 23 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const mediasoup = require('mediasoup');
const fs = require('fs');
const https = require('https');
const http = require('http');
const express = require('express');
const socketIO = require('socket.io');
const config = require('./config');
Expand Down Expand Up @@ -109,30 +109,33 @@ async function runExpressApp() {
}

async function runWebServer() {
const { sslKey, sslCrt } = config;
if (!fs.existsSync(sslKey) || !fs.existsSync(sslCrt)) {
console.error('SSL files are not found. check your config.js file');
process.exit(0);
}
const tls = {
cert: fs.readFileSync(sslCrt),
key: fs.readFileSync(sslKey),
};
webServer = https.createServer(tls, expressApp);
webServer.on('error', (err) => {
console.error('starting web server failed:', err.message);
});

await new Promise((resolve) => {
// https 로 테스트하고 싶은 경우 아래 주석처리 후 여기 주석 비활성화해서 사용하기
// const { sslKey, sslCrt } = config;
// if (!fs.existsSync(sslKey) || !fs.existsSync(sslCrt)) {
// console.error('SSL files are not found. check your config.js file');
// process.exit(0);
// }
// const tls = {
// cert: fs.readFileSync(sslCrt),
// key: fs.readFileSync(sslKey),
// };
// webServer = https.createServer(tls, expressApp);

const { listenIp, listenPort } = config;
webServer.listen(listenPort, listenIp, () => {
const listenIps = config.mediasoup.webRtcTransport.listenIps[0];
const ip = listenIps.announcedIp || listenIps.ip;
console.log('server is running');
console.log(`open https://${ip}:${listenPort} in your web browser`);
resolve();
webServer = http.createServer(expressApp);
webServer.on('error', (err) => {
console.error('starting web server failed:', err.message);
});

await new Promise((resolve) => {
webServer.listen(listenPort, listenIp, () => {
const listenIps = config.mediasoup.webRtcTransport.listenIps[0];
const ip = listenIps.announcedIp || listenIps.ip;
console.log('server is running');
console.log(`open https://${ip}:${listenPort} in your web browser`);
resolve();
});
});
});
}

async function runSocketServer() {
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const axios = require('axios');
const https = require('https');
const http = require('http');

const agent = new https.Agent({
const agent = new http.Agent({
rejectUnauthorized: false
});

Expand Down

0 comments on commit a8e5836

Please sign in to comment.