All Projects → skepticfx → Wshook

skepticfx / Wshook

Licence: mit
Easily intercept and modify WebSocket requests and message events.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Wshook

Hooked Form
Performant 2KB React library to manage your forms
Stars: ✭ 110 (-9.09%)
Mutual labels:  hooks
Spec
The AsyncAPI specification allows you to create machine-readable definitions of your asynchronous APIs.
Stars: ✭ 1,860 (+1437.19%)
Mutual labels:  websockets
Next Todos
200 lines realtime todos app powered by next.js, preact, jet, redux and now
Stars: ✭ 117 (-3.31%)
Mutual labels:  websockets
Ooui
A small cross-platform UI library that brings the simplicity of native UI development to the web
Stars: ✭ 1,530 (+1164.46%)
Mutual labels:  websockets
Anycable
Polyglot replacement for Ruby WebSocket servers with Action Cable protocol
Stars: ✭ 1,610 (+1230.58%)
Mutual labels:  websockets
Sound
🔊 A Vue composable for playing sound effects
Stars: ✭ 116 (-4.13%)
Mutual labels:  hooks
Atmosphere Javascript
atmosphere-javascript
Stars: ✭ 108 (-10.74%)
Mutual labels:  websockets
Websockets
WebSockets Inception
Stars: ✭ 120 (-0.83%)
Mutual labels:  websockets
React Tensorflow
Tensorflow hooks for React.js
Stars: ✭ 115 (-4.96%)
Mutual labels:  hooks
Hooks
Async middleware for JavaScript and TypeScript
Stars: ✭ 117 (-3.31%)
Mutual labels:  hooks
Lefthook
Fast and powerful Git hooks manager for any type of projects.
Stars: ✭ 1,848 (+1427.27%)
Mutual labels:  hooks
Ventas
Clojure ecommerce platform
Stars: ✭ 114 (-5.79%)
Mutual labels:  websockets
Hooks
A high-quality & reliable React Hooks library.
Stars: ✭ 7,841 (+6380.17%)
Mutual labels:  hooks
Use Conditional Effect
React.useEffect, except you can pass a comparison function.
Stars: ✭ 111 (-8.26%)
Mutual labels:  hooks
Php Wss
Web-socket server/client with multi-process and parse templates support on server and send/receive options on client
Stars: ✭ 117 (-3.31%)
Mutual labels:  websockets
Colyseus Examples
Colyseus Game Server examples for learning purposes
Stars: ✭ 109 (-9.92%)
Mutual labels:  websockets
Omega
Real-time issue tracker optimized for small teams
Stars: ✭ 115 (-4.96%)
Mutual labels:  websockets
Go Realtime Collaborative Drawing App
A simple real-time collaborative drawing app built with Go
Stars: ✭ 121 (+0%)
Mutual labels:  websockets
Mphx
A little library to let you make multiplayer games easily with Haxe. No longer maintained and better options are available.
Stars: ✭ 118 (-2.48%)
Mutual labels:  websockets
Webpack Hot Client
webpack HMR Client
Stars: ✭ 116 (-4.13%)
Mutual labels:  websockets

wsHook

Easily intercept and modify WebSocket requests and message events.

ToDo

Figure out if we still need immutable MessageEvent

Usage

1. Download and include wsHook.js in your WebSocket client

<script src='wsHook.js'></script>

2. Define the before and after hooks

Define your custom before and after hooks on the globally exposed wsHook object.

wsHook.before = function(data, url, wsObject) {
    console.log("Sending message to " + url + " : " + data);
}

// Make sure your program calls `wsClient.onmessage` event handler somewhere.
wsHook.after = function(messageEvent, url, wsObject) {
    console.log("Received message from " + url + " : " + messageEvent.data);
    return messageEvent;
}

// if you do not want to propagate the MessageEvent further down, just return null
wsHook.after = function(messageEvent, url, wsObject) {
 console.log("Received message from " + url + " : " + messageEvent.data);
 // This example can ping-pong forever, so maybe use some conditions
 wsObject.send("Intercepted and sent again")
 return null;
}

3. Let your program play with WebSockets

var wsClient = new WebSocket("wss://echo.websocket.org");

wsClient.onopen = function() {
    wsClient.send("Echo this");
}

wsClient.onmessage = function(e){
  console.log(e);
}

API

wsHook.before - function(data, url, wsObject):

Invoked just before calling the actual WebSocket's send() method.

This method must return data which can be modified as well.

wsHook.after - function(event, url, wsObject):

Invoked just after receiving the MessageEvent from the WebSocket server and before calling the WebSocket's onmessage Event Handler.

This method must return event whose properties can be modified as well. You might be interested in modiying, event.data or event.origin usually.

The wsObject refers to the corresponding WebSocket object used. You can use this to send a message to the server. This allows one to fully hijack the WebSocket connection programatically.

If you do not want the user's original onmessage event handler to be called, just return null.

Overview

Example

// Load wsHook.js
// Define the 'before' and 'after' hooks as you wish.

wsHook.before = function(data, url, wsObject){
  data += "_modified";
  console.log("Modifying data to " + data);
  return data;
}

var wsClient = new WebSocket("wss://echo.websocket.org");
wsClient.onopen = function() {
  wsClient.send("Echo this");
}
wsClient.onmessage = function(e){
  console.log(e);
}

Used by

  • Hookish: Hooks in to interesting functions and helps reverse the web app faster.

TODO

  • Test cases for common WebSocket libraries.

License

The MIT License (MIT)

Copyright (c) 2015 Ahamed Nafeez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].