Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* Sends a message to the reply channel.
*
* @param {Object} action The message
*
* @example
* Stream("myStream", ws).send({prop1: 'value1', prop2: 'value2'});
*/
send(action) {
const msg = {
stream: this.name,
payload: action,
};
this.socket.send(JSON.stringify(msg));
}
}
defineEventAttribute(Stream.prototype, "open");
defineEventAttribute(Stream.prototype, "close");
defineEventAttribute(Stream.prototype, "error");
defineEventAttribute(Stream.prototype, "message");
/**
* Bridge between Channels and plain javascript.
*
* @example
* const webSocketBridge = new WebSocketBridge();
* webSocketBridge.connect("http://example.com/ws/");
* webSocketBridge.addEventListener("message", function(event) {
* console.log(event.data);
* });
*/
export class WebSocketBridge extends Forwarder {
constructor(options) {
* @param {Object} action The message
*
* @example
* Stream("myStream", ws).send({prop1: 'value1', prop2: 'value2'});
*/
send(action) {
const msg = {
stream: this.name,
payload: action,
};
this.socket.send(JSON.stringify(msg));
}
}
defineEventAttribute(Stream.prototype, "open");
defineEventAttribute(Stream.prototype, "close");
defineEventAttribute(Stream.prototype, "error");
defineEventAttribute(Stream.prototype, "message");
/**
* Bridge between Channels and plain javascript.
*
* @example
* const webSocketBridge = new WebSocketBridge();
* webSocketBridge.connect("http://example.com/ws/");
* webSocketBridge.addEventListener("message", function(event) {
* console.log(event.data);
* });
*/
export class WebSocketBridge extends Forwarder {
constructor(options) {
super();
this.socket = null;
this.dispatchEvent(event)
}
private handleWebsocketInfo = ({
id,
info
}: IClientTopics['websocketInfo']) => {
if (id !== this.id) return
Object.keys(info).forEach(key => (this[key] = info[key]))
}
}
defineEventAttribute(WebSocket.prototype, 'close')
defineEventAttribute(WebSocket.prototype, 'error')
defineEventAttribute(WebSocket.prototype, 'message')
defineEventAttribute(WebSocket.prototype, 'open')
this.dispatchEvent(event)
}
private handleWebsocketInfo = ({
id,
info
}: IClientTopics['websocketInfo']) => {
if (id !== this.id) return
Object.keys(info).forEach(key => (this[key] = info[key]))
}
}
defineEventAttribute(WebSocket.prototype, 'close')
defineEventAttribute(WebSocket.prototype, 'error')
defineEventAttribute(WebSocket.prototype, 'message')
defineEventAttribute(WebSocket.prototype, 'open')
/**
* Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
*/
public get aborted(): boolean {
const aborted = abortedFlags.get(this)
if (typeof aborted !== "boolean") {
throw new TypeError(
`Expected 'this' to be an 'AbortSignal' object, but got ${
this === null ? "null" : typeof this
}`,
)
}
return aborted
}
}
defineEventAttribute(AbortSignal.prototype, "abort")
/**
* Create an AbortSignal object.
*/
export function createAbortSignal(): AbortSignal {
const signal = Object.create(AbortSignal.prototype)
EventTarget.call(signal)
abortedFlags.set(signal, false)
return signal
}
/**
* Abort a given signal.
*/
export function abortSignal(signal: AbortSignal): void {
if (abortedFlags.get(signal) !== false) {
constructor() {
super();
throw new TypeError("AbortSignal cannot be constructed directly");
}
/**
* Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
*/
get aborted() {
const aborted = abortedFlags.get(this);
if (typeof aborted !== "boolean") {
throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this === null ? "null" : typeof this}`);
}
return aborted;
}
}
eventTargetShim.defineEventAttribute(AbortSignal.prototype, "abort");
/**
* Create an AbortSignal object.
*/
function createAbortSignal() {
const signal = Object.create(AbortSignal.prototype);
eventTargetShim.EventTarget.call(signal);
abortedFlags.set(signal, false);
return signal;
}
/**
* Abort a given signal.
*/
function abortSignal(signal) {
if (abortedFlags.get(signal) !== false) {
return;
}
* @example
* webSocketBridge.stream('mystream').send({prop1: 'value1', prop2: 'value1'})
*/
stream(streamName) {
let stream;
if (this.streams[streamName] !== undefined) {
stream = this.streams[streamName];
} else {
stream = new Stream(streamName, this.socket);
this.streams[streamName] = stream;
}
return stream;
}
}
defineEventAttribute(WebSocketBridge.prototype, "open");
defineEventAttribute(WebSocketBridge.prototype, "close");
defineEventAttribute(WebSocketBridge.prototype, "error");
defineEventAttribute(WebSocketBridge.prototype, "message");
].forEach(name => defineEventAttribute(OpusMediaRecorder.prototype, name));
: new Event(type, rest)
this.dispatchEvent(event)
}
private handleWebsocketInfo = ({
id,
info
}: IClientTopics['websocketInfo']) => {
if (id !== this.id) return
Object.keys(info).forEach(key => (this[key] = info[key]))
}
}
defineEventAttribute(WebSocket.prototype, 'close')
defineEventAttribute(WebSocket.prototype, 'error')
defineEventAttribute(WebSocket.prototype, 'message')
defineEventAttribute(WebSocket.prototype, 'open')
}
private handleWebsocketInfo = ({
id,
info
}: IClientTopics['websocketInfo']) => {
if (id !== this.id) return
Object.keys(info).forEach(key => (this[key] = info[key]))
}
}
defineEventAttribute(WebSocket.prototype, 'close')
defineEventAttribute(WebSocket.prototype, 'error')
defineEventAttribute(WebSocket.prototype, 'message')
defineEventAttribute(WebSocket.prototype, 'open')