Comparing version 0.1.5 to 0.1.6
import { Filter, News } from "./types"; | ||
import { CloseEvent, ErrorEvent } from "isomorphic-ws"; | ||
export declare class Api { | ||
@@ -6,3 +7,3 @@ private apiKey; | ||
constructor(apiKey: string, host?: string); | ||
subscribe: (filter: Filter, callback: (news: News) => void, errorCallback?: ((event: Event) => void) | undefined, closeCallback?: ((event: Event) => void) | undefined) => void; | ||
subscribe: (filter: Filter, callback: (news: News) => void, errorCallback?: ((errorEvent: ErrorEvent) => void) | undefined, closeCallback?: ((closeEvent: CloseEvent) => void) | undefined) => void; | ||
} |
@@ -5,2 +5,3 @@ "use strict"; | ||
const types_1 = require("./types"); | ||
const isomorphic_ws_1 = require("isomorphic-ws"); | ||
class Api { | ||
@@ -15,6 +16,6 @@ constructor(apiKey, host = types_1.ApiHost.Production) { | ||
}); | ||
const socket = new WebSocket(`ws://${this.host}/v1/ws/news&${urlParams.toString()}`); | ||
const socket = new isomorphic_ws_1.default(`ws://${this.host}/v1/ws/news&${urlParams.toString()}`); | ||
socket.onmessage = (event) => { | ||
console.log("Message received: ", event); | ||
callback(JSON.parse(event.data)); | ||
console.log("Message received: ", event.data); | ||
callback(JSON.parse(event.data.toString())); | ||
}; | ||
@@ -21,0 +22,0 @@ socket.onerror = (event) => { |
{ | ||
"name": "newsware", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Typescript client for interacting with the Newsware API", | ||
@@ -36,4 +36,9 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@types/ws": "^8.5.5", | ||
"typescript": "^5.1.3" | ||
}, | ||
"dependencies": { | ||
"isomorphic-ws": "^5.0.0", | ||
"ws": "^8.13.0" | ||
} | ||
} |
import {ApiHost, Filter, News} from "./types"; | ||
import Websocket, {CloseEvent, ErrorEvent, MessageEvent} from "isomorphic-ws" | ||
@@ -13,4 +14,4 @@ export class Api { | ||
callback: (news: News) => void, | ||
errorCallback?: (event: Event) => void, | ||
closeCallback?: (event: Event) => void | ||
errorCallback?: (errorEvent: ErrorEvent) => void, | ||
closeCallback?: (closeEvent: CloseEvent) => void | ||
) => { | ||
@@ -21,10 +22,10 @@ const urlParams = new URLSearchParams({ | ||
}) | ||
const socket = new WebSocket(`ws://${this.host}/v1/ws/news&${urlParams.toString()}`) | ||
const socket = new Websocket(`ws://${this.host}/v1/ws/news&${urlParams.toString()}`) | ||
socket.onmessage = (event) => { | ||
console.log("Message received: ", event) | ||
callback(JSON.parse(event.data) as News) | ||
socket.onmessage = (event: MessageEvent) => { | ||
console.log("Message received: ", event.data) | ||
callback(JSON.parse(event.data.toString()) as News) | ||
} | ||
socket.onerror = (event) => { | ||
socket.onerror = (event: ErrorEvent) => { | ||
console.log("Websocket error: ", event) | ||
@@ -35,3 +36,3 @@ if (!errorCallback) this.subscribe(filter, callback, errorCallback) | ||
socket.onclose = (event) => { | ||
socket.onclose = (event: CloseEvent) => { | ||
console.log("Connection closed") | ||
@@ -38,0 +39,0 @@ if (closeCallback) closeCallback(event) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13156
304
2
2
+ Addedisomorphic-ws@^5.0.0
+ Addedws@^8.13.0
+ Addedisomorphic-ws@5.0.0(transitive)
+ Addedws@8.18.0(transitive)