Server: handle tls websockets
authorChocobozzz <florian.bigard@gmail.com>
Mon, 17 Oct 2016 19:10:29 +0000 (21:10 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 17 Oct 2016 19:10:29 +0000 (21:10 +0200)
server/initializers/constants.js
server/models/video.js

index 09c4f755e723be6fceb567f107ec6b0682385cc3..fb1cbc5f305929fd26a3732a2b3ab3c3aa2bacb1 100644 (file)
@@ -44,6 +44,7 @@ const CONFIG = {
   },
   WEBSERVER: {
     SCHEME: config.get('webserver.https') === true ? 'https' : 'http',
+    WS: config.get('webserver.https') === true ? 'wss' : 'ws',
     HOST: config.get('webserver.host'),
     PORT: config.get('webserver.port')
   }
index 9272bea6dc99c7886f57256df66c5226f56cb63b..4b941a40cf6ee8d11ef8b71b8f30a1fe3fd841bc 100644 (file)
@@ -1,6 +1,5 @@
 'use strict'
 
-const config = require('config')
 const createTorrent = require('create-torrent')
 const ffmpeg = require('fluent-ffmpeg')
 const fs = require('fs')
@@ -16,11 +15,6 @@ const logger = require('../helpers/logger')
 const modelUtils = require('./utils')
 const utils = require('../helpers/utils')
 
-const http = config.get('webserver.https') === true ? 'https' : 'http'
-const host = config.get('webserver.host')
-const port = config.get('webserver.port')
-const webseedBaseUrl = http + '://' + host + ':' + port + constants.STATIC_PATHS.WEBSEED
-
 // ---------------------------------------------------------------------------
 
 // TODO: add indexes on searchable columns
@@ -106,7 +100,16 @@ VideoSchema.pre('save', function (next) {
     tasks.push(
       // TODO: refractoring
       function (callback) {
-        createTorrent(videoPath, { announceList: [ [ 'ws://' + host + ':' + port + '/tracker/socket' ] ], urlList: [ webseedBaseUrl + video.filename ] }, function (err, torrent) {
+        const options = {
+          announceList: [
+            [ constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOST + ':' + constants.CONFIG.WEBSERVER.PORT + '/tracker/socket' ]
+          ],
+          urlList: [
+            constants.CONFIG.WEBSERVER.URL + constants.STATIC_PATHS.WEBSEED + video.filename
+          ]
+        }
+
+        createTorrent(videoPath, options, function (err, torrent) {
           if (err) return callback(err)
 
           fs.writeFile(constants.CONFIG.STORAGE.TORRENTS_DIR + video.filename + '.torrent', torrent, function (err) {