You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

ng-server-time

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-server-time

Angular web socket implementation of network time protocol

1.0.2
latest
Source
npmnpm
Version published
Weekly downloads
8
Maintainers
1
Weekly downloads
 
Created
Source

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){
    // 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();
});

FAQs

Package last updated on 08 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.