-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBroadSignAction.js
106 lines (79 loc) · 2.94 KB
/
BroadSignAction.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// jQuery BroadSign Player API
// Plugin by Frank JE Flitton
// https://github.com/FrankFlitton/jQuery-BroadSign-Player-API
// Initiate connection to broadsign server
var BroadSignSocket = new WebSocket("ws://localhost:2324");
console.log("BroadSign Socket Init");
var BSState = "";
(function($) {
$.fn.BroadSignState = function( options ) {
if (BroadSignSocket.readyState == 0) {
BSState = "CONNECTING";
} else if (BroadSignSocket.readyState == 1) {
BSState = "OPEN";
} else if (BroadSignSocket.readyState == 2) {
BSState = "CLOSING";
} else if (BroadSignSocket.readyState == 3) {
BSState = "CLOSED";
} else {
};
console.log("BroadSign Socket Status: " + BSState);
};
}(jQuery));
// Print state of Websocket to console, for debugging purposes
$.fn.BroadSignState();
// Listen and print to console
BroadSignSocket.onmessage = function (WSMessage) {
console.log("BroadSign Socket Message: " + WSMessage.data);
};
// Listen and print to console
BroadSignSocket.onopen = function (WSMessage) {
console.log("BroadSign Socket Status: OPEN");
};
BroadSignSocket.onclose = function (WSMessage) {
console.log("BroadSign Socket Status: CLOSED");
};
BroadSignSocket.onerror = function (WSMessage) {
console.log("BroadSign Socket Status: ERROR");
};
(function($) {
$.fn.BroadSignAction = function( options ) {
console.log("Start BroadSign Socket Call");
// Print state of Websocket to console, for debugging purposes
$.fn.BroadSignState();
// Unix time stamp for unique calls as default
var callID = new Date().getTime();
// Establish our default settings
var settings = {
"action" : "stop",
"frame_id" : null,
"enabled" : null,
"name" : null,
"id" : callID
};
// User Overides
var userSettings = $.extend(settings, options);
// Validation
var callId = "id=\"" + userSettings.id + "\" ";
var callAction = "action=\"" + userSettings.action + "\" ";
var callFrame_id = "";
if (null != userSettings.frame_id) {
var callFrame_id = "frame_id=\"" + userSettings.frame_id + "\" ";
}
var callEnabled = "";
if (null != userSettings.enabled) {
var callEnabled = "enabled=\"" + userSettings.enabled + "\" ";
}
var callName = "";
if (null != userSettings.name) {
var callName = "name=\"" + userSettings.name + "\" ";
}
// Package to send to BroadSign
var callXML = "<rc version=\"1\" " + callId + callAction + callFrame_id + callEnabled + callName + "/>\r\n\r\n";
// Frameid is ommitted. Not needed as content is fullscreen.
console.log("To send: " + callXML);
BroadSignSocket.send(callXML);
console.log("Sent");
return this;
};
}(jQuery));