-
-
Save jedi4ever/fbdb4938620293bfc5a0 to your computer and use it in GitHub Desktop.
Socket.io live reload for Apple TV TVML app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'babel-polyfill'; | |
import firstView from 'views/first'; | |
import * as liveReload from 'lib/liveReload'; | |
App.onLaunch((launchOptions) => { | |
firstView(); | |
liveReload.connect(launchOptions); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io from 'socket.io-client'; | |
import * as router from 'lib/router'; | |
function resume({lastLocation}) { | |
if (!lastLocation) { return; } | |
router.goTo(lastLocation); | |
} | |
export function connect(launchOptions = {}) { | |
const socket = io(launchOptions.BASE_URL); | |
socket.on('connect', () => console.debug('Live reload: connected') ); | |
socket.on('compile', () => console.debug('Live reload: compiling, prepare for reload') ); | |
socket.on('live-reload', () => { | |
App.reload({when: 'now'}, {lastLocation: router.getLocation()}); | |
}); | |
if (launchOptions.reloadData) { | |
resume(launchOptions.reloadData || {}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
io = require('socket.io')(server); | |
io.serveClient(false); | |
io.on('connection', (socket) => { | |
console.log('socket.io connection'); | |
socket.on('event', (data) => { | |
console.log('socket.io data:', data); | |
}); | |
socket.on('disconnect', () => { | |
console.log('socket.io disconnect'); | |
}); | |
}); | |
config = { | |
module: { | |
loaders: [ | |
{ | |
test: /socket\.io\-client/, | |
// socket.io-client requires the window object, and navigator.userAgent to be present. | |
// use webpack to shim these into socket.io | |
loader: `imports?window=>{},navigator=>{userAgent: 'tvos'}`, | |
}, | |
] | |
}, | |
plugins: [ | |
function() { | |
this.plugin('compile', function() { | |
io.emit('compile'); | |
}); | |
this.plugin('done', function() { | |
io.emit('live-reload'); | |
}); | |
}, | |
], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How did you implement this in your tvml app/files, my co-worker is having a hard time to implement socket.io in tvml.