On this page

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() returns Promise<Buffer>
  • file.toStream() returns Promise<Readable>
  • file.toString(encoding: string) returns a string encoded using encoding (if not available, defaults to utf8)
Methods supported in a browser​
  • file.toFile() returns Promise<File>
  • file.toBlob() returns Promise<Blob>
  • file.toArrayBuffer() returns Promise<ArrayBuffer>
  • file.toString(encoding: string) returns a string encoded using encoding (if not available, defaults to utf8)
React and React Native​
  • file.toBlob() returns Promise<Blob>

Creating a file​

1pubnub.File.create(input: FileInput): PubNubFile;

FileInput represents a variety of possible inputs that represent a file in different environments.

Node.js​

  • Using streams:

    1{
    2 stream: Readable,
    3 name: string,
    4 mimeType?: string
    5}
  • Using buffers:

    1{
    2 data: Buffer,
    3 name: string,
    4 mimeType?: string
    5}
  • Using strings:

    1{
    2 data: string,
    3 encoding: string,
    4 name: string,
    5 mimeType?: string
    6}

Browsers​

  • Using File API:

    1File
  • Using strings:

    1{
    2 data: string,
    3 name: string,
    4 mimeType?: string
    5}
  • Using ArrayBuffer:

    1{
    2 data: ArrayBuffer,
    3 name: string,
    4 mimeType?: string
    5}

Disconnect​

Call the disconnect method 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.

1disconnect()

This method doesn't take any arguments.

Sample code​

1

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.

1reconnect()

This method doesn't take any arguments.

Sample code​

1

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.

1setProxy({String hostname, Number port, String protocol})
* required
ParameterDescription
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 and https.

Sample code​

1

Other examples​

Delete the proxy in run time​

1