Announcement

Collapse
No announcement yet.

CometD

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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
    Material debug: 1. Launch via http: //SERVER:9000/material/?debug=json (Use http: //SERVER:9000/material/?debug=json,cometd to also see update messages, e.g. play queue) 2. Open browser's developer tools 3. Open console tab in developer tools 4. REQ/RESP messages sent to/from LMS will be logged here.

    #2
    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?
    Material debug: 1. Launch via http: //SERVER:9000/material/?debug=json (Use http: //SERVER:9000/material/?debug=json,cometd to also see update messages, e.g. play queue) 2. Open browser's developer tools 3. Open console tab in developer tools 4. REQ/RESP messages sent to/from LMS will be logged here.

    Comment


      #3
      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
      Michael

      "It doesn't work - what shall I do?" - "Please check your server.log and/or scanner.log file!"
      (LMS: Settings/Information)

      Comment


        #4
        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
        Material debug: 1. Launch via http: //SERVER:9000/material/?debug=json (Use http: //SERVER:9000/material/?debug=json,cometd to also see update messages, e.g. play queue) 2. Open browser's developer tools 3. Open console tab in developer tools 4. REQ/RESP messages sent to/from LMS will be logged here.

        Comment


          #5
          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.
          Material debug: 1. Launch via http: //SERVER:9000/material/?debug=json (Use http: //SERVER:9000/material/?debug=json,cometd to also see update messages, e.g. play queue) 2. Open browser's developer tools 3. Open console tab in developer tools 4. REQ/RESP messages sent to/from LMS will be logged here.

          Comment


            #6
            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, 22: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.

            Comment


              #7
              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.

              Comment

              Working...
              X