-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
export const errorCodes = { | ||
timeout: 1, | ||
transportClosed: 2, | ||
clientDisconnected: 3, | ||
clientClosed: 4, | ||
clientConnectToken: 5, | ||
clientRefreshToken: 6, | ||
subscriptionUnsubscribed: 7, | ||
subscriptionSubscribeToken: 8, | ||
subscriptionRefreshToken: 9, | ||
transportWriteError: 10, | ||
connectionClosed: 11, | ||
badConfiguration: 12, | ||
}; | ||
export enum errorCodes { | ||
timeout = 1, | ||
transportClosed = 2, | ||
clientDisconnected = 3, | ||
clientClosed = 4, | ||
clientConnectToken = 5, | ||
clientRefreshToken = 6, | ||
subscriptionUnsubscribed = 7, | ||
subscriptionSubscribeToken = 8, | ||
subscriptionRefreshToken = 9, | ||
transportWriteError = 10, | ||
connectionClosed = 11, | ||
badConfiguration = 12, | ||
} | ||
|
||
export const connectingCodes = { | ||
connectCalled: 0, | ||
transportClosed: 1, | ||
noPing: 2, | ||
subscribeTimeout: 3, | ||
unsubscribeError: 4 | ||
}; | ||
export enum connectingCodes { | ||
connectCalled = 0, | ||
transportClosed = 1, | ||
noPing = 2, | ||
subscribeTimeout = 3, | ||
unsubscribeError = 4 | ||
} | ||
|
||
export const disconnectedCodes = { | ||
disconnectCalled: 0, | ||
unauthorized: 1, | ||
badProtocol: 2, | ||
messageSizeLimit: 3 | ||
}; | ||
export enum disconnectedCodes { | ||
disconnectCalled = 0, | ||
unauthorized = 1, | ||
badProtocol = 2, | ||
messageSizeLimit = 3 | ||
} | ||
|
||
export const subscribingCodes = { | ||
subscribeCalled: 0, | ||
transportClosed: 1 | ||
}; | ||
export enum subscribingCodes { | ||
subscribeCalled = 0, | ||
transportClosed = 1 | ||
} | ||
|
||
export const unsubscribedCodes = { | ||
unsubscribeCalled: 0, | ||
unauthorized: 1, | ||
clientClosed: 2 | ||
}; | ||
export enum unsubscribedCodes { | ||
unsubscribeCalled = 0, | ||
unauthorized = 1, | ||
clientClosed = 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as protobuf from 'protobufjs/light' | ||
import * as protoJSON from './client.proto.json'; | ||
const proto = protobuf.Root.fromJSON(protoJSON); | ||
|
||
const Command = proto.lookupType('protocol.Command'); | ||
const Reply = proto.lookupType('protocol.Reply'); | ||
const EmulationRequest = proto.lookupType('protocol.EmulationRequest'); | ||
|
||
export class ProtobufCodec { | ||
name() { | ||
return 'protobuf'; | ||
} | ||
|
||
encodeEmulationRequest(req: any) { | ||
const writer = protobuf.Writer.create(); | ||
EmulationRequest.encode(req, writer); | ||
return writer.finish(); | ||
} | ||
|
||
encodeCommands(commands: any[]) { | ||
const writer = protobuf.Writer.create(); | ||
for (const i in commands) { | ||
if (commands.hasOwnProperty(i)) { | ||
const command = Object.assign({}, commands[i]); | ||
Command.encodeDelimited(command, writer); | ||
} | ||
} | ||
return writer.finish(); | ||
} | ||
|
||
decodeReplies(data: any) { | ||
const replies: any[] = []; | ||
const reader = protobuf.Reader.create(new Uint8Array(data)); | ||
while (reader.pos < reader.len) { | ||
const reply = Reply.decodeDelimited(reader); | ||
replies.push(reply); | ||
} | ||
return replies; | ||
} | ||
|
||
decodeReply(data: any) { | ||
const reader = protobuf.Reader.create(new Uint8Array(data)); | ||
while (reader.pos < reader.len) { | ||
Reply.decodeDelimited(reader); | ||
return { | ||
ok: true, | ||
pos: reader.pos | ||
}; | ||
} | ||
return { | ||
ok: false | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters