1
1
package io .scalajs .nodejs
2
2
package dgram
3
3
4
- import io .scalajs .RawOptions
5
- import io .scalajs .nodejs .buffer .Buffer
4
+ import com .thoughtworks .enableIf
6
5
import io .scalajs .nodejs .events .IEventEmitter
7
6
import io .scalajs .nodejs .net .Address
8
7
9
8
import scala .scalajs .js
10
9
import scala .scalajs .js .annotation .JSImport
11
- import scala .scalajs .js .|
12
10
13
11
/**
14
12
* The dgram.Socket object is an EventEmitter that encapsulates the datagram functionality.
@@ -18,7 +16,7 @@ import scala.scalajs.js.|
18
16
*/
19
17
@ js.native
20
18
@ JSImport (" dgram" , " Socket" )
21
- class Socket extends IEventEmitter {
19
+ class Socket private [ this ] () extends IEventEmitter {
22
20
23
21
/**
24
22
* Tells the kernel to join a multicast group at the given multicastAddress and multicastInterface using the
@@ -48,7 +46,13 @@ class Socket extends IEventEmitter {
48
46
* @param callback the callback
49
47
* @example bind([port][, address][, callback])
50
48
*/
51
- def bind (port : Int , address : String , callback : js.Function ): Unit = js.native
49
+ def bind (port : Int , address : String , callback : js.Function0 [Any ]): Unit = js.native
50
+ def bind (port : Int , address : String ): Unit = js.native
51
+ def bind (port : Int , callback : js.Function0 [Any ]): Unit = js.native
52
+ def bind (address : String , callback : js.Function0 [Any ]): Unit = js.native
53
+ def bind (port : Int ): Unit = js.native
54
+ def bind (callback : js.Function0 [Any ]): Unit = js.native
55
+ def bind (address : String ): Unit = js.native
52
56
53
57
/**
54
58
* For UDP sockets, causes the dgram.Socket to listen for datagram messages on a named port and optional address.
@@ -59,41 +63,44 @@ class Socket extends IEventEmitter {
59
63
* @param callback the callback
60
64
* @example bind(options[, callback])
61
65
*/
62
- def bind (options : RawOptions , callback : js.Function ): Unit = js.native
66
+ def bind (options : BindOptions , callback : js.Function = js.native ): Unit = js.native
63
67
64
- /**
65
- * For UDP sockets, causes the dgram.Socket to listen for datagram messages on a named port and optional address.
66
- * If port is not specified or is 0, the operating system will attempt to bind to a random port. If address is not
67
- * specified, the operating system will attempt to listen on all addresses. Once binding is complete, a 'listening'
68
- * event is emitted and the optional callback function is called.
69
- * @param options the optional settings
70
- * @example bind(options[, callback])
71
- */
72
- def bind (options : RawOptions ): Unit = js.native
68
+ def close (callback : js.Function = js.native): Unit = js.native
73
69
74
- /**
75
- * Broadcasts a datagram on the socket. The destination port and address must be specified.
76
- *
77
- * The msg argument contains the message to be sent. Depending on its type, different behavior can apply.
78
- * If msg is a Buffer, the offset and length specify the offset within the Buffer where the message begins
79
- * and the number of bytes in the message, respectively. If msg is a String, then it is automatically converted
80
- * to a Buffer with 'utf8' encoding. With messages that contain multi-byte characters, offset and length will
81
- * be calculated with respect to byte length and not the character position. If msg is an array, offset and
82
- * length must not be specified.
83
- * @param msg Message to be sent (<Buffer> | <String> | <Array>)
84
- * @param offset Optional. Offset in the buffer where the message starts.
85
- * @param length Optional. Number of bytes in the message.
86
- * @param port Destination port.
87
- * @param address Destination hostname or IP address.
88
- * @param callback Optional. Called when the message has been sent.
89
- * @example send(msg, [offset, length,] port, address[, callback])
90
- */
91
- def send (msg : Buffer | String | js.Array [Buffer ] | js.Array [String ],
92
- offset : Int = js.native,
93
- length : Int = js.native,
94
- port : Int ,
95
- address : String ,
96
- callback : js.Function ): Unit = js.native
70
+ @ enableIf(io.scalajs.nodejs.CompilerSwitches .gteNodeJs12)
71
+ def connect (port : Int , address : String = js.native, callback : js.Function0 [Any ] = js.native): Unit = js.native
72
+
73
+ @ enableIf(io.scalajs.nodejs.CompilerSwitches .gteNodeJs12)
74
+ def disconnect (): Unit = js.native
75
+
76
+ def dropMembership (multicastAddress : String , multicastInterface : String = js.native): Unit = js.native
77
+
78
+ def getRecvBufferSize (): Int = js.native
79
+ def getSendBufferSize (): Int = js.native
80
+
81
+ def ref (): this .type = js.native
82
+
83
+ @ enableIf(io.scalajs.nodejs.CompilerSwitches .gteNodeJs12)
84
+ def remoteAddress (): RemoteAddress = js.native
85
+
86
+ def send (msg : BufferMessage , offset : Int , length : Int , port : Int , address : String , callback : js.Function ): Unit =
87
+ js.native
88
+ def send (msg : BufferMessage , offset : Int , length : Int , port : Int , address : String ): Unit = js.native
89
+ def send (msg : BufferMessage , offset : Int , length : Int , port : Int , callback : js.Function ): Unit = js.native
90
+ def send (msg : BufferMessage , offset : Int , length : Int , address : String , callback : js.Function ): Unit = js.native
91
+ def send (msg : BufferMessage , offset : Int , length : Int , port : Int ): Unit = js.native
92
+ def send (msg : BufferMessage , offset : Int , length : Int , address : String ): Unit = js.native
93
+ def send (msg : BufferMessage , offset : Int , length : Int , callback : js.Function ): Unit = js.native
94
+ def send (msg : BufferMessage , offset : Int , length : Int ): Unit = js.native
95
+
96
+ def send (msg : Message , port : Int , address : String , callback : js.Function ): Unit = js.native
97
+ def send (msg : Message , address : String , callback : js.Function ): Unit = js.native
98
+ def send (msg : Message , port : Int , callback : js.Function ): Unit = js.native
99
+ def send (msg : Message , port : Int , address : String ): Unit = js.native
100
+ def send (msg : Message , callback : js.Function ): Unit = js.native
101
+ def send (msg : Message , port : Int ): Unit = js.native
102
+ def send (msg : Message , address : String ): Unit = js.native
103
+ def send (msg : Message ): Unit = js.native
97
104
98
105
/**
99
106
* Sets or clears the SO_BROADCAST socket option. When set to true, UDP packets may be sent to a
@@ -102,4 +109,25 @@ class Socket extends IEventEmitter {
102
109
*/
103
110
def setBroadcast (flag : Boolean ): Unit = js.native
104
111
112
+ def setMulticastInterface (multicastInterface : String ): Unit = js.native
113
+ def setMulticastLoopback (flag : Boolean ): Unit = js.native
114
+ def setMulticastTTL (ttl : Int ): Unit = js.native
115
+ def setRecvBufferSize (size : Int ): Unit = js.native
116
+ def setSendBufferSize (size : Int ): Unit = js.native
117
+ def setTTL (ttl : Int ): Unit = js.native
118
+ def unref (): this .type = js.native
119
+ }
120
+
121
+ class BindOptions (
122
+ var port : js.UndefOr [Int ] = js.undefined,
123
+ var address : js.UndefOr [String ] = js.undefined,
124
+ var exclusive : js.UndefOr [Boolean ] = js.undefined,
125
+ var fd : js.UndefOr [Int ] = js.undefined
126
+ ) extends js.Object {}
127
+
128
+ @ js.native
129
+ trait RemoteAddress extends js.Object {
130
+ var address : String = js.native
131
+ var family : String = js.native
132
+ var port : Int = js.native
105
133
}
0 commit comments