Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-ws

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-ws - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

2

package.json
{
"name": "koa-ws",
"version": "0.2.0",
"version": "0.2.1",
"keywords": [

@@ -5,0 +5,0 @@ "koa",

@@ -45,2 +45,13 @@ [![Build Status](https://secure.travis-ci.org/mekwall/koa-ws.png)](http://travis-ci.org/mekwall/koa-ws) [![Coverage Status](https://img.shields.io/coveralls/mekwall/koa-ws.svg)](https://coveralls.io/r/mekwall/koa-ws) [![Dependency Status](https://david-dm.org/mekwall/koa-ws.png)](https://david-dm.org/mekwall/koa-ws)

Register a method on the client to recieve the session:
koaws.register('session', function (err, payload) {
if (err) console.error('Something went wrong', err);
console.log(payload) // should include our session
});
Connect to the server:
koaws.connect();
Call the method from the client:

@@ -47,0 +58,0 @@

@@ -26,6 +26,11 @@ (function(){

var scriptElements = document.getElementsByTagName('script');
var guessedAddress = typeof __resourceQuery === "string" && __resourceQuery ?
__resourceQuery.substr(1) :
scriptElements[scriptElements.length-1].getAttribute("src").replace(/\/[^\/]+$/, "");
try {
var scriptElements = document.getElementsByTagName('script');
var guessedAddress = typeof __resourceQuery === "string" && __resourceQuery ?
__resourceQuery.substr(1) :
scriptElements[scriptElements.length-1].getAttribute("src").replace(/\/[^\/]+$/, "");
} catch (e) {
var guessedAddress = typeof __resourceQuery === "string" && __resourceQuery ?
__resourceQuery.substr(1) : 'localhost:3000';
}

@@ -84,12 +89,18 @@ function Client() {

var payload = JSON.parse(e.data || e);
if (payload.method) {
debug('← %s: %o', payload.method, payload.params);
if (payload.method) {
var request = new Request(this, payload);
if (payload.error) {
debug('Got error for method %s, code %s: %s',
payload.method, payload.error.code, payload.error.message);
if (typeof this._methods[payload.method] === 'undefined') {
debug('← (%s) Missing handler', payload.method);
} else if (payload.error) {
debug('← (%s) Error %s: %o', payload.method, payload.error.code, payload.error.message);
this._methods[payload.method].apply(
request,
payload.params
[payload.error, payload.params]
);
} else {
debug('← (%s) %o', payload.method, payload.params);
this._methods[payload.method].apply(
request,
[null, payload.params]
);
}

@@ -106,4 +117,2 @@ } else {

debug('← Error %s: %o', payload.error.code, payload.error.message);
//client.emit('error', payload.error);
//console.error('Error %s: %s', payload.error.code, payload.error.message);
} else if (payload.id && this._awaitingResults[payload.id]) {

@@ -143,5 +152,6 @@ debug('← (%s) %o', payload.id, payload.result);

Client.prototype.register = function (method, handler) {
if (typeof method === 'object') {
for (var name in methods) {
this.register(name, method[name]);
if (typeof handler === 'object') {
for (var name in handler) {
debug('Registering method: %s:%s', method, name);
this._methods[method + ':' + name] = handler[name];
}

@@ -148,0 +158,0 @@ } else {

@@ -45,5 +45,5 @@ var fs = require('fs');

app.ws.register('user', {
create: function* () { this.respond('ok'); },
update: function* () { this.respond('ok'); },
delete: function* () { this.respond('ok'); }
create: function* () { this.result('ok'); },
update: function* () { this.result('ok'); },
delete: function* () { this.result('ok'); }
});

@@ -68,2 +68,3 @@

client = require('../src/client');
client.connect();
client.on('open', function () {

@@ -103,3 +104,3 @@ done();

});
client.send({ foo: 'bar' });
client.socket.send({ foo: 'bar' });
});

@@ -113,3 +114,3 @@

});
client.send(JSON.stringify({ foo: 'bar' }));
client.socket.send(JSON.stringify({ foo: 'bar' }));
});

@@ -116,0 +117,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc