From bb743c42f68c4c260f40189741679f2b61a220d3 Mon Sep 17 00:00:00 2001 From: Julian Grinblat Date: Thu, 1 Mar 2018 08:29:26 +0900 Subject: [PATCH] [docs] Document connected and disconnected socket properties (#1155) --- docs/API.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/API.md b/docs/API.md index 873a00c76..b944854c1 100644 --- a/docs/API.md +++ b/docs/API.md @@ -33,6 +33,8 @@ - [Event: 'pong'](#event-pong) - [Class: io.Socket](#socket) - [socket.id](#socketid) + - [socket.connected](#socketconnected) + - [socket.disconnected](#socketdisconnected) - [socket.open()](#socketopen) - [socket.connect()](#socketconnect) - [socket.send([...args][, ack])](#socketsendargs-ack) @@ -396,6 +398,34 @@ socket.on('connect', () => { }); ``` +#### socket.connected + + - _(Boolean)_ + +Whether or not the socket is connected to the server. + +```js +const socket = io('http://localhost'); + +socket.on('connect', () => { + console.log(socket.connected); // true +}); +``` + +#### socket.disconnected + + - _(Boolean)_ + +Whether or not the socket is disconnected from the server. + +```js +const socket = io('http://localhost'); + +socket.on('connect', () => { + console.log(socket.disconnected); // false +}); +``` + #### socket.open() - **Returns** `Socket`