Parameter | Type | Description |
url | string | The address of the requested connection. |
callback | function | The callback function, which is called after the connection is established, passes the socketio objects into this function. Users can define the request logic in this function. |
option | Optional; the configuration parameters. |
Type | Description |
object, containing the response result returned by ws.connect. |
import socketio from 'pts/socketio';import { check, sleep } from 'pts';import util from 'pts/util';export default function () {const res = socketio.connect('http://localhost:8080', function (socket) {socket.on('open', () => console.log('connected'));socket.on('message', (data) => console.log('message received: ', data));socket.on('binaryMessage', (data) => console.log('binaryMessage received: ', data));socket.on('close', () => console.log('disconnected'));socket.on('error', (e) => console.log('error happened', e.error()));socket.setTimeout(function () {console.log('3 seconds passed, closing the socket');socket.close();}, 3000);socket.setInterval(function () {socket.emit('message', 'interval message');socket.emit('binaryMessage', util.base64Decoding('aGVsbG8=', 'std', 'b'));socket.emit('ackMessage', 'ack message', function (msg) {console.log('received ackMessage: ', msg)})}, 500);}, {headers: {token: 'VR23EQ2R',},protocol: 'webscoket'});check('status is 200', () => res.status === 200);};