Skip to content

Commit

Permalink
Merge pull request berty#3020 from n0izn0iz/fix-medias-eof
Browse files Browse the repository at this point in the history
fix(messenger): replace EOF checks
  • Loading branch information
n0izn0iz authored Jan 20, 2021
2 parents a2d17e4 + e046002 commit 201c7bb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
19 changes: 8 additions & 11 deletions js/packages/components/settings/DevTools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { ScreenProps, useNavigation } from '@berty-tech/navigation'
import * as middleware from '@berty-tech/grpc-bridge/middleware'
import beapi from '@berty-tech/api'
import { bridge as rpcBridge } from '@berty-tech/grpc-bridge/rpc'
import { EOF, Service } from '@berty-tech/grpc-bridge'
import { Service } from '@berty-tech/grpc-bridge'
import GoBridge from '@berty-tech/go-bridge'
import messengerMethodsHooks from '@berty-tech/store/methods'
import { useAccount, useMsgrContext } from '@berty-tech/store/hooks'
import { SwipeNavRecognizer } from '../shared-components/SwipeNavRecognizer'
import { Player } from '@react-native-community/audio-toolkit'
import { playSound } from '../sounds'
import { MessengerActions, PersistentOptionsKeys } from '@berty-tech/store/context'
import Long from 'long'

//
// DevTools
Expand Down Expand Up @@ -81,11 +82,7 @@ const NativeCallButton: React.FC = () => {
__DEV__ ? middleware.logger.create('MESSENGER') : null, // eslint-disable-line
)

const messengerClient: any = Service(
beapi.messenger.MessengerService,
rpcBridge,
messengerMiddlewares,
)
const messengerClient = Service(beapi.messenger.MessengerService, rpcBridge, messengerMiddlewares)
const { t } = useTranslation()
let i = 0
return (
Expand All @@ -101,10 +98,10 @@ const NativeCallButton: React.FC = () => {
messengerClient
.echoTest({
echo: `hello number #${n}`,
delay: 1000,
delay: Long.fromNumber(1000),
})
.then((stream: any) => {
stream.onMessage((res: any) => {
.then((stream) => {
stream.onMessage((res) => {
if (res) {
Vibration.vibrate(500)
}
Expand All @@ -113,8 +110,8 @@ const NativeCallButton: React.FC = () => {
setTimeout(stream.stop, 10000)
return stream.start()
})
.catch((err: Error) => {
if (err === EOF) {
.catch((err) => {
if (err?.EOF) {
console.info(`end of the EchoTest stream #${n}`)
} else if (err) {
console.warn(err)
Expand Down
3 changes: 1 addition & 2 deletions js/packages/components/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Buffer } from 'buffer'
import { EOF } from '@berty-tech/grpc-bridge'
import { WelshProtocolServiceClient } from '@berty-tech/grpc-bridge/welsh-clients.gen'

let cache: { cid: string; prom: Promise<string> }[] = []
Expand All @@ -17,7 +16,7 @@ const fetchSource = async (
const data = await new Promise<Buffer>((resolve, reject) => {
let buf = Buffer.from('')
stream.onMessage((msg, err) => {
if (err === EOF) {
if (err?.EOF) {
resolve(buf)
return
}
Expand Down
8 changes: 4 additions & 4 deletions js/packages/store/providerEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import beapi from '@berty-tech/api'
import { reducerAction } from '@berty-tech/store/providerReducer'
import { ServiceClientType } from '@berty-tech/grpc-bridge/welsh-clients.gen'
import i18n from '@berty-tech/berty-i18n'
import { EOF, Service } from '@berty-tech/grpc-bridge'
import { Service } from '@berty-tech/grpc-bridge'
import GoBridge, { GoBridgeDefaultOpts, GoBridgeOpts } from '@berty-tech/go-bridge'

import ExternalTransport from './externalTransport'
Expand Down Expand Up @@ -298,7 +298,7 @@ export const openingClients = (
cancel = () => stream.stop()
stream.onMessage((msg, err) => {
if (err) {
// if (err === EOF) {
// if (err.EOF) {
// return
// }
// console.warn('events stream onMessage error:', err)
Expand Down Expand Up @@ -356,8 +356,8 @@ export const openingClients = (
})
await stream.start()
})
.catch((err: Error) => {
if (err === EOF) {
.catch((err) => {
if (err?.EOF) {
console.info('end of the events stream')
dispatch({ type: MessengerActions.SetStateClosed })
} else {
Expand Down
4 changes: 2 additions & 2 deletions js/packages/store/services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MsgrState } from './context'
import { Alert } from 'react-native'
import { useAccount } from './hooks'
import * as middleware from '@berty-tech/grpc-bridge/middleware'
import { EOF, Service } from '@berty-tech/grpc-bridge'
import { Service } from '@berty-tech/grpc-bridge'
import { bridge as rpcBridge } from '@berty-tech/grpc-bridge/rpc'
import RNFS from 'react-native-fs'
import RNFetchBlob from 'rn-fetch-blob'
Expand Down Expand Up @@ -187,7 +187,7 @@ export const exportAccountToFile = async () => {
})
})
.catch(async (err) => {
if (err === EOF) {
if (err?.EOF) {
} else {
console.warn(err)
}
Expand Down

0 comments on commit 201c7bb

Please sign in to comment.