Shindig
  1. Shindig
  2. SHINDIG-1432

shindig.container's _handleGadgetRpcMethod doesn't allow you to implement osapi functions as advertised

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0.0
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      Trying to use gadgetsrpctransport for a container custom osapi implementation and found that it doesn't work.

      I've disabled the JSON-RPC osapi service and am hooking up custom osapi code in my container. My container.js config file has these settings:
      "osapi.services" :

      { "gadgets.rpc" : ["appdata.update"] }

      ,
      "osapi" :

      { "endPoints" : [] }

      ,

      With JSON-RPC disabled, gadgetsrpctransport.js code in osapi feature is active. For any osapi call, like osapi.appdata.update, It sends sends an RPC call to the container, which is handled by osapi._handleGadgetRpcMethod(), which is found in osapi.js in shindig.container feature.

      In my custom container code I implemented a simple osapi handler for appdata.update:

      osapi.appdata = {
      update: function (request, callback)

      { console.log("Yeah!"); }

      }

      The code gets hit when I call appdata.update from my gadget. Unfortunately, the container can't do anything meaningful because the originating gadget is lost. I have no idea which of the many gadgets on my page sent the appdata.update message! Note that "this" = window within the update function.

      _handleGadgetRpcMethod really needs to preserve the gadget info. I'd suggest something like what is done for setprefs and other RPC APIs. When _handleGadgetRpcMethod is called from the process() function in rpc.js, the "this" point is set to the rpc object, which allows access to the gadget like so:

      var id = shindig.container.gadgetService.getGadgetIdFromModuleId(this.f);
      var gadget = shindig.container.getGadget(id);

      So, without some improvements to _handleGadgetRpcMethod it is not possible to implement a useful osapi in the container.

        Activity

        Hide
        Damian Biollo added a comment -

        Here's the change I made on my copy of the code to fix the problem. If you like it, please apply to trunk.

        File: shindig-trunk/features/src/main/javascript/features/shindig.container/osapi.js
        Line: 63

        Before
        current(requests[i].params, function {
        return function(response) {
        // Put back in json-rpc format
        responses[i] =

        { id : requests[i].id, data : response}

        ;
        callCount++;
        if (callCount == requests.length)

        { callback(responses); }
        };
        });


        After
        current.apply(this, [requests[i].params, function {
        return function(response) {
        // Put back in json-rpc format
        responses[i] = { id : requests[i].id, data : response};
        callCount++;
        if (callCount == requests.length) { callback(responses); }

        };
        }]);

        With this change I can now find out the source gadget and do something appropriate. ex:
        osapi.appdata = {
        update: function (request, callback)

        { var id = shindig.container.gadgetService.getGadgetIdFromModuleId(this.f); var gadget = shindig.container.getGadget(id); // set appdata for this gadget ... }

        }

        Show
        Damian Biollo added a comment - Here's the change I made on my copy of the code to fix the problem. If you like it, please apply to trunk. File: shindig-trunk/features/src/main/javascript/features/shindig.container/osapi.js Line: 63 Before current(requests [i] .params, function { return function(response) { // Put back in json-rpc format responses [i] = { id : requests[i].id, data : response} ; callCount++; if (callCount == requests.length) { callback(responses); } }; } ); After current.apply(this, [requests [i] .params, function { return function(response) { // Put back in json-rpc format responses [i] = { id : requests[i].id, data : response}; callCount++; if (callCount == requests.length) { callback(responses); } }; } ]); With this change I can now find out the source gadget and do something appropriate. ex: osapi.appdata = { update: function (request, callback) { var id = shindig.container.gadgetService.getGadgetIdFromModuleId(this.f); var gadget = shindig.container.getGadget(id); // set appdata for this gadget ... } }

          People

          • Assignee:
            Unassigned
            Reporter:
            Damian Biollo
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development