ng-server-time
1.0.2 • Public • Published Synchronizes local browser time with server time
using clock synchronization algorithm, similar to
NTP.
Installation
-
Ensure angular, socket.io and ng-server-time are installed correctly
npm install socket.io
npm install angular
npm install ng-server-time
-
Ensure you have an angular socket.io factory such as this one, it is required by the server time factory:
app.factory('socket', function() {
var socket = io.connect();
return socket;
});
-
Include ng-server-time-factory.min.js
:
<script src="/socket.io.js"></script>
<script src="/angular.min.js"></script>
<script src="/ng-server-time-factory.min.js"></script>
<script src="/my-angular-app.js"></script>
-
Initilaize the socket on the server:
var server_time = require('ng-server-time');
io.sockets.on('connection', function (socket) {
server_time.init(socket);
});
Usage
app.controller('MainController', function($scope, ServerTime){
$scope.now = ServerTime.now();
$scope.new = ServerTime.new();
$scope.getOffset = ServerTime.getOffset();
});
Package Sidebar
Install
Weekly Downloads