Skip to content

GinterP/cordova-websocket-clientcert

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cordova-plugin-web-socket-client-certificate

This plugin provides a custom websocket implemenation for javascript supporting client side PKCS12 certificates.

Supported platforms

  • android
  • ios

Installation

cordova plugin add https://github.com/GinterP/cordova-websocket-clientcert.git

Note

For the time being all servers are trusted

Usage

var url = 'wss://hostname:port/path';
var certFile = '/absolute/path/myCert.p12'; // absolute path of the filesystem (see https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#android-file-system-layout)
var certPass = 'Secure123';

var ws = new WebSocketClient(url, certFile, certPass);
ws.onopen = function () {
    //socket open
}

ws.onclose = function () {
    //socket closed
}

ws.onerror = function () {
    //socket error
}

ws.onmessage = function (message) {
    var data = message.data;
}

ws.send(JSON.stringify({a: 1, b: 2}), function () {
    //success callback
}, function () {
    //error callback
});

Example using "cordova-plugin-file":

resolveLocalFileSystemURL(cordova.file.applicationStorageDirectory, function (dirEntry) {
    var certPath = dirEntry.fullPath  + 'myCert.p12';
    var ws = new WebSocketClient('wss://hostname:port/path', certPath, 'somePassword');

    ...
}, console.log);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 47.7%
  • Objective-C 39.4%
  • JavaScript 12.9%