mirror of
https://github.com/Syncplay/syncplay
synced 2025-03-11 06:07:53 +00:00
update resources/syncplay.lua - improved comments
This commit is contained in:
parent
d0e18a46d0
commit
bcffded6cd
@ -1,29 +1,39 @@
|
|||||||
--[==========================================================================[
|
--[==========================================================================[
|
||||||
syncplay.lua: Syncplay interface module
|
syncplay.lua: Syncplay interface module for VLC
|
||||||
--[==========================================================================[
|
--[==========================================================================[
|
||||||
|
|
||||||
Author: Etoh
|
Author: Etoh
|
||||||
Project: http://syncplay.pl
|
Project: http://syncplay.pl/
|
||||||
|
Version: 0.0.4
|
||||||
|
|
||||||
--[==========================================================================[
|
--[==========================================================================[
|
||||||
|
|
||||||
=== Commands and response ===
|
|
||||||
= Note: ? is optional response, * is mandatory response; uses \n terminator
|
=== Commands and responses ===
|
||||||
|
= Note: ? denotes optional responses; * denotes mandatory response; uses \n terminator.
|
||||||
|
|
||||||
[On connect]
|
[On connect]
|
||||||
>> VLC version
|
>> VLC version
|
||||||
|
|
||||||
.
|
.
|
||||||
? >> inputstate-change: [<input/no-input>]
|
? >> inputstate-change: [<input/no-input>]
|
||||||
? >> filepath-change: [filepath URI]
|
? >> filepath-change-notification
|
||||||
? >> file-length: [decimal seconds]
|
|
||||||
|
|
||||||
* >> playstate: [<playing/paused/no-input>]
|
* >> playstate: [<playing/paused/no-input>]
|
||||||
* >> position: [<decimal seconds/no-input>]
|
* >> position: [<decimal seconds/no-input>]
|
||||||
|
|
||||||
get-interface-version
|
get-interface-version
|
||||||
* >> interface-version: [sncplay connector version]
|
* >> interface-version: [syncplay connector version]
|
||||||
|
|
||||||
|
get-duration
|
||||||
|
* >> duration: [<duration/no-input>]
|
||||||
|
|
||||||
|
get-filepath
|
||||||
|
* >> filepath: [<filepath/no-input>]
|
||||||
|
|
||||||
|
get-filename
|
||||||
|
* >> filepath: [<filename/no-input>]
|
||||||
|
|
||||||
set-position: [decimal seconds]
|
set-position: [decimal seconds]
|
||||||
? >> play-error: no-input
|
? >> play-error: no-input
|
||||||
|
|
||||||
@ -45,7 +55,7 @@
|
|||||||
require "common"
|
require "common"
|
||||||
require "host"
|
require "host"
|
||||||
|
|
||||||
local connectorversion = "0.0.3"
|
local connectorversion = "0.0.4"
|
||||||
|
|
||||||
local port
|
local port
|
||||||
|
|
||||||
@ -66,7 +76,18 @@ local oldinputstate
|
|||||||
local newfilepath
|
local newfilepath
|
||||||
local newinputstate
|
local newinputstate
|
||||||
|
|
||||||
|
-- Start hosting Syncplay interface.
|
||||||
|
|
||||||
|
port = tonumber(config["port"])
|
||||||
|
if (port == nil or port < 1) then port = 4123 end
|
||||||
|
|
||||||
|
vlc.msg.info("Hosting Syncplay interface on port: "..port)
|
||||||
|
|
||||||
|
h = host.host()
|
||||||
|
|
||||||
function detectchanges()
|
function detectchanges()
|
||||||
|
-- Detects changes in VLC to report to Syncplay.
|
||||||
|
-- [Used by the polll / "." command]
|
||||||
|
|
||||||
local notificationbuffer = ""
|
local notificationbuffer = ""
|
||||||
|
|
||||||
@ -96,6 +117,9 @@ function detectchanges()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function get_args (argument, argcount)
|
function get_args (argument, argcount)
|
||||||
|
-- Converts comma-space-seperated values into array of a given size, with last item absorbing all remaining data if needed.
|
||||||
|
-- [Used by the display-osd command]
|
||||||
|
|
||||||
local argarray = {}
|
local argarray = {}
|
||||||
local index
|
local index
|
||||||
local i
|
local i
|
||||||
@ -126,19 +150,10 @@ function get_args (argument, argcount)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
port = tonumber(config["port"])
|
|
||||||
if (port == nil or port < 1) then port = 4123 end
|
|
||||||
|
|
||||||
vlc.msg.info("Hosting Syncplay interface on port: "..port)
|
|
||||||
|
|
||||||
h = host.host()
|
|
||||||
|
|
||||||
-- Bypass any authentication
|
|
||||||
function on_password( client )
|
|
||||||
client:switch_status( host.status.read )
|
|
||||||
end
|
|
||||||
|
|
||||||
function get_var( vartoget )
|
function get_var( vartoget )
|
||||||
|
-- [Used by the poll / '.' command to get time]
|
||||||
|
|
||||||
local response
|
local response
|
||||||
local errormsg
|
local errormsg
|
||||||
local input = vlc.object.input()
|
local input = vlc.object.input()
|
||||||
@ -152,7 +167,10 @@ function get_var( vartoget )
|
|||||||
return response, errormsg
|
return response, errormsg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function set_var(vartoset, varvalue)
|
function set_var(vartoset, varvalue)
|
||||||
|
-- [Used by the set-time and set-rate commands]
|
||||||
|
|
||||||
local errormsg
|
local errormsg
|
||||||
local input = vlc.object.input()
|
local input = vlc.object.input()
|
||||||
|
|
||||||
@ -166,9 +184,10 @@ function set_var(vartoset, varvalue)
|
|||||||
end
|
end
|
||||||
|
|
||||||
h:listen( "localhost:"..port)
|
h:listen( "localhost:"..port)
|
||||||
-- h:listen( "*console" )
|
|
||||||
|
|
||||||
function get_play_state()
|
function get_play_state()
|
||||||
|
-- [Used by the get-playstate command]
|
||||||
|
|
||||||
local response
|
local response
|
||||||
local errormsg
|
local errormsg
|
||||||
local input = vlc.object.input()
|
local input = vlc.object.input()
|
||||||
@ -184,6 +203,8 @@ function get_play_state()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function get_filepath ()
|
function get_filepath ()
|
||||||
|
-- [Used by get-filepath command]
|
||||||
|
|
||||||
local response
|
local response
|
||||||
local errormsg
|
local errormsg
|
||||||
local item
|
local item
|
||||||
@ -212,7 +233,8 @@ function get_filepath ()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function get_filename ()
|
function get_filename ()
|
||||||
|
-- [Used by get-filename command]
|
||||||
|
|
||||||
local response
|
local response
|
||||||
local index
|
local index
|
||||||
local filename
|
local filename
|
||||||
@ -231,6 +253,8 @@ function get_filename ()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function get_duration ()
|
function get_duration ()
|
||||||
|
-- [Used by get-duration command]
|
||||||
|
|
||||||
local response
|
local response
|
||||||
local errormsg
|
local errormsg
|
||||||
local item
|
local item
|
||||||
@ -252,6 +276,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function display_osd ( argument )
|
function display_osd ( argument )
|
||||||
|
-- [Used by display-osd command]
|
||||||
local errormsg
|
local errormsg
|
||||||
local osdarray
|
local osdarray
|
||||||
local input = vlc.object.input()
|
local input = vlc.object.input()
|
||||||
@ -268,6 +293,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function do_command ( command, argument)
|
function do_command ( command, argument)
|
||||||
|
-- Processes all commands sent by Syncplay (see protocol, above).
|
||||||
|
|
||||||
if command == "." then
|
if command == "." then
|
||||||
do return detectchanges() end
|
do return detectchanges() end
|
||||||
end
|
end
|
||||||
@ -296,7 +323,10 @@ function do_command ( command, argument)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function errormerge(argument, errormsg)
|
function errormerge(argument, errormsg)
|
||||||
|
-- Used to integrate 'no-input' error messages into command responses.
|
||||||
|
|
||||||
if (errormsg ~= nil) and (errormsg ~= "") then
|
if (errormsg ~= nil) and (errormsg ~= "") then
|
||||||
do return errormsg end
|
do return errormsg end
|
||||||
end
|
end
|
||||||
@ -305,6 +335,8 @@ function errormerge(argument, errormsg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function set_playstate(argument)
|
function set_playstate(argument)
|
||||||
|
-- [Used by the set-playstate command]
|
||||||
|
|
||||||
local errormsg
|
local errormsg
|
||||||
local input = vlc.object.input()
|
local input = vlc.object.input()
|
||||||
local playstate
|
local playstate
|
||||||
@ -318,7 +350,7 @@ function set_playstate(argument)
|
|||||||
return errormsg
|
return errormsg
|
||||||
end
|
end
|
||||||
|
|
||||||
-- main loop
|
-- main loop, which alternates between writing and reading
|
||||||
while not vlc.misc.should_die() do
|
while not vlc.misc.should_die() do
|
||||||
-- accept new connections and select active clients
|
-- accept new connections and select active clients
|
||||||
local write, read = h:accept_and_select()
|
local write, read = h:accept_and_select()
|
||||||
|
Loading…
Reference in New Issue
Block a user