Takes no parameter, generates and returns UUIDv4↗ string
back.
var coolID = uuidv4();
console.log(`my cool universally unique ID is ${coolID}`);
This object being injected by content script at document start event and exposes socket creation functions to window.
-
string
bindAddresslocal address to bind socket
-
object
handlerscontains
onOpen
,onReceive
,onClose
event handling functionsreturns
object
udpPeer
Creates UDP socket, binds to specified address and fires onOpen
or onClose
event afterwards.
var myPeer = socketify.udpPeer(":9696", {
onOpen: function (address) {
console.log(`peer bound to <${address}>`);
},
onReceive: function (address, message) {
console.log(`peer received <${address}>: ${message}`);
},
onClose: function (error) {
if (error) {
console.log(`peer closed with error: ${error}`);
} else {
console.log(`peer closed`);
}
}
});
-
string
serverAddressserver address to connect
-
object
handlerscontains
onOpen
,onReceive
,onClose
event functionsreturns
object
tcpClient
Creates TCP socket, opens connection to server with specified address and fires onOpen
or onClose
event afterwards.
var myClient = socketify.tcpClient("127.0.0.1:9696", {
onOpen: function (address) {
console.log(`client bound to <${address}> and connected`);
},
onReceive: function (message) {
console.log(`client received: ${message}`);
},
onClose: function (error) {
if (error) {
console.log(`client closed with error: ${error}`);
} else {
console.log(`client closed`);
}
}
});
-
string
listenAddresslocal address to listen from
-
object
handlerscontains
onOpen
,onConnect
,onReceive
,onDisconnect
,onClose
event functionsreturns
object
tcpServer
Creates TCP socket, starts listening on specified address and fires onOpen
or onClose
afterwards.
var myServer = socketify.tcpServer(":9696", {
onOpen: function (address) {
console.log(`server bound to <${address}> and listening`);
},
onConnect: function (address) {
console.log(`server connected to <${address}>`);
},
onReceive: function (address, message) {
console.log(`server received <${address}>: ${message}`);
},
onDisconnect: function (address, error) {
if (error) {
console.log(`server disconnected from <${address}> with error: ${error}`);
} else {
console.log(`server disconnected from <${address}>`);
}
},
onClose: function (error) {
if (error) {
console.log(`server closed with error: ${error}`);
} else {
console.log(`server closed`);
}
}
});
UDP socket instance on browser that bridges native calls.
Unique socket id assigned by window to specify instance, primarly used to dispatch calls.
// Sample code
-
string
bindAddresslocal bound address
This function does things!
// Sample code
-
string
peerAddresssender peer address
-
object
messagemessage received from peer
This function does things!
// Sample code
-
string
error (optional)error message, will be
undefined
if socket closed withfunction
close()
This function does things!
// Sample code
-
string
peerAddresstarget peer address
-
object
messagemessage to send to peer
This function does things!
// Sample code
This function does things!
// Sample code
TCP client socket instance on browser that bridges native calls.
Unique socket id assigned by window to specify instance, primarly used to dispatch calls.
// Sample code
-
string
localAddresslocal bound address
This function does things!
// Sample code
-
object
messagemessage received from server
This function does things!
// Sample code
-
string
error (optional)error message, will be
undefined
if socket closed withfunction
close()
This function does things!
// Sample code
-
object
messagemessage to send to server
This function does things!
// Sample code
This function does things!
// Sample code
TCP server socket instance on browser that bridges native calls.
Unique socket id assigned by window to specify instance, primarly used to dispatch calls.
// Sample code
-
string
listenAddresslocal bound address
This function does things!
// Sample code
-
string
clientAddressconnected client address
This function does things!
// Sample code
-
string
clientAddresssender client address
-
object
messagemessage received from client
This function does things!
// Sample code
-
string
clientAddressdisconnected client address
-
string
error (optional)error message, will be
undefined
if connection closed withfunction
drop()
This function does things!
// Sample code
-
string
error (optional)error message, will be
undefined
if socket closed withfunction
close()
This function does things!
// Sample code
-
string
clientAddresstarget client address
-
object
messagemessage to send to client
This function does things!
// Sample code
-
string
clientAddresstarget client address
This function does things!
// Sample code
This function does things!
// Sample code