项目作者: Scientific-Guy

项目描述 :
A custom socket for deno to add custom headers!
高级语言: TypeScript
项目地址: git://github.com/Scientific-Guy/custom-socket.git
创建时间: 2021-03-25T14:47:24Z
项目社区:https://github.com/Scientific-Guy/custom-socket

开源协议:MIT License

下载


Custom Socket

As of current deno version, deno does not supports adding custom headers to the socket beacause deno follows the js web standards. So for people who want custom headers. Here is a module for it.
This module helps you to add custom headers something like this

This package is made for some development issues. If you find bugs report an issue or create an pull request.

  1. import WS from "https://raw.githubusercontent.com/scientific-dev/custom-socket/main/mod.ts";
  2. const headers = {
  3. Authorization: "Bearer token"
  4. };
  5. const ws = new WS("wss://somedomain.com", headers);
  6. ws.onopen = (ev: Event) => console.log('Socket has been opened');
  7. ws.onmessage = (ev: MessageEvent) => console.log(ev.data);
  8. ws.onclose = (ev: CloseEvent) => console.log('Socket has been closed');
  9. ws.onerror = (ev: ErrorEvent) => console.log(ev.errior);

This package uses the codes of std@0.68.0/ws"">https://deno.land/std@0.68.0/ws and uses the latest updated standard libraries and a better WebSocket implementation for it.