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

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})
* 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, https, socks5, socks4 and pac.

Sample code


Other examples

Delete the proxy in run time


Last updated on