You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.1 KiB

4 years ago
  1. # socket.io-client
  2. [![Build Status](https://secure.travis-ci.org/socketio/socket.io-client.svg?branch=master)](http://travis-ci.org/socketio/socket.io-client)
  3. [![Dependency Status](https://david-dm.org/socketio/socket.io-client.svg)](https://david-dm.org/socketio/socket.io-client)
  4. [![devDependency Status](https://david-dm.org/socketio/socket.io-client/dev-status.svg)](https://david-dm.org/socketio/socket.io-client#info=devDependencies)
  5. [![NPM version](https://badge.fury.io/js/socket.io-client.svg)](https://www.npmjs.com/package/socket.io-client)
  6. ![Downloads](http://img.shields.io/npm/dm/socket.io-client.svg?style=flat)
  7. [![](http://slack.socket.io/badge.svg?)](http://slack.socket.io)
  8. [![Sauce Test Status](https://saucelabs.com/browser-matrix/socket.svg)](https://saucelabs.com/u/socket)
  9. ## How to use
  10. A standalone build of `socket.io-client` is exposed automatically by the
  11. socket.io server as `/socket.io/socket.io.js`. Alternatively you can
  12. serve the file `socket.io.js` found in the `dist` folder or include it via [CDN](https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js).
  13. ```html
  14. <script src="/socket.io/socket.io.js"></script>
  15. <script>
  16. var socket = io('http://localhost');
  17. socket.on('connect', function(){});
  18. socket.on('event', function(data){});
  19. socket.on('disconnect', function(){});
  20. </script>
  21. ```
  22. ```js
  23. // with ES6 import
  24. import io from 'socket.io-client';
  25. const socket = io('http://localhost');
  26. ```
  27. A slim build (without `JSON3`, a JSON polyfill for IE6/IE7, and `debug`) is also available: `socket.io.slim.js`.
  28. Socket.IO is compatible with [browserify](http://browserify.org/) and [webpack](https://webpack.js.org/) (see example [there](https://github.com/socketio/socket.io/tree/2.0.3/examples/webpack-build)).
  29. ### Node.JS (server-side usage)
  30. Add `socket.io-client` to your `package.json` and then:
  31. ```js
  32. var socket = require('socket.io-client')('http://localhost');
  33. socket.on('connect', function(){});
  34. socket.on('event', function(data){});
  35. socket.on('disconnect', function(){});
  36. ```
  37. ## API
  38. See [API](/docs/API.md)
  39. ## License
  40. [MIT](/LICENSE)