SymphonyElectron/demo/index.html

215 lines
7.0 KiB
HTML
Raw Normal View History

<html>
<head>
</head>
<body>
<h1>Symphony Electron API Demo</h1>
<hr>
<p>Notifications:<p>
<button id='notf'>show notification</button>
<p>
<label for='title'>title:</label>
<input type='text' id='title' value='Notification Demo'/>
</p>
<p>
<label for='body'>body:</label>
<input type='text' id='body' value='Some message'/>
</p>
<p>
<label for='image'>image url:</label>
<input type='text' id='image' value='https://lh3.googleusercontent.com/-s2PXL6wWMCc/AAAAAAAAAAI/AAAAAAAAAAA/AAomvV2gUNMMeFsOijwVVpihfg_anpKWQA/s32-c-mo/photo.jpg'/>
</p>
<p>
<label for='flash'>flash:</label>
<input type='checkbox' id='flash'/>
</p>
2017-03-29 22:11:08 -05:00
<p>
<label for='sticky'>sticky:</label>
<input type='checkbox' id='sticky'/>
</p>
<p>
<label for='color'>color:</label>
<input type='text' id='color' value='white'/>
2017-03-29 22:11:08 -05:00
</p>
<p>
<label for='tag'>tag:</label>
<input type='text' id='tag' value=''/>
</p>
<button id='open-config-win'>Open configure window</button>
<br>
<hr>
<p>Badge Count:<p>
<button id='inc-badge'>increment badge count</button>
<br>
<button id='clear-badge'>clear badge count</button>
<br>
<hr>
<p>Screen Snippet:</p>
<button id='snippet'>get snippet</button>
<p>snippet output:</p>
<image id='snippet-img'/>
2017-04-18 11:02:25 -05:00
<hr>
<p>Window activate:</p>
<button id='open-win'>open window</button>
<button id='bring-to-front'>bring open window to front</button>
2017-05-05 12:02:35 -05:00
<hr>
<p>Get Media Sources:</p>
<button id='get-sources'>get entire desktop</button>
<br>
<video id='video'></video>
<hr>
<p>Get Version Info:</p>
<button id='get-version'>get version info</button>
<br>
Version Info:<span id='info'></span>
</body>
<script>
var openConfigWin = document.getElementById('open-config-win');
openConfigWin.addEventListener('click', function() {
ssf.showNotificationSettings();
});
var notfEl = document.getElementById('notf');
2017-03-29 19:42:15 -05:00
var num = 0;
// note: notification will close when clicked
notfEl.addEventListener('click', function() {
var title = document.getElementById('title').value;
var body = document.getElementById('body').value;
var imageUrl = document.getElementById('image').value;
var shouldFlash = document.getElementById('flash').checked;
2017-03-29 22:11:08 -05:00
var shouldStick = document.getElementById('sticky').checked;
var color = document.getElementById('color').value;
2017-03-29 22:11:08 -05:00
var tag = document.getElementById('tag').value;
2017-03-29 19:42:15 -05:00
num++;
2017-05-08 12:46:56 -05:00
var notf = new ssf.Notification(title, {
2017-03-29 22:11:08 -05:00
body: (body + ' num=' + num + ' tag=' + tag),
image: imageUrl,
flash: shouldFlash,
2017-03-28 19:04:21 -05:00
color: color || 'white',
2017-03-29 22:11:08 -05:00
sticky: shouldStick,
2017-03-28 19:04:21 -05:00
data: {
hello: 'hello word'
2017-03-29 19:42:15 -05:00
},
2017-03-29 22:11:08 -05:00
tag: tag
});
2017-03-29 19:42:15 -05:00
notf.addEventListener('click', onclick);
function onclick(event) {
2017-04-03 18:50:35 -05:00
event.target.close();
alert('notification clicked: ' + event.target.data.hello);
2017-03-29 19:42:15 -05:00
}
2017-03-29 19:42:15 -05:00
notf.addEventListener('close', onclose);
function onclose() {
alert('notification closed');
2017-03-29 19:42:15 -05:00
};
notf.addEventListener('error', onerror);
function onerror(event) {
alert('error=' + event.result);
};
});
var badgeCount = 0;
var incBadgeEl = document.getElementById('inc-badge');
incBadgeEl.addEventListener('click', function() {
badgeCount++;
2017-05-08 12:46:56 -05:00
ssf.setBadgeCount(badgeCount);
});
var incBadgeEl = document.getElementById('clear-badge');
incBadgeEl.addEventListener('click', function() {
badgeCount = 0;
2017-05-08 12:46:56 -05:00
ssf.setBadgeCount(0);
});
var snippetButton = document.getElementById('snippet');
snippetButton.addEventListener('click', function() {
2017-05-08 12:46:56 -05:00
let snippet = new ssf.ScreenSnippet();
snippet
.capture()
.then(gotSnippet)
.catch(snippetError);
function gotSnippet(rsp) {
if (rsp && rsp.data && rsp.type) {
var dataUrl = 'data:' + rsp.type + ',' + rsp.data;
var img = document.getElementById('snippet-img');
img.src = dataUrl;
}
}
function snippetError(err) {
alert('error getting snippet' + err);
}
});
2017-04-18 11:02:25 -05:00
var win;
2017-04-18 11:02:25 -05:00
var openWinButton = document.getElementById('open-win');
openWinButton.addEventListener('click', function() {
win = window.open('win.html?x=100&y=100', 'test-window', 'height=800,width=400');
2017-04-18 11:02:25 -05:00
});
var front = document.getElementById('bring-to-front');
front.addEventListener('click', function() {
2017-05-08 12:46:56 -05:00
window.ssf.activate(win.name);
2017-04-18 11:02:25 -05:00
});
// register callback to be notified when size/position changes for win.
2017-05-08 12:46:56 -05:00
ssf.registerBoundsChange(onBoundsChange);
function onBoundsChange(arg) {
console.log('bounds changed for=', arg)
}
2017-05-05 12:02:35 -05:00
var getSources = document.getElementById('get-sources');
getSources.addEventListener('click', function() {
2017-05-08 12:46:56 -05:00
ssf.getMediaSources({types: ['window', 'screen']}, function(error, sources) {
2017-05-05 12:02:35 -05:00
if (error) throw error
navigator.webkitGetUserMedia({
audio: false,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: sources[0].id,
minWidth: 1280,
maxWidth: 1280,
minHeight: 720,
maxHeight: 720
}
}
}, handleStream, handleError)
});
});
function handleStream (stream) {
document.querySelector('video').src = URL.createObjectURL(stream)
}
function handleError (e) {
console.log(e)
}
var getSources = document.getElementById('get-version');
getSources.addEventListener('click', function() {
ssf.getVersionInfo().then(function(verInfo) {
var verEl = document.getElementById('info');
verEl.innerText = '\napi ver=' + verInfo.apiVer +
'\ncontainer identifier=' + verInfo.containerIdentifier +
'\ncontainer ver=' + verInfo.containerVer
})
});
2017-05-05 12:02:35 -05:00
</script>
</html>