-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcommands.go
More file actions
374 lines (305 loc) · 10.1 KB
/
Copy pathcommands.go
File metadata and controls
374 lines (305 loc) · 10.1 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
package webos
import (
"github.com/mitchellh/mapstructure"
)
// Command is the type used by tv.Command to interact with the TV.
type Command string
const (
// APIServiceListCommand lists the API services available on the TV.
APIServiceListCommand Command = "ssap://api/getServiceList"
// ApplicationManagerForegroundAppCommand returns information about the forgeground app.
ApplicationManagerForegroundAppCommand Command = "ssap://com.webos.applicationManager/getForegroundAppInfo"
// ApplicationManagerListAppsCommand returns information about the forgeground app.
ApplicationManagerListAppsCommand Command = "ssap://com.webos.applicationManager/listApps"
// AudioGetVolumeCommand returns information about the TV's configured audio output volume.
AudioGetVolumeCommand Command = "ssap://audio/getVolume"
// AudioSetVolumeCommand sets the TV's configured audio output volume.
AudioSetVolumeCommand Command = "ssap://audio/setVolume"
// AudioVolumeDownCommand decrements the TV's configured audio output volume.
AudioVolumeDownCommand Command = "ssap://audio/volumeDown"
// AudioVolumeStatusCommand returns information about the TV's configured audio output volume.
// Same as AudioGetVolumeCommand.
AudioVolumeStatusCommand Command = "ssap://audio/getVolume"
// AudioVolumeUpCommand increments the TV's configured audio output volume.
AudioVolumeUpCommand Command = "ssap://audio/volumeUp"
// AudioVolumeSetMuteCommand sets/toggles muting the TV's configured audio output.
AudioVolumeSetMuteCommand Command = "ssap://audio/setMute"
// MediaControlFastForwardCommand fast forwards the current media.
MediaControlFastForwardCommand Command = "ssap://media.controls/fastForward"
// MediaControlPauseCommand pauses the current media.
MediaControlPauseCommand Command = "ssap://media.controls/pause"
// MediaControlPlayCommand plays or resumes the current media.
MediaControlPlayCommand Command = "ssap://media.controls/play"
// MediaControlRewindCommand rewinds the current media.
MediaControlRewindCommand Command = "ssap://media.controls/rewind"
// MediaControlStopCommand stops the current media.
MediaControlStopCommand Command = "ssap://media.controls/stop"
// SystemLauncherCloseCommand closes a given application.
SystemLauncherCloseCommand Command = "ssap://system.launcher/close"
// SystemLauncherGetAppStateCommand returns information about the given application state.
SystemLauncherGetAppStateCommand Command = "ssap://system.launcher/getAppState"
// SystemLauncherLaunchCommand launches the given application.
SystemLauncherLaunchCommand Command = "ssap://system.launcher/launch"
// SystemLauncherOpenCommand opens a previously launched application.
SystemLauncherOpenCommand Command = "ssap://system.launcher/open"
// SystemNotificationsCreateToastCommand creates a "toast" notification.
SystemNotificationsCreateToastCommand Command = "ssap://system.notifications/createToast"
// SystemTurnOffCommand turns the TV off.
SystemTurnOffCommand Command = "ssap://system/turnOff"
// TVChannelDownCommand changes the channel down.
TVChannelDownCommand Command = "ssap://tv/channelDown"
// TVChannelListCommand returns information about the available channels.
TVChannelListCommand Command = "ssap://tv/getChannelList"
// TVChannelUpCommand changes the channel up.
TVChannelUpCommand Command = "ssap://tv/channelUp"
// TVCurrentChannelCommand returns information about the current channel.
TVCurrentChannelCommand Command = "ssap://tv/getCurrentChannel"
// TVCurrentChannelProgramCommand returns information about the current program playing on
// the current channel.
TVCurrentChannelProgramCommand Command = "ssap://tv/getChannelProgramInfo"
GetPointerInputSocketCommand Command = "ssap://com.webos.service.networkinput/getPointerInputSocket"
KeyEnterCommand Command = "ssap://com.webos.service.ime/sendEnterKey"
)
// ServiceList returns information about the available services.
func (tv *TV) ServiceList() (*ServiceList, error) {
msg, err := tv.Command(APIServiceListCommand, nil)
if err != nil {
return nil, err
}
sl := &ServiceList{}
err = mapstructure.Decode(msg.Payload, sl)
return sl, err
}
// CurrentApp returns information about the current app.
func (tv *TV) CurrentApp() (*App, error) {
msg, err := tv.Command(ApplicationManagerForegroundAppCommand, nil)
if err != nil {
return nil, err
}
a := &App{}
err = mapstructure.Decode(msg.Payload, a)
return a, err
}
// CurrentApp returns information about the current app.
func (tv *TV) ListApps() ([]*App, error) {
msg, err := tv.Command(ApplicationManagerListAppsCommand, nil)
if err != nil {
return nil, err
}
resp := struct {
Apps []*App `json:"apps"`
}{}
err = mapstructure.Decode(msg.Payload, &resp)
return resp.Apps, err
}
// GetVolume returns information about the audio output volume.
func (tv *TV) GetVolume() (*Volume, error) {
msg, err := tv.Command(AudioGetVolumeCommand, nil)
if err != nil {
return nil, err
}
v := &Volume{}
err = mapstructure.Decode(msg.Payload, v)
return v, err
}
// SetVolume sets the audio output volume to v.
func (tv *TV) SetVolume(v int) error {
_, err := tv.Command(AudioSetVolumeCommand, Payload{"volume": v})
return err
}
// VolumeDown decrements the audio output volume.
func (tv *TV) VolumeDown() error {
_, err := tv.Command(AudioVolumeDownCommand, nil)
return err
}
// VolumeStatus returns information about the audio output volume.
func (tv *TV) VolumeStatus() (*Volume, error) {
msg, err := tv.Command(AudioVolumeStatusCommand, nil)
if err != nil {
return nil, err
}
v := &Volume{}
err = mapstructure.Decode(msg.Payload, v)
return v, err
}
// VolumeUp increments the audio output volume.
func (tv *TV) VolumeUp() error {
_, err := tv.Command(AudioVolumeUpCommand, nil)
return err
}
// Mute mutes the TV audio output.
func (tv *TV) Mute() error {
_, err := tv.Command(AudioVolumeSetMuteCommand, Payload{"mute": 1})
return err
}
// Unmute unmutes the TV audio output.
func (tv *TV) Unmute() error {
_, err := tv.Command(AudioVolumeSetMuteCommand, Payload{"mute": 0})
return err
}
// FastForward fast forwards the current media.
func (tv *TV) FastForward() error {
_, err := tv.Command(MediaControlFastForwardCommand, nil)
return err
}
// Pause pauses the current media.
func (tv *TV) Pause() error {
_, err := tv.Command(MediaControlPauseCommand, nil)
return err
}
// Play plays or resumes the current media.
func (tv *TV) Play() error {
_, err := tv.Command(MediaControlPlayCommand, nil)
return err
}
// Rewind rewinds the current media.
func (tv *TV) Rewind() error {
_, err := tv.Command(MediaControlRewindCommand, nil)
return err
}
// Stop stops the current media.
func (tv *TV) Stop() error {
_, err := tv.Command(MediaControlStopCommand, nil)
return err
}
// CloseApp closes the given app.
func (tv *TV) CloseApp(app string) error {
_, err := tv.Command(SystemLauncherCloseCommand, Payload{"id": app})
return err
}
// AppStatus returns information about the given app status.
func (tv *TV) AppStatus(app string) (*App, error) {
msg, err := tv.Command(SystemLauncherGetAppStateCommand, Payload{"id": app})
if err != nil {
return nil, err
}
a := &App{}
err = mapstructure.Decode(msg.Payload, a)
return a, err
}
// LaunchApp launches an app.
func (tv *TV) LaunchApp(app string) error {
_, err := tv.Command(SystemLauncherLaunchCommand, Payload{"id": app})
return err
}
// OpenApp switches to a previously launched/backgrounded app.
func (tv *TV) OpenApp(app string) error {
_, err := tv.Command(SystemLauncherOpenCommand, Payload{"id": app})
return err
}
// Notification creates a "toast" notification.
func (tv *TV) Notification(m string) error {
_, err := tv.Command(SystemNotificationsCreateToastCommand, Payload{"message": m})
return err
}
// Shutdown turns the TV off.
func (tv *TV) Shutdown() error {
_, err := tv.Command(SystemTurnOffCommand, nil)
return err
}
// ChannelDown decrements the current channel.
func (tv *TV) ChannelDown() error {
_, err := tv.Command(TVChannelDownCommand, nil)
return err
}
// ChannelList returns information about available channels.
// @todo implement a ChannelList type. This doesn't work on my TV.
func (tv *TV) ChannelList() (Message, error) {
return tv.Command(TVChannelListCommand, nil)
}
// ChannelUp increments the current channel.
func (tv *TV) ChannelUp() error {
_, err := tv.Command(TVChannelUpCommand, nil)
return err
}
// CurrentChannel returns information about the current channel.
// @todo implement a Channel type. This doesn't work on my TV.
func (tv *TV) CurrentChannel() (Message, error) {
return tv.Command(TVCurrentChannelCommand, nil)
}
// CurrentProgram returns information about the current program
// shown on the CurrentChannel.
// @todo implement a Program type. This doesn't work on my TV.
func (tv *TV) CurrentProgram() (Message, error) {
return tv.Command(TVCurrentChannelProgramCommand, nil)
}
func (tv *TV) KeyUp() error {
if tv.input == nil {
var err error
tv.input, err = tv.createInput()
if err != nil {
return err
}
}
tv.input.SendButton("UP")
return nil
}
func (tv *TV) KeyDown() error {
if tv.input == nil {
var err error
tv.input, err = tv.createInput()
if err != nil {
return err
}
}
tv.input.SendButton("DOWN")
return nil
}
func (tv *TV) KeyLeft() error {
if tv.input == nil {
var err error
tv.input, err = tv.createInput()
if err != nil {
return err
}
}
tv.input.SendButton("LEFT")
return nil
}
func (tv *TV) KeyRight() error {
if tv.input == nil {
var err error
tv.input, err = tv.createInput()
if err != nil {
return err
}
}
tv.input.SendButton("RIGHT")
return nil
}
func (tv *TV) KeyOk() (Message, error) {
return tv.Command(KeyEnterCommand, nil)
}
func (tv *TV) KeyEnter() error {
if tv.input == nil {
var err error
tv.input, err = tv.createInput()
if err != nil {
return err
}
}
tv.input.SendButton("ENTER")
return nil
}
func (tv *TV) KeyBack() error {
if tv.input == nil {
var err error
tv.input, err = tv.createInput()
if err != nil {
return err
}
}
tv.input.SendButton("BACK")
return nil
}
func (tv *TV) KeyHome() error {
if tv.input == nil {
var err error
tv.input, err = tv.createInput()
if err != nil {
return err
}
}
tv.input.SendButton("HOME")
return nil
}