Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Stremio Service.exe and accessing it via LAN for multi-device streaming #39

Open
Willyanlz opened this issue Jun 16, 2023 · 20 comments

Comments

@Willyanlz
Copy link

I would like to run the Stremio Service.exe on my computer and access it via LAN from other devices using Stremio Web, like my iPhone. Is there any way to do this?

@TRtomasz
Copy link
Member

Just use your local ip address to access it, if it is locally(LAN) then it should work without problem, if it is not working moste likely something on your side is blocking this

@Willyanlz
Copy link
Author

Thank you, Tomas. I'll give it a try and I'll be back soon!

@jaruba
Copy link
Member

jaruba commented Jun 16, 2023

@TRtomasz nope, he'd need to enable https by connecting the desktop client to the service first, as stremio web does not have this setting yet and it won't work through LAN without HTTPS enabled

@Willyanlz
Copy link
Author

Jaruba, how could I do that? Can you give me a step-by-step guide? I would like to use this method to link devices like the iPhone to use Stremio Web!

@rodhfr
Copy link

rodhfr commented Sep 22, 2023

So... there's no way to use this web app via LAN? That's sad .
Even the docker container I couldn't make work. Local adresses does not work at all just 127.0.0.1, it does not connect to the sever, just show the Web UI when I set a local address in the Web UI like 192.168.0.50 for example.
This prevents me from running this web app over proxy manager, tailscale or anything. I have CGNAT, can't use the normal https apparently.

For https I get this error in docker container:

EngineFS server started at http://127.0.0.1:11470
EngineFS HTTPS endpoint at https://local.strem.io:12470
HTTPS: Request error Could not get a valid HTTPS certificate

This is probably because CGNAT, but I couldn't test otherwise. Anyway I would like to just acess via LAN normally. This occours in QT Stremio app for Linux and Flatpak too. None of them work for LAN, only the 127.0.0.1 address.

Is this a security measure? If so, how could I disable this feature in the code?

@jaruba
Copy link
Member

jaruba commented Sep 22, 2023

It will be possible for sure, we will return to Stremio Service development after we solve the new bugs created during the redesign release.

@stonegray
Copy link

stonegray commented Dec 5, 2023

@rodhfr I think HTTPS is not functional, there doesn't appear to be a documented way to load a cert. I got it to work by proxying the HTTP using NGINX to add HTTPS support. Docker is not required but does make it easier.

  • Start a stremio docker container and expose :11470
  • Start a nginx docker container and expose :12470
    • Configure a reverse proxy to http://{server-ip}:10470
    • Add a HTTPS certificate and any authentication you wish
  • Configure your router to port forward 12470 if you want to use it outside of your LAN
  • Connect to "https://{server-ip}:12470 with a web browser, it will redirect you to app.strem.io:
    • Modify the URL to use HTTPS for streamingServer arg:
    • Eg: replace
      https://app.strem.io/shell-v4.4/?streamingServer=http%3A%2F%2Fexample.org#/
      with
      https://app.strem.io/shell-v4.4/?streamingServer=https%3A%2F%2Fexample.org#/
  • Bookmark that modified link and it should work as expected. Use https://{server-ip}:12470 as the streaming server URL in stremio desktop apps.

@Willyanlz
Copy link
Author

@stonegray Does this method work for use on devices such as iPhone via web browser?

@stonegray
Copy link

Yep, works fine on my iPhone over both LAN and cellular.

@Willyanlz
Copy link
Author

@stonegray incredible, I'm going to take an old notebook and set up an nginx server for this purpose. Can you help me if I need it?

@stonegray
Copy link

Keep in mind that the server sometimes transcodes video in software so it works in the iOS browser, so you may need a reasonably beefy CPU unless you have an Nvidia GPU, which appears to be the only hardware acceleration that stremio-server has enabled. (although the bundled ffmpeg supports qsv for vp9, hevc and more...)

I'm reluctant to provide any support and definitely not any contributions to this project as the core logic is not open source, and the devs seem uninterested in contributions. See #49

@Willyanlz
Copy link
Author

@stonegray, I understand, thanks anyway, it helped a lot!

@Willyanlz
Copy link
Author

Willyanlz commented Dec 5, 2023

@jaruba, Do you think that at some point in the future it will be possible to do what @stonegray proposed in an easier way? or even some other solution to watch via IOS devices

@stonegray
Copy link

stonegray commented Dec 5, 2023

Fuck it. Run the stremio-server docker container and login to it with docker exec -it [container name] bash

Run the following in a new folder called "ssl" to make a self signed ssl cert, make sure to put "*" as the FQDN otherwise it won't work.

openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout server.key -out server.crt

Then patch. the server.js with the following:

--- server.js   2023-12-05 18:20:52.775001047 +0000
+++ server.js   2023-12-05 18:28:37.677115234 +0000
@@ -36048,7 +36048,18 @@
             appPath: appPath,
             apiEndpoint: apiCertifficateEndpoint
         });
-        var sserver = https.createServer(app);
+           try {
+                   var fs = require('fs');
+                   var https = require('https');
+                   _cr = {
+                           key: fs.readFileSync('./ssl/server.key', 'utf8'),
+                           cert: fs.readFileSync('./ssl/server.crt', 'utf8')
+                   };
+           } catch (e) {
+                   console.error("Failed to load SSL cert:", e);
+                   _cr = { };
+           }
+           var sserver = https.createServer(_cr, app);
         if (sserver.listen(12470), sserver.on("listening", (function() {
             console.log("EngineFS HTTPS endpoint at https://local.strem.io:12470");
         })), sserver.on("error", (function(err) {
@@ -85771,4 +85782,4 @@
             exec(opener + ' "' + escape(target) + '"', callback);
         };
     }).call(this, "/");
-} ]);
\ No newline at end of file
+} ]);

That fixes the server and it works as expected. Just open https://[server-ip]:12470, click through any ssl cert warnings and it will work.

@Willyanlz
Copy link
Author

Willyanlz commented Dec 5, 2023

@stonegray, Friend, thank you very much, your knowledge must be recognized and used as a contribution to the project without a doubt!
Sorry for the inconvenience, I'm a Front-End developer, this side is a bit obscure for me and sorry my english, I'm using Google Translate to communicate

@FelipeOtz
Copy link

@Willyanlz conseguiu fazer funcionar? estou com o mesmo problema

@MatissAndersons
Copy link

MatissAndersons commented Feb 28, 2024

Thanks @stonegray for the patch. Got me thinking. If one doesn't want to mess with the contents of a docker image, it's possible to do it similarly without touching the stremio image.

Make a docker-compose.yml

version: '3'

services:
  stremio_server:
    image: stremio/server:latest
    ports:
      - "11470:11470"
      - "12470:12470"
    environment:
      - NO_CORS=1

  nginx:
    image: nginx:alpine
    ports:
      - "10443:443"
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf
      - ./ssl:/ssl
    depends_on:
      - stremio_server

In the same folder run mkdir ssl && openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout ssl/server.key -out ssl/server.crt

Then create a default.conf file looking like this:

server {
    listen 443 ssl;
    server_name _;
    ssl_certificate /ssl/server.crt;
    ssl_certificate_key /ssl/server.key;
    location / {
        proxy_pass http://stremio_server:11470;
    }
}

Run docker compose up -d and you have a reverse proxy. Of course the browser still throws an SSL warning/error. I just think this is a bit cleaner than a patch (or maybe I couldn't find a way to apply it simply, took me quite a bit of time to apply it the first time).

EDIT: one issue is that I couldn't get it to work through iOS app, chrome browser only, where I cannot see subtitles. Maybe someone has an idea how to fix that? Or I guess I could just buy a really cheap domain and put a letsencrypt "correctly" on it.

I'm not used to writing such messages, so pardon me for my lazy formatting.

@vijayvcm
Copy link

Fuck it. Run the stremio-server docker container and login to it with docker exec -it [container name] bash

Run the following in a new folder called "ssl" to make a self signed ssl cert, make sure to put "*" as the FQDN otherwise it won't work.

openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout server.key -out server.crt

Then patch. the server.js with the following:

--- server.js   2023-12-05 18:20:52.775001047 +0000
+++ server.js   2023-12-05 18:28:37.677115234 +0000
@@ -36048,7 +36048,18 @@
             appPath: appPath,
             apiEndpoint: apiCertifficateEndpoint
         });
-        var sserver = https.createServer(app);
+           try {
+                   var fs = require('fs');
+                   var https = require('https');
+                   _cr = {
+                           key: fs.readFileSync('./ssl/server.key', 'utf8'),
+                           cert: fs.readFileSync('./ssl/server.crt', 'utf8')
+                   };
+           } catch (e) {
+                   console.error("Failed to load SSL cert:", e);
+                   _cr = { };
+           }
+           var sserver = https.createServer(_cr, app);
         if (sserver.listen(12470), sserver.on("listening", (function() {
             console.log("EngineFS HTTPS endpoint at https://local.strem.io:12470");
         })), sserver.on("error", (function(err) {
@@ -85771,4 +85782,4 @@
             exec(opener + ' "' + escape(target) + '"', callback);
         };
     }).call(this, "/");
-} ]);
\ No newline at end of file
+} ]);

That fixes the server and it works as expected. Just open https://[server-ip]:12470, click through any ssl cert warnings and it will work.

How can I patch server.js file here?

@augustine-d-nguyen
Copy link

augustine-d-nguyen commented Apr 23, 2024

When you start the service, it will create a folder called .stremio-server. Create a file httpsCert.json inside the folder with content:

{
    "key": "-----BEGIN PRIVATE KEY-----\nMII....",
    "cert": "-----BEGIN CERTIFICATE-----\nMII...."
}

then it works like a champ. We don't need to patch the server.js
(Tested on my raspi 3B+)

@xxmathias
Copy link

xxmathias commented Oct 18, 2024

Thanks @stonegray for the patch. Got me thinking. If one doesn't want to mess with the contents of a docker image, it's possible to do it similarly without touching the stremio image.

Make a docker-compose.yml

version: '3'

services:
  stremio_server:
    image: stremio/server:latest
    ports:
      - "11470:11470"
      - "12470:12470"
    environment:
      - NO_CORS=1

  nginx:
    image: nginx:alpine
    ports:
      - "10443:443"
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf
      - ./ssl:/ssl
    depends_on:
      - stremio_server

In the same folder run mkdir ssl && openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout ssl/server.key -out ssl/server.crt

Then create a default.conf file looking like this:

server {
    listen 443 ssl;
    server_name _;
    ssl_certificate /ssl/server.crt;
    ssl_certificate_key /ssl/server.key;
    location / {
        proxy_pass http://stremio_server:11470;
    }
}

Run docker compose up -d and you have a reverse proxy. Of course the browser still throws an SSL warning/error. I just think this is a bit cleaner than a patch (or maybe I couldn't find a way to apply it simply, took me quite a bit of time to apply it the first time).

EDIT: one issue is that I couldn't get it to work through iOS app, chrome browser only, where I cannot see subtitles. Maybe someone has an idea how to fix that? Or I guess I could just buy a really cheap domain and put a letsencrypt "correctly" on it.

I'm not used to writing such messages, so pardon me for my lazy formatting.

tried it your way, accessed via https, accepted the cert and i still have the issue with the Network Error.
my logs:

EngineFS server started at http://127.0.0.1:11470

hls-converter - Initiating tests for hardware accelerated transcoding support, possible options: qsv-linux,nvenc-linux,vaapi-renderD128

hls-converter - Testing video hw accel for profile: qsv-linux

EngineFS HTTPS endpoint at https://local.strem.io:12470

-> GET /hlsv2/11470-qsv-linux-video-hevc.mkv/video0.m3u8?mediaURL=http%3A%2F%2F127.0.0.1%3A11470%2Fsamples%2Fhevc.mkv&profile=qsv-linux&maxWidth=1200 

-> GET /samples/hevc.mkv bytes=0-

-> GET /samples/hevc.mkv 

Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close

    at new NodeError (internal/errors.js:322:7)

    at Socket.onclose (internal/streams/end-of-stream.js:121:38)

    at Socket.emit (events.js:412:35)

    at Pipe.<anonymous> (net.js:686:12) {

  code: 'ERR_STREAM_PREMATURE_CLOSE'

}

-> GET /hlsv2/11470-qsv-linux-video-hevc.mkv/destroy 

hls-converter 11470-qsv-linux-video-hevc.mkv has been requested to be destroyed

hls-converter 11470-qsv-linux-video-hevc.mkv destoyed

hls-converter - Tests failed for [video] hw accel profile: qsv-linux

hls-converter - Some tests failed for hw accel profile: qsv-linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants