-
Notifications
You must be signed in to change notification settings - Fork 4
/
heartbeat_plugin.brs
86 lines (67 loc) · 2.08 KB
/
heartbeat_plugin.brs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Function heartbeat_Initialize(msgPort As Object, userVariables As Object, bsp as Object)
h = {}
h.name="heartbeat"
h.version=0.1
h.msgPort = msgPort
h.userVariables = userVariables
h.bsp = bsp
h.ProcessEvent=heartbeat_process_event
player = CreateObject("roDeviceInfo")
h.snum=player.GetDeviceUniqueId()
h.fw=player.GetVersion()
h.ip=""
net = CreateObject("roNetworkConfiguration", 0)
if net = invalid then
net = CreateObject("roNetworkConfiguration", 1)
endif
if net <> invalid then
h.ip = net.GetCurrentConfig().ip4_address
endif
return h
End Function
Function heartbeat_process_event(event as Object) as boolean
retval = false
if m.ip=""
print "no local IP address - heartbeat disabled"
return false
end if
if type(event) = "roAssociativeArray" then
if type(event["EventType"]) = "roString"
if (event["EventType"] = "SEND_PLUGIN_MESSAGE") then
if event["PluginName"] = "heartbeat" then
print "event heartbeat"
pluginMessage$ = event["PluginMessage"]
retval = heartbeat(pluginMessage$, m)
endif
endif
endif
endif
if type(event) = "roDatagramEvent" then
msg$ = event
retval = heartbeat(msg, m)
end if
return retval
end Function
Function heartbeat(msg as string, h as Object) as Object
print "heartbeat: ";msg;
retval=false
tag=""
if h.userVariables["heartbeat_url"]<>invalid
heartbeat_url=h.userVariables["heartbeat_url"].currentValue$
else
heartbeat_url=""
end if
if h.userVariables["heartbeat_tag"]<>invalid
tag=h.userVariables["heartbeat_tag"].currentValue$
end if
if heartbeat_url<>""
xfer = CreateObject("roUrlTransfer")
urlstring=heartbeat_url+"?serial="+h.snum+"&fw="+h.fw+"&intip="+h.ip+"&event="+msg+"&tag="+tag
print urlstring
xfer.SetURL(urlstring)
xfer.PostFromString("test")
else
print "cannot do heartbeat since no heartbeat_url user variable is defined"
endif
return retval
end Function