mirror of
https://github.com/brunofontes/shareit.git
synced 2025-11-15 07:50:54 -03:00
feat: broadcasting item to refresh pages
This commit is contained in:
2
resources/js/app.js
vendored
2
resources/js/app.js
vendored
@@ -5,7 +5,7 @@
|
||||
* building robust, powerful web applications using Vue and Laravel.
|
||||
*/
|
||||
|
||||
require('./bootstrap');
|
||||
import './bootstrap';
|
||||
|
||||
// window.Vue = require('vue');
|
||||
|
||||
|
||||
54
resources/js/bootstrap.js
vendored
54
resources/js/bootstrap.js
vendored
@@ -1,18 +1,5 @@
|
||||
|
||||
window._ = require('lodash');
|
||||
window.Popper = require('popper.js').default;
|
||||
|
||||
/**
|
||||
* We'll load jQuery and the Bootstrap jQuery plugin which provides support
|
||||
* for JavaScript based Bootstrap features such as modals and tabs. This
|
||||
* code may be modified to fit the specific needs of your application.
|
||||
*/
|
||||
|
||||
try {
|
||||
window.$ = window.jQuery = require('jquery');
|
||||
|
||||
require('bootstrap');
|
||||
} catch (e) {}
|
||||
import _ from 'lodash';
|
||||
window._ = _;
|
||||
|
||||
/**
|
||||
* We'll load the axios HTTP library which allows us to easily issue requests
|
||||
@@ -20,37 +7,28 @@ try {
|
||||
* CSRF token as a header based on the value of the "XSRF" token cookie.
|
||||
*/
|
||||
|
||||
window.axios = require('axios');
|
||||
import axios from 'axios';
|
||||
window.axios = axios;
|
||||
|
||||
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
|
||||
|
||||
/**
|
||||
* Next we will register the CSRF Token as a common header with Axios so that
|
||||
* all outgoing HTTP requests automatically have it attached. This is just
|
||||
* a simple convenience so we don't have to attach every token manually.
|
||||
*/
|
||||
|
||||
let token = document.head.querySelector('meta[name="csrf-token"]');
|
||||
|
||||
if (token) {
|
||||
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
|
||||
} else {
|
||||
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
|
||||
}
|
||||
|
||||
/**
|
||||
* Echo exposes an expressive API for subscribing to channels and listening
|
||||
* for events that are broadcast by Laravel. Echo and event broadcasting
|
||||
* allows your team to easily build robust real-time web applications.
|
||||
*/
|
||||
|
||||
// import Echo from 'laravel-echo'
|
||||
import Echo from 'laravel-echo';
|
||||
|
||||
// window.Pusher = require('pusher-js');
|
||||
import Pusher from 'pusher-js';
|
||||
window.Pusher = Pusher;
|
||||
|
||||
// window.Echo = new Echo({
|
||||
// broadcaster: 'pusher',
|
||||
// key: process.env.MIX_PUSHER_APP_KEY,
|
||||
// cluster: process.env.MIX_PUSHER_APP_CLUSTER,
|
||||
// encrypted: true
|
||||
// });
|
||||
window.Echo = new Echo({
|
||||
broadcaster: 'pusher',
|
||||
key: import.meta.env.VITE_PUSHER_APP_KEY,
|
||||
wsHost: import.meta.env.VITE_PUSHER_HOST ? import.meta.env.VITE_PUSHER_HOST : `ws-${import.meta.env.VITE_PUSHER_APP_CLUSTER}.pusher.com`,
|
||||
wsPort: import.meta.env.VITE_PUSHER_PORT ?? 80,
|
||||
wssPort: import.meta.env.VITE_PUSHER_PORT ?? 443,
|
||||
forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? 'https') === 'https',
|
||||
enabledTransports: ['ws', 'wss'],
|
||||
});
|
||||
|
||||
10
resources/js/pusher.js
vendored
Normal file
10
resources/js/pusher.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import 'https://js.pusher.com/7.2/pusher.min.js';
|
||||
var pusher = new Pusher('93b3e504421787295454', {
|
||||
cluster: 'us2'
|
||||
});
|
||||
|
||||
var channel = pusher.subscribe('touchedItem');
|
||||
channel.bind('RefreshPage', function(data) {
|
||||
window.location.reload();
|
||||
console.log(JSON.stringify(data));
|
||||
});
|
||||
@@ -2,15 +2,7 @@
|
||||
|
||||
@section('content')
|
||||
|
||||
<script type="text/javascript">
|
||||
setInterval(
|
||||
function() {
|
||||
if (!document.hasFocus() ) {
|
||||
window.location.reload(true);
|
||||
}
|
||||
},
|
||||
2*60000); //NOTE: period is passed in milliseconds
|
||||
</script>
|
||||
@vite('resources/js/pusher.js')
|
||||
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
@@ -53,4 +45,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@endsection
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<title>{{ config('app.name', 'Laravel') }} {{ isset($usedItems) && $usedItems > 0 ? "(${usedItems})" : '' }}</title>
|
||||
|
||||
<!-- Scripts -->
|
||||
<script src="{{ asset('js/app.js') }}" defer></script>
|
||||
@vite('resources/js/app.js')
|
||||
|
||||
<!-- Fonts -->
|
||||
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
|
||||
@@ -88,4 +88,4 @@
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user