IsSuEat / open-livestreamer-firefox-addon

Addon for firefox to quickly open stream urls in vlc using livestreamer
GNU General Public License v3.0
18 stars 7 forks source link

Added the possibility to use the twitch chat #31

Closed sxe closed 8 years ago

sxe commented 9 years ago

Hi there, i have added the possibility to open the twitch chat when a stream is launched. There is a new entry in the preferences menu for that. You can either use a browser popup or a native irc client to start the chat (or disable it completely "default").

Please have a look and let me know what you think. Works great on my system so far.

Greetings, Andy

sxe commented 9 years ago

Ah i just noticed this addon works for other sites beside twitch as well. Right now the chat option would be opened on all sites.

I will change it to make it "twitch only".

sxe commented 9 years ago

ok, updated it again.

  1. It only works on twitch sites now.
  2. Changed the preferences strings so that it is clear that it's a twitch only feature.

Greetings

julianrichen commented 9 years ago

Hi! Just tested the feature/twitch_chat branch. Few things:

  1. Using pop-up instantly closes the selection box, this is because it is called before a quality button is loaded (video: https://vid.me/e/xmJK)
  2. This feature is all or nothing, this is not a deal breaker but it would be nice to open the chat on a stream by stream basis (would require changing the ui a bit, that can be another pr down the road)
  3. We should look into making it modular where we can easily add chat support from other sites, maybe store the info in a a json file:
{
    "twitch.tv": {
        "stream": "/(twitch)\\.tv/[A-z]+/g",
        "irc": "irc.twitch.tv/#<stream_id>",
        "http": "twitch.tv/<stream_id>chat?popout",
        "port": "6667",
        "notes": "Your password will be your OAuth string <http://help.twitch.tv/customer/portal/articles/1302780-twitch-irc>"
    },
    "ustream.tv": {
        "stream": "/(ustream).tv/channel/[A-z]+/g",
        "irc": "chat1.ustream.tv/#<stream_id>",
        "http": "ustream.tv/socialstream/<stream_id>",
        "port": "6667"
    }
}

I'll take a look when I have time to make the openChat() function modular.

sxe commented 9 years ago

Hi Julian, thx for the feedback.

  1. Should be easy to fix, i will look into it. *edit: Turns out it's not that easy to fix. As soon as an other window is created the panel disappears, that's a limitation (or feature) of the panel itself. So we have two possibilities. First: Start the chat first but then it would be started even when the stream fails for some reason. Second: Starting the chat from the closePanel function what works fine but i have no idea on how to get the correct url from within that function without using a global variable. Any idea? (I am talking about the panel while launching livestreamer btw, not the quality selection panel.)
  2. I am not sure what you mean. Do you want to be able to open more than one chat at the same time?
  3. I figured something like this would be necessary in the future. I started by just implementing it for myself to be able to chat via IRC but then added the popup solution as a simpler way for everybody else. Right now i have no idea what other services supported by livestreamer even have a chat function. It will be much more work to figure out the services and maintain all of them in the future. If you are willing to look into this that's fine with me, just let me know if you do so, until then i will not look into it myself, just to avoid the same work is done twice.

Greetings

julianrichen commented 9 years ago
  1. I think I figured out the issue (had to playing around with it because the docs are lack luster), solution below
  2. As I mentioned it's not a deal breaker just a slight enhancement, I was talking about the ability to open a Stream A with no chat and then open Stream B + Stream B's chat. Basically being able to selectively choose to open a chat based on the stream. This is mostly if you are stream hopping and you just want to see if the stream interest you, then you open the chat afterwards if you want to contribute but.... if the user is doing that they can just disable the chat feature.

Solution for # 1

So since I can't push directly to this PR and if I fork your repo it will overwrite my fork I'll just post my diff changes.

The 2 main issues was open() needed to be used instead of openDialog(), not 100% why but the docs on windows/utlis is not great. Then I moved openChat() call in the panel & context menu to the end of runLivestreamer() function.`

At the top I added { open } = require('sdk/window/utils'),:

const { Cc, Ci }     = require("chrome");
var { ToggleButton } = require("sdk/ui/button/toggle"),
    { open }         = require('sdk/window/utils'),
    panels           = require("sdk/panel"),
    self             = require("sdk/self"),
    system           = require("sdk/system"),
    tabs             = require("sdk/tabs"),
    prefs            = require("sdk/simple-prefs").prefs,
    contextMenu      = require("sdk/context-menu"),
    locale           = require("sdk/l10n").get;

I removed openChat() from the panel & context menu and added it at the end of the runLivestreamer() function as openChat(args[0]);:

// Run Livestreamer
function runLivestreamer(args) {
    var path,
        file,
        process;
    // Notify
    panel.width = 250;
    panel.height = 90;
    panel.port.emit("status", locale("status_lauching"));
    panel.port.emit("loading", true);
    // Get livestreamer path
    path = getLivestreamerPath();
    // Build file
    file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
    file.initWithPath(path);
    // New child process
    process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
    process.init(file);
    process.run(false, args, args.length);
    // Open chat if selected
    openChat(args[0]);
}

Then changed the openChat() function with:

// Open twitch chat
function openChat(url) {

    if (prefs.chatselector == "none") {
        return null;
    }

    // Check if it's a twitch link
    // Chat only works for twitch so far
    var reg = /(twitch)\.tv\/[A-z]+/g;
    var twitch = reg.exec(url);
    if (twitch[1] !== "twitch") {
        return null;
    }

    if (prefs.chatselector == "popup") {

        var chat = "/chat?popout=";
        var url = url + chat;

        var window = open('data:text/html,Loading...', {
            name: 'Chat',
            features: {
                chrome: true,
                centerscreen: true,
                resizable: true,
                scrollbars: false,
                width: 400,
                height: 550
            }
        });
        window.addEventListener('load', function (win) {
            window.location.href = url;
        });

    } else if (prefs.chatselector == "irc") {

        var reg = /twitch\.tv\/([A-z]+)/g;
        var name = reg.exec(url);
        var url = "irc://irc.twitch.tv/#" + name[1];

        var req = require("sdk/request").Request;
        var fakeReq = req({
          url: url
        }).get();

    } 

Also open() allows the OS's menu bar to be present so you can close the pop-up.

sxe commented 9 years ago

Hi Julian, i have to problems with your solution:

  1. I tried adding the openChat call to runLivestreamer before but was not satisfied with the result. As i mentioned above, the quality panel is accessible but the start panel disappears directly and not after the stream is launched. If this solution is acceptable we can keep it like that. I still think calling openChat from the closePanel function would be the best solution but as i said i am not sure how to get the url there.
  2. I don't understand why you switched to open instead of openDialog. For one it does not work here. :) The popup opens but there is nothing in it. When i leave it like it was before and use openDialog, it works just fine with the "limitation" mentioned in 1.

I will push my changes again to make sure we are talking about the same thing. ;)

Please have a look and let me know if that works. (It works perfectly on my system with the mentioned limitations.

julianrichen commented 9 years ago

aaaah, not sure why but that went over my head but If I understand you now you mean the message "Launching Livestreamer" instantly disappears because the pop-up window takes focus? If so you are correct, that will be tricky to fix without creating a global var.

Also what operating system are you on? I was Linux when using open() and it worked like a charm yet when I switched to Windows open() failed all together. openDialog() works on Windows for me. I'll try your new commit on Linux and see if openDialog() works. If not might have to create a bug report :(

sxe commented 9 years ago

"Launching Livestreamer" instantly disappears because the pop-up window takes focus?

Exactly

I am on Linux (Archlinux 64bit Firefox 38.0.5)

IsSuEat commented 9 years ago

Hi there! Sorry for being so quiet in the last time, had a lot of RL stuff to do.

The chat feature sounds interesting. What I would prefer though, would be to have maybe an extra button in the quality selection box to open the chat. I don't want chat for all the channels I watch, and going through the addon preferences everytime is a pain imho.

sxe commented 9 years ago

Hi IsSuEat, that's kind of what julianrichen suggested with his 2. point.

I suggest the following. I add a check box to the chat preference menu called "manual" (or something similar). If that box is checked two more entries are added to the "quality" panel with the ability to launch the chat (IRC or popup) an extra panel pops up to choose the chat. Combining it with the quality menu is a bit problematic cause you have to click twice. This way we have the auto launch chat functionality and a manual launch option.

*edit: We could also add check boxes for each chat type to the quality panel, so we just have one panel that pops up. I will play around with this idea and see what works better.

I will start to implement this, you guys can have a look then and decide if you like it.

julianrichen commented 9 years ago

The manual chat button could be under the "Launching livestreamer..." status message to notify the user that the streaming is launching but that they can also open the chat if they wish. Would avoid another step (and panel).

Also Open in Livestreamer just got it's 2.0 version approved in the addon repo :)

IsSuEat commented 8 years ago

I'm gonna close this. If anyone wants to do this, I will reopen it :)