Utility Methods API for JavaScript SDK
The methods on this page are utility methods that don't fit into other categories.
PubNubFile
Internal representation of the file used by the SDK. Depending on the environment, different methods can be used to extract the file.
Extracting the file
Methods supported in Node.js
file.toBuffer()
returnsPromise<Buffer>
file.toStream()
returnsPromise<Readable>
file.toString(encoding: string)
returns a string encoded usingencoding
(if not available, defaults toutf8
)
Methods supported in a browser
file.toFile()
returnsPromise<File>
file.toBlob()
returnsPromise<Blob>
file.toArrayBuffer()
returnsPromise<ArrayBuffer>
file.toString(encoding: string)
returns a string encoded usingencoding
(if not available, defaults toutf8
)
React and React Native
file.toBlob()
returnsPromise<Blob>
Creating a file
pubnub.File.create(input: FileInput): PubNubFile;
FileInput
represents a variety of possible inputs that represent a file in different environments.
Node.js
-
Using streams:
{
stream: Readable,
name: string,
mimeType?: string
} -
Using buffers:
{
data: Buffer,
name: string,
mimeType?: string
} -
Using strings:
{
data: string,
encoding: string,
name: string,
mimeType?: string
}
Browsers
-
Using File API:
File
-
Using strings:
{
data: string,
name: string,
mimeType?: string
} -
Using ArrayBuffer:
{
data: ArrayBuffer,
name: string,
mimeType?: string
}
Disconnect
Call the disconnect
method to force the SDK to stop all requests to PubNub server when there are active subscribe channels.
Method(s)
To disconnect
the data transmission you can use the following method(s) in JavaScript SDK.
disconnect()
This method doesn't take any arguments.
Sample code
Reconnect
Call the reconnect
method to force the SDK to try and reach out PubNub.
Method(s)
To reconnect
the data, you can use the following method(s) in JavaScript SDK.
reconnect()
This method doesn't take any arguments.
Sample code
setProxy
Call setProxy()
to instruct the SDK to assign or reassign a proxy configuration in run time. This method is only available for NodeJS.
Method(s)
To setProxy
the data you can use the following method(s) in Node.js SDK.
setProxy({String hostname, Number port, String protocol})
Parameter | Description |
---|---|
hostname *Type: String Default: n/a | Specifies the IP address the or URI to use. |
port *Type: Number Default: n/a | Specifies the port which the proxy will be listened. |
protocol Type: String Default: http | Supported Protocols are http , https , socks5 , socks4 and pac . |
Sample code
Other examples
Delete the proxy in run time