https://github.com/mfbx9da4/ng-server-time
Time synchronization directive between angular and node server using socket.io. Emulating NTP protocol.
https://github.com/mfbx9da4/ng-server-time
angular ntp socket
Last synced: about 2 months ago
JSON representation
Time synchronization directive between angular and node server using socket.io. Emulating NTP protocol.
- Host: GitHub
- URL: https://github.com/mfbx9da4/ng-server-time
- Owner: mfbx9da4
- Created: 2016-03-11T19:57:06.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-04-29T21:10:22.000Z (about 7 years ago)
- Last Synced: 2025-01-26T17:45:46.569Z (4 months ago)
- Topics: angular, ntp, socket
- Language: JavaScript
- Homepage: http://ng-server-time.herokuapp.com/
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ng Server Time
Synchronizes local browser time with server time
using clock synchronization algorithm, similar to
NTP.## [Demo](http://ng-server-time.herokuapp.com/)
## [Demo code](https://github.com/mfbx9da4/ng-server-time-example)## Installation
1. Ensure angular, socket.io and ng-server-time are installed correctly
```
npm install socket.io
npm install angular
npm install ng-server-time
```2. Ensure you have an angular socket.io factory such as this one, it is required by the server time factory:
```js
app.factory('socket', function() {
var socket = io.connect();
return socket;
});
```
3. Include `ng-server-time-factory.min.js`:```html
```
4. Initilaize the socket on the server:```js
var server_time = require('ng-server-time');io.sockets.on('connection', function (socket) {
server_time.init(socket);
});
```###Usage
```js
app.controller('MainController', function($scope, ServerTime){
// Date.now() on the server
$scope.now = ServerTime.now();// new Date() on the server
$scope.new = ServerTime.new();// get offset in milliseconds between current browser
// time and server time
$scope.getOffset = ServerTime.getOffset();
});
```