LrSocket.bind and getFolders
Hello,
i want to write a little application to remote control LR CC, just switch on the second screen an show the next or the last picture.
Therefor i want to read out the catalog-info of my lightroom-catalog. This part is quite easy, but when i connect via socket, it isn't possible to load the folders of the catalog:.
Here is my code, it's a sample from Adobe ( thanks ), i removed anything i did not realy need, until yet.
--------------------------------8<----------------------------
local LrDialogs = import "LrDialogs"
local LrFunctionContext = import "LrFunctionContext"
local LrTasks = import "LrTasks"
local LrApplication = import "LrApplication"
local LrSelection = import "LrSelection"
local LrDevelopController = import "LrDevelopController"
local LrSocket = import "LrSocket"
local LrTableUtils = import "LrTableUtils"
local LrApplicationView = import "LrApplicationView"
local LrLogger = import "LrLogger"
local LrBinding = import "LrBinding"
local LrView = import "LrView"
-- Port numbers
-- port zero indicates that we want the OS to auto-assign the port
local AUTO_PORT = 0
-- port number used to send change notifications local
local sendPort = AUTO_PORT
-- port number used to receive commands
local receivePort = 59999 -- AUTO_PORT
--------------------------------------------------------------------------------
local myLogger = LrLogger( 'libraryLogger' )
myLogger:enable( "logfile" ) -- or "logfile"
local function outputToLog( message )
myLogger:trace( message )
end
local function parseMessage( data )
if type( data ) == "string" then
local _, _, key, value = string.find( data, "([^ ]+)%s*=%s*(.*)" )
return key, value
end
end
--------------------------------------------------------------------------------
local function maybeStartService()
if senderPort and receiverPort then
LrTasks.startAsyncTask( function()
for countDown = 10, 1, -1 do
if not _G.running then
break
end
if senderConnected and receiverConnected then
break
end
local msg = "Connect to port:"
if not receiverConnected then
msg = string.format( "%s\nReceiver = %d", msg, receiverPort )
end
if not senderConnected then
msg = string.format( "%s\nSender = %d", msg, senderPort )
end
msg = string.format("%s\n%d", msg, countDown )
LrDialogs.showBezel( msg, 1 )
LrTasks.sleep( 1 )
end
end )
end
end
local function makeReceiverSocket( context )
LrDialogs.attachErrorDialogToFunctionContext( context )
--getCatalog('makeSocket')
local receiver = LrSocket.bind {
functionContext = context,
port = receivePort,
mode = "receive",
plugin = _PLUGIN,
onConnecting = function( socket, port )
receiverPort = port
maybeStartService()
end,
onConnected = function( socket, port )
receiverConnected = true
end,
onClosed = function( socket )
_G.running = false
end,
onMessage = function( socket, message )
outputToLog('got message')
getCatalog('onMessage')
outputToLog('got message2')
end,
onError = function( socket, err )
if err == "timeout" then
socket:reconnect()
end
end,
}
LrDevelopController.revealAdjustedControls( true )
return receiver
end
local function showCustomDialog()
outputToLog("function showCustomDialog")
end
local function getCatalog(name)
outputToLog(string.format ("-----------> %s",name ))
local mycatalog = LrApplication.activeCatalog()
local myfolder = mycatalog:getFolders()
local path = mycatalog:getPath()
outputToLog( "found catalog:" .. path )
outputToLog ( string.format("catalog type = %s",mycatalog:type()) )
for i, v in ipairs (myfolder) do
outputToLog(string.format ("i %d %s",i,v.type()))
outputToLog(string.format ("i %d %s %s",i,v:getName(),v:getPath()))
end
outputToLog(string.format ("-----------> %s",name ))
end
--------------------------------------------------------------------------------
outputToLog( "Start LUA V2 1" )
LrTasks.startAsyncTask( function()
LrFunctionContext.callWithContext( 'socket_remote', function( context )
context:addFailureHandler(function(status, error)
LrDialogs.message("INTERNAL ERROR", error, "critical")
end)
getCatalog('Start')
local receiver = makeReceiverSocket( context )
LrDialogs.showBezel( "Controller Demo Running" )
_G.running = true
while _G.running do
LrTasks.sleep( 3 ) -- seconds
end
_G.shutdown = true
if receiverConnected then
receiver:close()
end
LrDialogs.showBezel( "Remote Connections Closed", 4 )
end )
end )
--------------------------------8<----------------------------
The Log file shows:
2018-04-22 12:44:09 +0000, TRACE -----------> Start
2018-04-22 12:44:09 +0000, TRACE found catalog:/Users/boni/Pictures/ImageTherapie/ImageTherapy/ImageTherapy-2.lrcat
2018-04-22 12:44:09 +0000, TRACE catalog type = LrCatalog
2018-04-22 12:44:09 +0000, TRACE i 1 LrFolder
2018-04-22 12:44:09 +0000, TRACE i 1 lr-test /Users/boni/lr-test
2018-04-22 12:44:09 +0000, TRACE i 2 LrFolder
2018-04-22 12:44:09 +0000, TRACE i 2 Downloads /Users/boni/Downloads
2018-04-22 12:44:09 +0000, TRACE i 3 LrFolder
2018-04-22 12:44:09 +0000, TRACE i 3 Import /Users/boni/Pictures/ImageTherapie/Import
2018-04-22 12:44:09 +0000, TRACE i 4 LrFolder
2018-04-22 12:44:09 +0000, TRACE i 4 2018 /Volumes/TOSHIBA/2018
2018-04-22 12:44:09 +0000, TRACE i 5 LrFolder
2018-04-22 12:44:09 +0000, TRACE i 5 Alltagsgegensta<CC><88>nde /Volumes/Untitled/Alltagsgegensta<CC><88>nde
2018-04-22 12:44:09 +0000, TRACE i 6 LrFolder
2018-04-22 12:44:09 +0000, TRACE i 6 Medion USB Flash _ ARalla /Volumes/Medion USB Flash _ ARalla
2018-04-22 12:44:09 +0000, TRACE -----------> Start
2018-04-22 12:44:27 +0000, TRACE got message
So you can see, the getFolder() works , but when i send a message ( via nc localhost 59999) , i see my message in the log ( got message ) but the function getCatalog return nothing, not even an error 🙂
Any Idea?
Thanks Detlev.