mezon-js-protobuf 1.8.85 → 1.8.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/api.ts +53 -45
- package/dist/mezon-js/api/api.d.ts +24358 -0
- package/dist/mezon-js/google/protobuf/struct.d.ts +201 -0
- package/dist/mezon-js/google/protobuf/wrappers.d.ts +238 -0
- package/dist/mezon-js/utils.d.ts +6 -2
- package/dist/mezon-js-protobuf/api/api.d.ts +487 -27
- package/dist/mezon-js-protobuf/index.d.ts +0 -1
- package/dist/mezon-js-protobuf/rtapi/realtime.d.ts +14 -14
- package/dist/mezon-js-protobuf.cjs.js +9 -613
- package/dist/mezon-js-protobuf.esm.mjs +9 -613
- package/index.ts +0 -1
- package/package.json +1 -1
- package/web_socket_adapter_pb.ts +123 -123
- package/utils.ts +0 -40
package/web_socket_adapter_pb.ts
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2020 The Mezon Authors
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import {
|
|
17
|
-
WebSocketAdapter,
|
|
18
|
-
SocketCloseHandler,
|
|
19
|
-
SocketErrorHandler,
|
|
20
|
-
SocketMessageHandler,
|
|
21
|
-
SocketOpenHandler,
|
|
22
|
-
} from "../mezon-js/web_socket_adapter";
|
|
23
|
-
import * as tsproto from "./rtapi/realtime";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A protocol buffer socket adapter that accepts and transmits payloads using the protobuf binary wire format.
|
|
27
|
-
*/
|
|
28
|
-
export class WebSocketAdapterPb implements WebSocketAdapter {
|
|
29
|
-
private _socket?: WebSocket;
|
|
30
|
-
|
|
31
|
-
constructor() {
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get onClose(): SocketCloseHandler | null {
|
|
35
|
-
return this._socket!.onclose;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
set onClose(value: SocketCloseHandler | null) {
|
|
39
|
-
this._socket!.onclose = value;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get onError(): SocketErrorHandler | null {
|
|
43
|
-
return this._socket!.onerror;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
set onError(value: SocketErrorHandler | null) {
|
|
47
|
-
this._socket!.onerror = value;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get onMessage(): SocketMessageHandler | null {
|
|
51
|
-
return this._socket!.onmessage;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
set onMessage(value: SocketMessageHandler | null) {
|
|
55
|
-
if (value) {
|
|
56
|
-
this._socket!.onmessage = (evt: MessageEvent) => {
|
|
57
|
-
const buffer: ArrayBuffer = evt.data;
|
|
58
|
-
const uintBuffer: Uint8Array = new Uint8Array(buffer);
|
|
59
|
-
const envelope = tsproto.Envelope.decode(uintBuffer);
|
|
60
|
-
|
|
61
|
-
if (envelope.channel_message) {
|
|
62
|
-
if (envelope.channel_message.code == undefined) {
|
|
63
|
-
//protobuf plugin does not default-initialize missing Int32Value fields
|
|
64
|
-
envelope.channel_message.code = 0;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
value!(envelope);
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
value = null;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
get onOpen(): SocketOpenHandler | null {
|
|
77
|
-
return this._socket!.onopen;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
set onOpen(value: SocketOpenHandler | null) {
|
|
81
|
-
this._socket!.onopen = value;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
isOpen(): boolean {
|
|
85
|
-
return this._socket?.readyState == WebSocket.OPEN;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
close() {
|
|
89
|
-
this._socket?.close();
|
|
90
|
-
this._socket = undefined;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
connect(
|
|
94
|
-
scheme: string,
|
|
95
|
-
host: string,
|
|
96
|
-
port: string,
|
|
97
|
-
createStatus: boolean,
|
|
98
|
-
token: string,
|
|
99
|
-
platform: string,
|
|
100
|
-
signal?: AbortSignal
|
|
101
|
-
): void {
|
|
102
|
-
if (signal) {
|
|
103
|
-
signal.addEventListener("abort", () => {
|
|
104
|
-
this.close();
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
const url = `${scheme}${host}:${port}/ws?lang=en&status=${encodeURIComponent(
|
|
108
|
-
createStatus.toString()
|
|
109
|
-
)}&token=${encodeURIComponent(
|
|
110
|
-
token
|
|
111
|
-
)}&format=protobuf&platform=${encodeURIComponent(platform)}`;
|
|
112
|
-
this._socket = new WebSocket(url);
|
|
113
|
-
this._socket.binaryType = "arraybuffer";
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
send(msg: any): void {
|
|
117
|
-
const envelopeWriter = tsproto.Envelope.encode(
|
|
118
|
-
tsproto.Envelope.fromPartial(msg)
|
|
119
|
-
);
|
|
120
|
-
const encodedMsg = envelopeWriter.finish();
|
|
121
|
-
this._socket!.send(encodedMsg);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2020 The Mezon Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import {
|
|
17
|
+
WebSocketAdapter,
|
|
18
|
+
SocketCloseHandler,
|
|
19
|
+
SocketErrorHandler,
|
|
20
|
+
SocketMessageHandler,
|
|
21
|
+
SocketOpenHandler,
|
|
22
|
+
} from "../mezon-js/web_socket_adapter";
|
|
23
|
+
import * as tsproto from "./rtapi/realtime";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A protocol buffer socket adapter that accepts and transmits payloads using the protobuf binary wire format.
|
|
27
|
+
*/
|
|
28
|
+
export class WebSocketAdapterPb implements WebSocketAdapter {
|
|
29
|
+
private _socket?: WebSocket;
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get onClose(): SocketCloseHandler | null {
|
|
35
|
+
return this._socket!.onclose;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
set onClose(value: SocketCloseHandler | null) {
|
|
39
|
+
this._socket!.onclose = value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get onError(): SocketErrorHandler | null {
|
|
43
|
+
return this._socket!.onerror;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
set onError(value: SocketErrorHandler | null) {
|
|
47
|
+
this._socket!.onerror = value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get onMessage(): SocketMessageHandler | null {
|
|
51
|
+
return this._socket!.onmessage;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
set onMessage(value: SocketMessageHandler | null) {
|
|
55
|
+
if (value) {
|
|
56
|
+
this._socket!.onmessage = (evt: MessageEvent) => {
|
|
57
|
+
const buffer: ArrayBuffer = evt.data;
|
|
58
|
+
const uintBuffer: Uint8Array = new Uint8Array(buffer);
|
|
59
|
+
const envelope = tsproto.Envelope.decode(uintBuffer);
|
|
60
|
+
|
|
61
|
+
if (envelope.channel_message) {
|
|
62
|
+
if (envelope.channel_message.code == undefined) {
|
|
63
|
+
//protobuf plugin does not default-initialize missing Int32Value fields
|
|
64
|
+
envelope.channel_message.code = 0;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
value!(envelope);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
value = null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get onOpen(): SocketOpenHandler | null {
|
|
77
|
+
return this._socket!.onopen;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
set onOpen(value: SocketOpenHandler | null) {
|
|
81
|
+
this._socket!.onopen = value;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
isOpen(): boolean {
|
|
85
|
+
return this._socket?.readyState == WebSocket.OPEN;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
close() {
|
|
89
|
+
this._socket?.close();
|
|
90
|
+
this._socket = undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
connect(
|
|
94
|
+
scheme: string,
|
|
95
|
+
host: string,
|
|
96
|
+
port: string,
|
|
97
|
+
createStatus: boolean,
|
|
98
|
+
token: string,
|
|
99
|
+
platform: string,
|
|
100
|
+
signal?: AbortSignal
|
|
101
|
+
): void {
|
|
102
|
+
if (signal) {
|
|
103
|
+
signal.addEventListener("abort", () => {
|
|
104
|
+
this.close();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const url = `${scheme}${host}:${port}/ws?lang=en&status=${encodeURIComponent(
|
|
108
|
+
createStatus.toString()
|
|
109
|
+
)}&token=${encodeURIComponent(
|
|
110
|
+
token
|
|
111
|
+
)}&format=protobuf&platform=${encodeURIComponent(platform)}`;
|
|
112
|
+
this._socket = new WebSocket(url);
|
|
113
|
+
this._socket.binaryType = "arraybuffer";
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
send(msg: any): void {
|
|
117
|
+
const envelopeWriter = tsproto.Envelope.encode(
|
|
118
|
+
tsproto.Envelope.fromPartial(msg)
|
|
119
|
+
);
|
|
120
|
+
const encodedMsg = envelopeWriter.finish();
|
|
121
|
+
this._socket!.send(encodedMsg);
|
|
122
|
+
}
|
|
123
|
+
}
|
package/utils.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import * as tsproto from "./api/api";
|
|
2
|
-
|
|
3
|
-
export function decodeMentions(data: any) {
|
|
4
|
-
const buffer: ArrayBuffer = data;
|
|
5
|
-
const uintBuffer: Uint8Array = new Uint8Array(buffer);
|
|
6
|
-
const mentions = tsproto.MessageMentionList.decode(uintBuffer);
|
|
7
|
-
|
|
8
|
-
return mentions;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function decodeAttachments(data: any) {
|
|
12
|
-
const buffer: ArrayBuffer = data;
|
|
13
|
-
const uintBuffer: Uint8Array = new Uint8Array(buffer);
|
|
14
|
-
const attachments = tsproto.MessageAttachmentList.decode(uintBuffer);
|
|
15
|
-
|
|
16
|
-
return attachments;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function decodeRefs(data: any) {
|
|
20
|
-
const buffer: ArrayBuffer = data;
|
|
21
|
-
const uintBuffer: Uint8Array = new Uint8Array(buffer);
|
|
22
|
-
const refs = tsproto.MessageRefList.decode(uintBuffer);
|
|
23
|
-
|
|
24
|
-
return refs;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function decodeReactions(data: any) {
|
|
28
|
-
const buffer: ArrayBuffer = data;
|
|
29
|
-
const uintBuffer: Uint8Array = new Uint8Array(buffer);
|
|
30
|
-
const reactions = tsproto.MessageReactionList.decode(uintBuffer);
|
|
31
|
-
return reactions;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function decodeNotificationFcm(data: any) {
|
|
35
|
-
const buffer: ArrayBuffer = data;
|
|
36
|
-
const uintBuffer: Uint8Array = new Uint8Array(buffer);
|
|
37
|
-
const noti = tsproto.DirectFcmProto.decode(uintBuffer);
|
|
38
|
-
|
|
39
|
-
return noti;
|
|
40
|
-
}
|