Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 7 of 7

Thread: CometD

  1. #1
    Senior Member
    Join Date
    Mar 2017
    Posts
    3,742

    CometD

    Thinking about using CometD to obtain status updates, rather than polling in Material Skin. I found a Javascript library for this at https://github.com/cometd/cometd-javascript (As an aside, I had to rename this libcometd.js, otherwise LMS would just return some error message instead of the JS file?)

    Just quickly adding this to my server.js file, so that I can see how things work, I tried:

    Code:
            var cometd = new org.cometd.CometD();
            cometd.init({url: lmsServerAddress + '/cometd', logLevel:'debug'});
            cometd.addListener('/meta/handshake', function(message) {
                if (eval(message).successful) {
                    console.log("Handshake successful");
                    cometd.subscribe('/slim/serverstatus', cometd.getClientId(),
                                    function(res) { console.log("serverstatus:"+JSON.stringify(res, null, 2));},
                                    {data:{response:'/'+cometd.getClientId()+'/slim/serverstatus', request:['', ['serverstatus', 0, 50, 'subscribe:60']]}});
                }
            });
    But I never get any serverstatus messages. CometD does produce some logging, and the handshake is successful. If I edit the libcometd.js file and replace channel: '/meta/subscribe' with channel: '/slim/subscribe' in CometD.subscribe(), then CometD does log what appears to be serverstatus messages. But still my handler above is not called. This is hack anyway, and I'm sure its not a correct change.

    Any ideas as to what's wrong? Anybody have experience using cometd.js with LMS?

  2. #2
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,776

    CometD

    > Just quickly adding this to my -server.js- file, so that I can see how
    > things work, I tried:


    Could you please create a branch on github I could play with this? Would
    be easier than finding the right place to put this in...

    > Any ideas as to what's wrong? Anybody have experience using cometd.js
    > with LMS?


    I'll see what I did when I was using it - when I find some time.

    --

    Michael

  3. #3
    Senior Member
    Join Date
    Mar 2017
    Posts
    3,742
    Quote Originally Posted by mherger View Post
    > Just quickly adding this to my -server.js- file, so that I can see how
    > things work, I tried:


    Could you please create a branch on github I could play with this? Would
    be easier than finding the right place to put this in...
    Sure, but it'll have to be much later - at work at the moment. But, I literally just copied cometd.js to MaterialSkin/HTML/material/html/lib/libcometd.js (must be renamed), edited desktop.html to include this JS file, and placed the above code in the "mounted" section of server.js

  4. #4
    Senior Member
    Join Date
    Mar 2017
    Posts
    3,742
    Quote Originally Posted by mherger View Post
    > Just quickly adding this to my -server.js- file, so that I can see how
    > things work, I tried:


    Could you please create a branch on github I could play with this? Would
    be easier than finding the right place to put this in...
    Code checked into cometd branch.

  5. #5
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,776

    CometD

    > Code checked into cometd branch.

    Thanks. Played with it, but didn't get it to report anything either. I
    do see that it's connecting to the server. But no events.

    --

    Michael

  6. #6
    Senior Member
    Join Date
    Aug 2014
    Location
    UK
    Posts
    735
    Sorry to resurrect an old thread, I've been wrestling with cometD from a REACT Javascript app I'm building and not having much luck.

    I'm handshaking fine, but when I subscribe I get nothing.
    I'm using the standard npm package for cometD.

    If for example, I use similar code to Craig's code above it sends a message like this :

    Code:
    [
      {
        "data": {
          "response": "/4954119f/slim/serverstatus",
          "request": [
            "",
            [
              "serverstatus",
              0,
              50,
              "subscribe:60"
            ]
          ]
        },
        "id": "3",
        "channel": "/meta/subscribe",
        "subscription": "/slim/subscribe",
        "clientId": "4954119f"
      }
    ]
    Which, if I look at the documentation for CometD, is correct.

    However, if I look at the LMS code, it states this :

    Code:
    			# A valid /slim/subscribe message looks like this:
    			# {
    			#   channel  => '/slim/subscribe',
    			#   id       => <unique id>,
    			#   data     => {
    			#     response => '/slim/serverstatus', # the channel all messages should be sent back on
    			#     request  => [ '', [ 'serverstatus', 0, 50, 'subscribe:60' ],
    			#     priority => <value>, # optional priority value, is passed-through with the response
    			#   }
    Note, it says '/slim/subscribe' should be in the 'channel' key (instead of 'meta/subscribe' and there should be no 'subscription' key.

    Is it simply that LMS is non-standard and I'm going to have to hand craft my own subscription method?


    [EDIT]
    Ah, I now realise that is exactly what Craig has done, he is maintaining is own amended version of libcometd.js and put some custom code in to make it work : https://github.com/CDrummond/lms-mat...ometd.js#L2820
    Last edited by expectingtofly; 2022-05-25 at 13:30.
    Stuart McLean

    ExpectingToFly Plugins :
    BBC Sounds, Global Player (UK), Times Radio, UK Radio Player, Virgin Radio (UK) and the Radio Favourites Plugin

    For BBC Sounds help see the BBC Sounds Wiki.

  7. #7
    Senior Member
    Join Date
    Aug 2014
    Location
    UK
    Posts
    735
    I now realise that Craig has been down this journey before, I'll just have to look at his amended libcometd.js.
    Stuart McLean

    ExpectingToFly Plugins :
    BBC Sounds, Global Player (UK), Times Radio, UK Radio Player, Virgin Radio (UK) and the Radio Favourites Plugin

    For BBC Sounds help see the BBC Sounds Wiki.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •