Best Practice: How do I identify a socket as belonging to a specific entity?

16 views
Skip to first unread message

Ben Kuhl

unread,
May 29, 2013, 10:59:56 AM5/29/13
to portal_...@googlegroups.com
I'm using AngularJS and have created a SocketService which is essentially just a wrapper for portal.  Currently I'm passing a UUID with each request.  This isn't a fantastic solution and I'd like to come up with a better way to do it.

    service.makeInactive = function (doneCallback) {
            return SocketService.send('makeInactive', { workstationUuid: $rootScope.workstation.uuid }, function (r) {
                $rootScope.workstation.active = !r;
                if (doneCallback != null)
                    doneCallback(r);
                $rootScope.$apply();
            });
        }
        /* Make a workstation active - will begin accepting new work */
        service.makeActive = function (doneCallback) {
            return SocketService.send('makeActive', { workstationUuid: $rootScope.workstation.uuid }, function (r) {
                $rootScope.workstation.active = r;
                if (doneCallback != null)
                    doneCallback(r);
                $rootScope.$apply();
            });
        }
        /* Set work as being completed so it can progress to the next workflow process */
        service.completeWork = function (work, doneCallback) {
            if (!work.isArray)
                work = new Array(work);

            return SocketService.send('completeWork', { workstationUuid: $rootScope.workstation.uuid, work: work }, doneCallback);
        }

Is it a better practice to send an initial message with the open() event passing the UUID of the workstation?  Or is it better to use params?

Donghwan Kim

unread,
May 29, 2013, 2:05:28 PM5/29/13
to portal_...@googlegroups.com
Hi Ben,

If you need to send static data or identifier every per request, using params is better.

Browser side:
portal.open(url, {params: {open: {workstationUuid: $rootScope.workstation.uuid}}});
https://github.com/flowersinthesand/portal/wiki/API#params

Server side:
socket.param("workstationUuid")
https://github.com/flowersinthesand/portal-java/tree/portal-parent-0.6/core#socket

Thanks,

-- Donghwan

Ben Kuhl

unread,
Jun 4, 2013, 11:24:17 AM6/4/13
to portal_...@googlegroups.com
That's exactly what I was looking for... thanks!
Reply all
Reply to author
Forward
0 new messages