mirror of
https://github.com/idanoo/GoScrobble
synced 2025-07-01 21:52:19 +00:00
0.2.0 - Mid migration
This commit is contained in:
parent
139e6a915e
commit
7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions
10088
web/node_modules/eventsource/example/eventsource-polyfill.js
generated
vendored
Normal file
10088
web/node_modules/eventsource/example/eventsource-polyfill.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
40
web/node_modules/eventsource/example/index.html
generated
vendored
Normal file
40
web/node_modules/eventsource/example/index.html
generated
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
.col {
|
||||
float:left;
|
||||
width:50%;
|
||||
left:50%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class=col>
|
||||
<h2>EventSource</h2>
|
||||
<ul id=es-messages>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class=col>
|
||||
<h2>EventSourcePolyfill</h2>
|
||||
<ul id=es-polyfill-messages>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script src=/eventsource-polyfill.js></script>
|
||||
|
||||
<script>
|
||||
function subscribe(es, ul) {
|
||||
es.addEventListener('server-time', function (e) {
|
||||
var li = document.createElement("LI");
|
||||
li.appendChild(document.createTextNode(e.data));
|
||||
ul.appendChild(li);
|
||||
});
|
||||
}
|
||||
|
||||
subscribe(new EventSource('/sse'), document.getElementById('es-messages'));
|
||||
subscribe(new EventSourcePolyfill('/sse'), document.getElementById('es-polyfill-messages'));
|
||||
</script>
|
||||
</body>
|
5
web/node_modules/eventsource/example/sse-client.js
generated
vendored
Normal file
5
web/node_modules/eventsource/example/sse-client.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
var EventSource = require('..')
|
||||
var es = new EventSource('http://localhost:8080/sse')
|
||||
es.addEventListener('server-time', function (e) {
|
||||
console.log(e.data)
|
||||
})
|
29
web/node_modules/eventsource/example/sse-server.js
generated
vendored
Normal file
29
web/node_modules/eventsource/example/sse-server.js
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
const express = require('express')
|
||||
const serveStatic = require('serve-static')
|
||||
const SseStream = require('ssestream')
|
||||
|
||||
const app = express()
|
||||
app.use(serveStatic(__dirname))
|
||||
app.get('/sse', (req, res) => {
|
||||
console.log('new connection')
|
||||
|
||||
const sseStream = new SseStream(req)
|
||||
sseStream.pipe(res)
|
||||
const pusher = setInterval(() => {
|
||||
sseStream.write({
|
||||
event: 'server-time',
|
||||
data: new Date().toTimeString()
|
||||
})
|
||||
}, 1000)
|
||||
|
||||
res.on('close', () => {
|
||||
console.log('lost connection')
|
||||
clearInterval(pusher)
|
||||
sseStream.unpipe(res)
|
||||
})
|
||||
})
|
||||
|
||||
app.listen(8080, (err) => {
|
||||
if (err) throw err
|
||||
console.log('server ready on http://localhost:8080')
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue