UNPKG

2.4 kBMarkdownView Raw
1
2# socket.io-client
3
4[![Build Status](https://secure.travis-ci.org/socketio/socket.io-client.svg?branch=master)](http://travis-ci.org/socketio/socket.io-client)
5[![Dependency Status](https://david-dm.org/socketio/socket.io-client.svg)](https://david-dm.org/socketio/socket.io-client)
6[![devDependency Status](https://david-dm.org/socketio/socket.io-client/dev-status.svg)](https://david-dm.org/socketio/socket.io-client#info=devDependencies)
7[![NPM version](https://badge.fury.io/js/socket.io-client.svg)](https://www.npmjs.com/package/socket.io-client)
8![Downloads](http://img.shields.io/npm/dm/socket.io-client.svg?style=flat)
9[![](http://slack.socket.io/badge.svg?)](http://slack.socket.io)
10
11[![Sauce Test Status](https://saucelabs.com/browser-matrix/socket.svg)](https://saucelabs.com/u/socket)
12
13## How to use
14
15A standalone build of `socket.io-client` is exposed automatically by the
16socket.io server as `/socket.io/socket.io.js`. Alternatively you can
17serve 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).
18
19```html
20<script src="/socket.io/socket.io.js"></script>
21<script>
22 var socket = io();
23 socket.on('connect', function(){});
24 socket.on('event', function(data){});
25 socket.on('disconnect', function(){});
26</script>
27```
28
29```js
30// with ES6 import
31import io from 'socket.io-client';
32
33const socket = io();
34```
35
36A slim build (without [debug](https://github.com/visionmedia/debug)) is also available: `socket.io.slim.js`.
37
38Socket.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)).
39
40### Node.JS (server-side usage)
41
42 Add `socket.io-client` to your `package.json` and then:
43
44 ```js
45 var socket = require('socket.io-client')('http://localhost:3000');
46 socket.on('connect', function(){});
47 socket.on('event', function(data){});
48 socket.on('disconnect', function(){});
49 ```
50
51## Debug / logging
52
53In order to see all the client debug output, run the following command on the browser console – including the desired scope – and reload your app page:
54
55```
56localStorage.debug = '*';
57```
58
59And then, filter by the scopes you're interested in. See also: https://socket.io/docs/logging-and-debugging/
60
61## API
62
63See [API](/docs/API.md)
64
65## License
66
67[MIT](/LICENSE)
68
\No newline at end of file