How to use tcp protocol in ionic

I tried to use this code TCP sockets in ionic in my ionic 2 app but it says can not read property sockets of undefined.
Anyone can help me to solve this problem and to understand how to use chrome.tcp.socket plugin?

I am using and it works fine (only works on devices)