-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathip-camera.coffee
168 lines (164 loc) · 4.9 KB
/
ip-camera.coffee
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
module.exports = (env) ->
Promise = env.require 'bluebird'
assert = env.require 'cassert'
MjpegCamera = require 'mjpeg-camera'
fs = env.require 'fs'
http = require 'http'
Base = require('./base')
class IpCameraPlugin extends env.plugins.Plugin
init: (app, @framework, @config) =>
@base = new Base(@framework, @config, this,app)
deviceConfigDef = require("./device-config-schema")
@framework.deviceManager.registerDeviceClass("IpCameraDevice",{
configDef : deviceConfigDef.IpCameraDevice,
createCallback : (config) => new IpCameraDevice(config,this,@base)
})
#@framework.ruleManager.addActionProvider(new IpCameraActionProvider(@framework))
@framework.on "after init", =>
mobileFrontend = @framework.pluginManager.getPlugin 'mobile-frontend'
if mobileFrontend?
mobileFrontend.registerAssetFile 'js', "pimatic-ipcamera/app/IpCameraTempl-page.coffee"
mobileFrontend.registerAssetFile 'html', "pimatic-ipcamera/app/IpCameraTempl-template.html"
#@base.start()
return
info: (text) ->
env.logger.info text
return
error: (text) ->
env.logger.error text
return
debug: (text) ->
env.logger.debug text
return
replaceAll: (x,s,r) ->
return x.split(s).join(r)
class IpCameraDevice extends env.devices.Device
attributes:
username:
description: "User name for the access"
type: "string"
default: ""
password:
description: "password for the access"
type: "string"
default: ""
cameraUrl:
description: "URL of IP Camera"
type: "string"
filename:
description: "File name of the output"
type: "string"
width:
description: "Width of the Image"
type: "number"
default : 240
height:
description: "Height of the Image"
type: "number"
default : 160
leftURL:
description: "URL to be called to move camera left"
type: "string"
default: ""
rightURL:
description: "URL to be called to move camera right"
type: "string"
default: ""
upURL:
description: "URL to be called to move camera up"
type: "string"
default: ""
downURL:
description: "URL to be called to move camera down"
type: "string"
default: ""
actions:
streamCommand:
description: "Command for streaming"
params:
command:
type: "string"
delay:
type: "number"
otherCommand:
description: "Command for stop / capture streaming"
params:
command:
type: "string"
moveCommand:
description: "Command using a verb to move camera"
params:
direction:
type: "string"
template: 'ipcamera'
isCreateDir = false
constructor: (@config,@plugin,@base) ->
@id = @config.id
@name = @config.name
@filename = @config.filename
@refresh = @config.refresh
@cameraUrl = @config.cameraUrl
@width = @config.width
@height = @config.height
@username = @config.username
@password = @config.password
@leftURL = @config.leftURL
@rightURL = @config.rightURL
@upURL = @config.upURL
@downURL = @config.downURL
@base.add(@id,@name,@cameraUrl,@username,@password)
super()
getWidth: -> Promise.resolve(@width)
getHeight: -> Promise.resolve(@height)
getCameraUrl : -> Promise.resolve(@cameraUrl)
getRefresh : -> Promise.resolve(@refresh)
getFilename: -> Promise.resolve(@filename)
getUsername: -> Promise.resolve(@username)
getPassword: -> Promise.resolve(@password)
getLeftURL: -> Promise.resolve(@leftURL)
getRightURL: -> Promise.resolve(@rightURL)
getUpURL: -> Promise.resolve(@upURL)
getDownURL: -> Promise.resolve(@downURL)
streamCommand : (command,delay) ->
if command == "start"
@plugin.info "Start Stream for "+ @name + ",delay : "+delay
@base.streamingCapture @id,delay
otherCommand : (command) ->
if command == "stop"
@plugin.info "Stop Stream for "+ @name
@base.stopStreaming @id
else if command == "refresh"
@plugin.info "Refresh Stream for "+ @name + " ,@id: "+@id
@base.capture @id
moveCommand : (direction) ->
if direction == "left"
@plugin.info "Moving " + @id + " to the left"
@base.moveCamera(@leftURL.toString())
return
else if direction == "right"
@plugin.info "Moving " + @id + " to the right"
@base.moveCamera(@rightURL.toString())
return
else if direction == "up"
@plugin.info "Moving " + @id + " up"
@base.moveCamera(@upURL.toString())
return
else if direction == "down"
@plugin.info "Moving " + @id + " down"
@base.moveCamera(@downURL.toString())
return
else
@plugin.error "Invalid direction"
return
class IpCameraActionProvider extends env.actions.ActionProvider
constructor: (@framework)->
#env.logger.info "Masuk sini constructor"
return
executeAction: (simulate) =>
#env.logger.info "Masuk sini executeAction"
return
parseAction: (input,context)->
#env.logger.info "Masuk sini parseAction"
return
myPlugin = new IpCameraPlugin
return myPlugin