How to use streamr-client-protocol - 5 common examples

To help you get started, we’ve selected a few streamr-client-protocol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github streamr-dev / streamr-client-javascript / src / StreamrClient.js View on Github external
this.connection.on('error', (err) => {
            // If there is an error parsing a json message in a stream, fire error events on the relevant subs
            if (err instanceof Errors.InvalidJsonError) {
                const stream = this._getSubscribedStreamPartition(err.streamMessage.getStreamId(), err.streamMessage.getStreamPartition())
                if (stream) {
                    stream.getSubscriptions().forEach((sub) => sub.handleError(err))
                } else {
                    debug('WARN: InvalidJsonError received for stream with no subscriptions: %s', err.streamId)
                }
            } else {
                // if it looks like an error emit as-is, otherwise wrap in new Error
                const errorObject = (err && err.stack && err.message) ? err : new Error(err)
                this.emit('error', errorObject)
                console.error(errorObject)
            }
        })
    }
github streamr-dev / streamr-client-javascript / src / ResendUtil.js View on Github external
deleteDoneSubsByResponse(response) {
        // TODO: replace with response.requestId
        if (response.type === ControlLayer.ResendResponseResent.TYPE || response.type === ControlLayer.ResendResponseNoResend.TYPE) {
            delete this.subForRequestId[response.requestId]
        }
    }
github streamr-dev / streamr-client-javascript / src / AbstractSubscription.js View on Github external
handleError(err) {
        /**
         * If parsing the (expected) message failed, we should still mark it as received. Otherwise the
         * gap detection will think a message was lost, and re-request the failing message.
         */
        if (err instanceof Errors.InvalidJsonError && err.streamMessage && this.orderingUtil) {
            this.orderingUtil.markMessageExplicitly(err.streamMessage)
        }
        this.emit('error', err)
    }
github streamr-dev / streamr-client-javascript / src / Connection.js View on Github external
this.socket.onmessage = (messageEvent) => {
            try {
                const websocketResponse = WebsocketResponse.deserialize(messageEvent.data)
                this.emit(websocketResponse.constructor.getMessageName(), websocketResponse)
            } catch (err) {
                this.emit('error', err)
            }
        }
github streamr-dev / streamr-client-javascript / src / StreamrClient.js View on Github external
_requestPublish(streamMessage, sessionToken) {
        const request = ControlLayer.PublishRequest.create(streamMessage, sessionToken)
        debug('_requestPublish: %o', request)
        return this.connection.send(request)
    }

streamr-client-protocol

JavaScript classes implementing the Streamr client-to-node protocol

Apache-2.0
Latest version published 2 years ago

Package Health Score

61 / 100
Full package analysis

Similar packages