tSIP: showing window on BLF change

Lua "on BLF (dialog-info) change" script showing application window when contact(s) state changed to early or confirmed.
Function ApplicationShow() used here was added in tSIP 0.3.1.2.

local execSourceType = GetExecSourceType()	-- 7 = BLF state change
if execSourceType ~= 7 then
	print("Unexpected context for BLF state script!\n")
	return
end
local contactId = GetExecSourceId()			-- contact id in this context

local number, state = GetBlfState(contactId)

--[[
for state value:
enum dialog_info_status {
	DIALOG_INFO_UNKNOWN = 0,		///< not subscribed / subscription failed
	DIALOG_INFO_TERMINATED,
	DIALOG_INFO_EARLY,
	DIALOG_INFO_CONFIRMED
};
If contactId is out of range (e.g. there is no subscription) then value = -1 is returned.
This is unexpected in script running on event though.
]]

-- number might be used to limit contacts for which action is executed
-- print(string.format("on_blf_state: number %s state = %d\n", number, state))

if state == 2 or state == 3 then	-- early + confirmed states
	-- let's limit frequency
	local currentTime = os.time()
	print ("currentTime: " .. currentTime .. "\n")
	local variableName = "OnBlfStatePlaTime"
	local prevTime, prevTimeIsSet = GetVariable(variableName)
	if prevTimeIsSet ~= 0 then
		print(string.format("prevTime = %s\n", prevTime))
		prevTime = tonumber(prevTime)
		if currentTime - prevTime < 2 then
			-- skip action
			print("Skipping show - 2 seconds not passed\n")
			return
		else
			print(string.format("delta = %d\n", currentTime - prevTime))
		end
	else
		print("prevTime not set\n")
	end

	SetVariable(variableName, currentTime)
	ApplicationShow(false) -- show without grabbing focus
end

Back to howto list.


 "Cookie monsters": 7741452    Parse time: 0.001 s