Skip to content

Commit 0937fcf

Browse files
author
Tim Berners-Lee
committed
should work - untested
1 parent 7dd4be4 commit 0937fcf

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/infiniteMessageArea.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,17 @@ module.exports = function (dom, kb, subject, options) {
194194
sendButton.addEventListener('click', ev => sendMessage(), false)
195195
rhs.appendChild(sendButton)
196196

197+
const chatDocument = chatDocumentFromDate(new Date())
198+
var imageDoc
199+
function getImageDoc () {
200+
imageDoc = kb.sym(chatDocument.dir().uri + 'Image_' + Date.now() + '.png')
201+
return imageDoc
202+
}
203+
function tookPicture () {
204+
sendMessage(imageDoc.uri)
205+
}
206+
rhs.appendChild(UI.media.cameraButton(dom, kb, getImageDoc, tookPicture))
207+
197208
UI.pad.recordParticipation(subject, subject.doc()) // participation =
198209
} // turn on inpuut
199210

src/media-capture.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ var UI = {
3333
/** A control to capture a picture using camera
3434
* @param {Docuemnt} dom - The Document object
3535
* @param {IndexedForumla} store - The quadstore to store data in
36-
* @param {NamedNode} destination - NN of the image file to be created
36+
* @param {NamedNode} getImageDoc() - NN of the image file to be created
3737
* @param {function} doneCallback - Called when a picture has been taken
3838
*/
39-
function cameraCaptureControl (dom, store, destination, doneCallback) {
39+
function cameraCaptureControl (dom, store, getImageDoc, doneCallback) {
4040
const div = dom.createElement('div')
4141
const player = div.appendChild(dom.createElement('video'))
4242
const controlStyle = 'border-radius: 0.5em; margin: 0.8em; width: 320; height:240;'
@@ -70,8 +70,9 @@ function cameraCaptureControl (dom, store, destination, doneCallback) {
7070
canvas.toBlob(blob => {
7171
let msg = `got blob type ${blob.type} size ${blob.size}`
7272
console.log(msg)
73+
let destination = getImageDoc()
7374
saveBlob(blob, destination)
74-
alert(msg)
75+
// alert(msg)
7576
}, contentType) // toBlob
7677
}
7778

@@ -81,6 +82,7 @@ function cameraCaptureControl (dom, store, destination, doneCallback) {
8182
console.log('Putting ' + blob.size + ' bytes of ' + contentType + ' to ' + destination)
8283
store.fetcher.webOperation('PUT', destination.uri, {data: blob, contentType: contentType}).then(resp => {
8384
console.log('ok saved ' + destination)
85+
doneCallback(destination)
8486
alert('saved ok: ' + destination)
8587
}, err => {
8688
alert(err)
@@ -100,23 +102,25 @@ function cameraCaptureControl (dom, store, destination, doneCallback) {
100102
/** A button to capture a picture using camera
101103
* @param {Docuemnt} dom - The Document object
102104
* @param {IndexedForumla} store - The quadstore to store data in
103-
* @param {NamedNode} destination - NN of the image file to be created
105+
* @param {fuunction} getImageDoc - returns NN of the image file to be created
106+
* @param {function<Node>} doneCallback - called with the image taken
104107
* @returns {DomElement} - A div element with the buton in it
105108
*
106109
* This expacts the buttton to a large control when it is pressed
107110
*/
108-
function cameraButton (dom, store, destination) {
111+
function cameraButton (dom, store, getImageDoc, doneCallback) {
109112
const div = dom.createElement('div')
110113
const but = UI.widgets.button(dom, UI.icons.iconBase + 'noun_383448.svg', 'Take picture')
111114
var control
112-
function restoreButton () {
115+
function restoreButton (imageDoc) {
113116
div.removeChild(control)
114117
div.appendChild(but)
118+
doneCallback(imageDoc)
115119
}
116120
div.appendChild(but)
117121
but.addEventListener('click', event => {
118122
div.removeChild(but)
119-
control = control || cameraCaptureControl(dom, store, destination, restoreButton)
123+
control = control || cameraCaptureControl(dom, store, getImageDoc, restoreButton)
120124
div.appendChild(control)
121125
})
122126
return div

0 commit comments

Comments
 (0)