livekit-client 0.17.3 → 0.17.6-rc1

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.
Files changed (155) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +26 -20
  3. package/dist/api/SignalClient.d.ts +1 -0
  4. package/dist/connect.d.ts +2 -0
  5. package/dist/index.d.ts +2 -2
  6. package/dist/livekit-client.esm.js +17344 -0
  7. package/dist/livekit-client.esm.js.map +1 -0
  8. package/dist/livekit-client.umd.js +17388 -0
  9. package/dist/livekit-client.umd.js.map +1 -0
  10. package/dist/logger.d.ts +22 -11
  11. package/dist/options.d.ts +4 -2
  12. package/dist/proto/google/protobuf/timestamp.d.ts +12 -2
  13. package/dist/proto/livekit_models.d.ts +524 -17
  14. package/dist/proto/livekit_rtc.d.ts +3449 -31
  15. package/dist/room/DeviceManager.d.ts +1 -1
  16. package/dist/room/RTCEngine.d.ts +1 -1
  17. package/dist/room/Room.d.ts +2 -2
  18. package/dist/room/events.d.ts +1 -1
  19. package/dist/room/participant/LocalParticipant.d.ts +9 -5
  20. package/dist/room/participant/RemoteParticipant.d.ts +9 -0
  21. package/dist/room/track/RemoteAudioTrack.d.ts +11 -0
  22. package/dist/room/track/options.d.ts +1 -1
  23. package/dist/test/mocks.d.ts +11 -0
  24. package/dist/version.d.ts +1 -1
  25. package/package.json +41 -16
  26. package/.eslintrc.js +0 -17
  27. package/.gitmodules +0 -3
  28. package/dist/api/RequestQueue.js +0 -61
  29. package/dist/api/RequestQueue.js.map +0 -1
  30. package/dist/api/SignalClient.js +0 -428
  31. package/dist/api/SignalClient.js.map +0 -1
  32. package/dist/connect.js +0 -130
  33. package/dist/connect.js.map +0 -1
  34. package/dist/index.js +0 -71
  35. package/dist/index.js.map +0 -1
  36. package/dist/logger.js +0 -24
  37. package/dist/logger.js.map +0 -1
  38. package/dist/options.js +0 -3
  39. package/dist/options.js.map +0 -1
  40. package/dist/proto/google/protobuf/timestamp.js +0 -93
  41. package/dist/proto/google/protobuf/timestamp.js.map +0 -1
  42. package/dist/proto/livekit_models.js +0 -2688
  43. package/dist/proto/livekit_models.js.map +0 -1
  44. package/dist/proto/livekit_rtc.js +0 -2995
  45. package/dist/proto/livekit_rtc.js.map +0 -1
  46. package/dist/room/DeviceManager.js +0 -62
  47. package/dist/room/DeviceManager.js.map +0 -1
  48. package/dist/room/PCTransport.js +0 -91
  49. package/dist/room/PCTransport.js.map +0 -1
  50. package/dist/room/RTCEngine.js +0 -562
  51. package/dist/room/RTCEngine.js.map +0 -1
  52. package/dist/room/Room.js +0 -759
  53. package/dist/room/Room.js.map +0 -1
  54. package/dist/room/errors.js +0 -68
  55. package/dist/room/errors.js.map +0 -1
  56. package/dist/room/events.js +0 -385
  57. package/dist/room/events.js.map +0 -1
  58. package/dist/room/participant/LocalParticipant.js +0 -647
  59. package/dist/room/participant/LocalParticipant.js.map +0 -1
  60. package/dist/room/participant/Participant.js +0 -189
  61. package/dist/room/participant/Participant.js.map +0 -1
  62. package/dist/room/participant/ParticipantTrackPermission.js +0 -16
  63. package/dist/room/participant/ParticipantTrackPermission.js.map +0 -1
  64. package/dist/room/participant/RemoteParticipant.js +0 -194
  65. package/dist/room/participant/RemoteParticipant.js.map +0 -1
  66. package/dist/room/participant/publishUtils.js +0 -189
  67. package/dist/room/participant/publishUtils.js.map +0 -1
  68. package/dist/room/participant/publishUtils.test.d.ts +0 -1
  69. package/dist/room/participant/publishUtils.test.js +0 -118
  70. package/dist/room/participant/publishUtils.test.js.map +0 -1
  71. package/dist/room/stats.js +0 -26
  72. package/dist/room/stats.js.map +0 -1
  73. package/dist/room/track/LocalAudioTrack.js +0 -153
  74. package/dist/room/track/LocalAudioTrack.js.map +0 -1
  75. package/dist/room/track/LocalTrack.js +0 -158
  76. package/dist/room/track/LocalTrack.js.map +0 -1
  77. package/dist/room/track/LocalTrackPublication.js +0 -64
  78. package/dist/room/track/LocalTrackPublication.js.map +0 -1
  79. package/dist/room/track/LocalVideoTrack.js +0 -297
  80. package/dist/room/track/LocalVideoTrack.js.map +0 -1
  81. package/dist/room/track/LocalVideoTrack.test.d.ts +0 -1
  82. package/dist/room/track/LocalVideoTrack.test.js +0 -68
  83. package/dist/room/track/LocalVideoTrack.test.js.map +0 -1
  84. package/dist/room/track/RemoteAudioTrack.js +0 -64
  85. package/dist/room/track/RemoteAudioTrack.js.map +0 -1
  86. package/dist/room/track/RemoteTrack.js +0 -49
  87. package/dist/room/track/RemoteTrack.js.map +0 -1
  88. package/dist/room/track/RemoteTrackPublication.js +0 -178
  89. package/dist/room/track/RemoteTrackPublication.js.map +0 -1
  90. package/dist/room/track/RemoteVideoTrack.js +0 -201
  91. package/dist/room/track/RemoteVideoTrack.js.map +0 -1
  92. package/dist/room/track/Track.js +0 -276
  93. package/dist/room/track/Track.js.map +0 -1
  94. package/dist/room/track/TrackPublication.js +0 -92
  95. package/dist/room/track/TrackPublication.js.map +0 -1
  96. package/dist/room/track/create.js +0 -131
  97. package/dist/room/track/create.js.map +0 -1
  98. package/dist/room/track/defaults.js +0 -21
  99. package/dist/room/track/defaults.js.map +0 -1
  100. package/dist/room/track/options.js +0 -100
  101. package/dist/room/track/options.js.map +0 -1
  102. package/dist/room/track/types.js +0 -3
  103. package/dist/room/track/types.js.map +0 -1
  104. package/dist/room/track/utils.js +0 -113
  105. package/dist/room/track/utils.js.map +0 -1
  106. package/dist/room/track/utils.test.d.ts +0 -1
  107. package/dist/room/track/utils.test.js +0 -85
  108. package/dist/room/track/utils.test.js.map +0 -1
  109. package/dist/room/utils.js +0 -79
  110. package/dist/room/utils.js.map +0 -1
  111. package/dist/version.js +0 -6
  112. package/dist/version.js.map +0 -1
  113. package/jest.config.js +0 -6
  114. package/src/api/RequestQueue.ts +0 -53
  115. package/src/api/SignalClient.ts +0 -499
  116. package/src/connect.ts +0 -100
  117. package/src/index.ts +0 -47
  118. package/src/logger.ts +0 -22
  119. package/src/options.ts +0 -149
  120. package/src/proto/google/protobuf/timestamp.ts +0 -222
  121. package/src/proto/livekit_models.ts +0 -3019
  122. package/src/proto/livekit_rtc.ts +0 -3677
  123. package/src/room/DeviceManager.ts +0 -57
  124. package/src/room/PCTransport.ts +0 -86
  125. package/src/room/RTCEngine.ts +0 -652
  126. package/src/room/Room.ts +0 -943
  127. package/src/room/errors.ts +0 -65
  128. package/src/room/events.ts +0 -424
  129. package/src/room/participant/LocalParticipant.ts +0 -734
  130. package/src/room/participant/Participant.ts +0 -269
  131. package/src/room/participant/ParticipantTrackPermission.ts +0 -32
  132. package/src/room/participant/RemoteParticipant.ts +0 -243
  133. package/src/room/participant/publishUtils.test.ts +0 -145
  134. package/src/room/participant/publishUtils.ts +0 -225
  135. package/src/room/stats.ts +0 -130
  136. package/src/room/track/LocalAudioTrack.ts +0 -137
  137. package/src/room/track/LocalTrack.ts +0 -161
  138. package/src/room/track/LocalTrackPublication.ts +0 -66
  139. package/src/room/track/LocalVideoTrack.test.ts +0 -70
  140. package/src/room/track/LocalVideoTrack.ts +0 -293
  141. package/src/room/track/RemoteAudioTrack.ts +0 -58
  142. package/src/room/track/RemoteTrack.ts +0 -62
  143. package/src/room/track/RemoteTrackPublication.ts +0 -198
  144. package/src/room/track/RemoteVideoTrack.ts +0 -235
  145. package/src/room/track/Track.ts +0 -337
  146. package/src/room/track/TrackPublication.ts +0 -120
  147. package/src/room/track/create.ts +0 -121
  148. package/src/room/track/defaults.ts +0 -23
  149. package/src/room/track/options.ts +0 -281
  150. package/src/room/track/types.ts +0 -20
  151. package/src/room/track/utils.test.ts +0 -93
  152. package/src/room/track/utils.ts +0 -115
  153. package/src/room/utils.ts +0 -70
  154. package/src/version.ts +0 -2
  155. package/tsconfig.eslint.json +0 -11
package/src/connect.ts DELETED
@@ -1,100 +0,0 @@
1
- import log, { LogLevel, setLogLevel } from './logger';
2
- import {
3
- ConnectOptions,
4
- } from './options';
5
- import { MediaDeviceFailure } from './room/errors';
6
- import { RoomEvent } from './room/events';
7
- import Room from './room/Room';
8
-
9
- export { version } from './version';
10
-
11
- /**
12
- * Connects to a LiveKit room, shorthand for `new Room()` and [[Room.connect]]
13
- *
14
- * ```typescript
15
- * connect('wss://myhost.livekit.io', token, {
16
- * // publish audio and video tracks on joining
17
- * audio: true,
18
- * video: true,
19
- * captureDefaults: {
20
- * facingMode: 'user',
21
- * },
22
- * })
23
- * ```
24
- * @param url URL to LiveKit server
25
- * @param token AccessToken, a JWT token that includes authentication and room details
26
- * @param options
27
- */
28
- export async function connect(
29
- url: string,
30
- token: string,
31
- options?: ConnectOptions,
32
- ): Promise<Room> {
33
- options ??= {};
34
- if (options.adaptiveStream === undefined) {
35
- options.adaptiveStream = options.autoManageVideo === true ? {} : undefined;
36
- }
37
- setLogLevel(options.logLevel ?? LogLevel.warn);
38
-
39
- const config: RTCConfiguration = options.rtcConfig ?? {};
40
- if (options.iceServers) {
41
- config.iceServers = options.iceServers;
42
- }
43
-
44
- const room = new Room(options);
45
-
46
- // connect to room
47
- await room.connect(url, token, options);
48
-
49
- const publishAudio: boolean = options.audio ?? false;
50
- const publishVideo: boolean = options.video ?? false;
51
-
52
- if (publishAudio || publishVideo) {
53
- setTimeout(async () => {
54
- // if publishing both
55
- let err: any;
56
- if (publishAudio && publishVideo) {
57
- try {
58
- await room.localParticipant.enableCameraAndMicrophone();
59
- } catch (e) {
60
- const errKind = MediaDeviceFailure.getFailure(e);
61
- log.warn('received error while creating media', errKind);
62
- if (e instanceof Error) {
63
- log.warn(e.message);
64
- }
65
-
66
- // when it's a device issue, try to publish the other kind
67
- if (errKind === MediaDeviceFailure.NotFound
68
- || errKind === MediaDeviceFailure.DeviceInUse) {
69
- try {
70
- await room.localParticipant.setMicrophoneEnabled(true);
71
- } catch (audioErr) {
72
- err = audioErr;
73
- }
74
- } else {
75
- err = e;
76
- }
77
- }
78
- } else if (publishAudio) {
79
- try {
80
- await room.localParticipant.setMicrophoneEnabled(true);
81
- } catch (e) {
82
- err = e;
83
- }
84
- } else if (publishVideo) {
85
- try {
86
- await room.localParticipant.setCameraEnabled(true);
87
- } catch (e) {
88
- err = e;
89
- }
90
- }
91
-
92
- if (err) {
93
- room.emit(RoomEvent.MediaDevicesError, err);
94
- log.error('could not create media', err);
95
- }
96
- });
97
- }
98
-
99
- return room;
100
- }
package/src/index.ts DELETED
@@ -1,47 +0,0 @@
1
- import { setLogLevel } from './logger';
2
- import { DataPacket_Kind, VideoQuality } from './proto/livekit_models';
3
- import LocalParticipant from './room/participant/LocalParticipant';
4
- import Participant, { ConnectionQuality } from './room/participant/Participant';
5
- import { ParticipantTrackPermission } from './room/participant/ParticipantTrackPermission';
6
- import RemoteParticipant from './room/participant/RemoteParticipant';
7
- import Room, { RoomState } from './room/Room';
8
- import LocalAudioTrack from './room/track/LocalAudioTrack';
9
- import LocalTrack from './room/track/LocalTrack';
10
- import LocalTrackPublication from './room/track/LocalTrackPublication';
11
- import LocalVideoTrack from './room/track/LocalVideoTrack';
12
- import RemoteAudioTrack from './room/track/RemoteAudioTrack';
13
- import RemoteTrack from './room/track/RemoteTrack';
14
- import RemoteTrackPublication from './room/track/RemoteTrackPublication';
15
- import RemoteVideoTrack from './room/track/RemoteVideoTrack';
16
- import { TrackPublication } from './room/track/TrackPublication';
17
-
18
- export * from './connect';
19
- export * from './options';
20
- export * from './room/errors';
21
- export * from './room/events';
22
- export * from './room/track/create';
23
- export * from './room/track/options';
24
- export * from './room/track/Track';
25
- export * from './room/track/types';
26
- export * from './version';
27
- export {
28
- setLogLevel,
29
- Room,
30
- RoomState,
31
- DataPacket_Kind,
32
- Participant,
33
- RemoteParticipant,
34
- LocalParticipant,
35
- LocalAudioTrack,
36
- LocalVideoTrack,
37
- LocalTrack,
38
- LocalTrackPublication,
39
- RemoteTrack,
40
- RemoteAudioTrack,
41
- RemoteVideoTrack,
42
- RemoteTrackPublication,
43
- ParticipantTrackPermission,
44
- TrackPublication,
45
- VideoQuality,
46
- ConnectionQuality,
47
- };
package/src/logger.ts DELETED
@@ -1,22 +0,0 @@
1
- import log from 'loglevel';
2
-
3
- export type LogLevelDesc = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
4
-
5
- export enum LogLevel {
6
- trace = 'trace',
7
- debug = 'debug',
8
- info = 'info',
9
- warn = 'warn',
10
- error = 'error',
11
- silent = 'silent',
12
- }
13
-
14
- const livekitLogger = log.getLogger('livekit');
15
-
16
- livekitLogger.setLevel(LogLevel.info);
17
-
18
- export default livekitLogger;
19
-
20
- export function setLogLevel(level: LogLevel | LogLevelDesc) {
21
- livekitLogger.setLevel(level);
22
- }
package/src/options.ts DELETED
@@ -1,149 +0,0 @@
1
- import { LogLevel, LogLevelDesc } from './logger';
2
- import {
3
- AudioCaptureOptions,
4
- CreateLocalTracksOptions,
5
- TrackPublishDefaults,
6
- VideoCaptureOptions,
7
- } from './room/track/options';
8
- import { AdaptiveStreamSettings } from './room/track/types';
9
-
10
- /**
11
- * Options for when creating a new room
12
- */
13
- export interface RoomOptions {
14
- /**
15
- * AdaptiveStream lets LiveKit automatically manage quality of subscribed
16
- * video tracks to optimize for bandwidth and CPU.
17
- * When attached video elements are visible, it'll choose an appropriate
18
- * resolution based on the size of largest video element it's attached to.
19
- *
20
- * When none of the video elements are visible, it'll temporarily pause
21
- * the data flow until they are visible again.
22
- */
23
- adaptiveStream?: AdaptiveStreamSettings | boolean;
24
-
25
- /**
26
- * enable Dynacast, off by default. With Dynacast dynamically pauses
27
- * video layers that are not being consumed by any subscribers, significantly
28
- * reducing publishing CPU and bandwidth usage.
29
- */
30
- dynacast?: boolean;
31
-
32
- /**
33
- * default options to use when capturing user's audio
34
- */
35
- audioCaptureDefaults?: AudioCaptureOptions;
36
-
37
- /**
38
- * default options to use when capturing user's video
39
- */
40
- videoCaptureDefaults?: VideoCaptureOptions;
41
-
42
- /**
43
- * default options to use when publishing tracks
44
- */
45
- publishDefaults?: TrackPublishDefaults;
46
-
47
- /**
48
- * should local tracks be stopped when they are unpublished. defaults to true
49
- * set this to false if you would prefer to clean up unpublished local tracks manually.
50
- */
51
- stopLocalTrackOnUnpublish?: boolean;
52
-
53
- /**
54
- * @internal
55
- * experimental flag, introduce a delay before sending signaling messages
56
- */
57
- expSignalLatency?: number;
58
- }
59
-
60
- /**
61
- * Options for Room.connect()
62
- */
63
- export interface RoomConnectOptions {
64
- /** autosubscribe to room tracks after joining, defaults to true */
65
- autoSubscribe?: boolean;
66
-
67
- /**
68
- * use to override any RTCConfiguration options.
69
- */
70
- rtcConfig?: RTCConfiguration;
71
-
72
- /**
73
- * publish only mode
74
- */
75
- publishOnly?: string;
76
- }
77
-
78
- /**
79
- * if video or audio tracks are created as part of [[connect]], it'll automatically
80
- * publish those tracks to the room.
81
- */
82
- export interface ConnectOptions extends CreateLocalTracksOptions {
83
- /** autosubscribe to room tracks upon connect, defaults to true */
84
- autoSubscribe?: boolean;
85
-
86
- /**
87
- * see [[RoomOptions.adaptiveStream]]
88
- */
89
- adaptiveStream?: AdaptiveStreamSettings | boolean;
90
-
91
- /**
92
- * alias for adaptiveStream
93
- * @deprecated
94
- */
95
- autoManageVideo?: boolean;
96
-
97
- /**
98
- * see [[RoomOptions.dynacast]]
99
- */
100
- dynacast?: boolean;
101
-
102
- /** configures LiveKit internal log level */
103
- logLevel?: LogLevel | LogLevelDesc;
104
-
105
- /**
106
- * set ICE servers. When deployed correctly, LiveKit automatically uses the built-in TURN servers
107
- */
108
- iceServers?: RTCIceServer[];
109
-
110
- /**
111
- * use to override any RTCConfiguration options.
112
- */
113
- rtcConfig?: RTCConfiguration;
114
-
115
- /**
116
- * capture and publish audio track on connect, defaults to false
117
- *
118
- * If this option is used, you will not be notified if user denies capture permission.
119
- */
120
- audio?: boolean;
121
-
122
- /**
123
- * capture and publish video track on connect, defaults to false
124
- *
125
- * If this option is used, you will not be notified if user denies capture permission.
126
- */
127
- video?: boolean;
128
-
129
- /**
130
- * default options to use when capturing user's audio
131
- */
132
- audioCaptureDefaults?: AudioCaptureOptions;
133
-
134
- /**
135
- * default options to use when capturing user's video
136
- */
137
- videoCaptureDefaults?: VideoCaptureOptions;
138
-
139
- /**
140
- * default options to use when publishing tracks
141
- */
142
- publishDefaults?: TrackPublishDefaults;
143
-
144
- /**
145
- * should local tracks be stopped when they are unpublished. defaults to true
146
- * set this to false if you would prefer to clean up unpublished local tracks manually.
147
- */
148
- stopLocalTrackOnUnpublish?: boolean;
149
- }
@@ -1,222 +0,0 @@
1
- /* eslint-disable */
2
- import Long from "long";
3
- import _m0 from "protobufjs/minimal";
4
-
5
- export const protobufPackage = "google.protobuf";
6
-
7
- /**
8
- * A Timestamp represents a point in time independent of any time zone or local
9
- * calendar, encoded as a count of seconds and fractions of seconds at
10
- * nanosecond resolution. The count is relative to an epoch at UTC midnight on
11
- * January 1, 1970, in the proleptic Gregorian calendar which extends the
12
- * Gregorian calendar backwards to year one.
13
- *
14
- * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
15
- * second table is needed for interpretation, using a [24-hour linear
16
- * smear](https://developers.google.com/time/smear).
17
- *
18
- * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
19
- * restricting to that range, we ensure that we can convert to and from [RFC
20
- * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
21
- *
22
- * # Examples
23
- *
24
- * Example 1: Compute Timestamp from POSIX `time()`.
25
- *
26
- * Timestamp timestamp;
27
- * timestamp.set_seconds(time(NULL));
28
- * timestamp.set_nanos(0);
29
- *
30
- * Example 2: Compute Timestamp from POSIX `gettimeofday()`.
31
- *
32
- * struct timeval tv;
33
- * gettimeofday(&tv, NULL);
34
- *
35
- * Timestamp timestamp;
36
- * timestamp.set_seconds(tv.tv_sec);
37
- * timestamp.set_nanos(tv.tv_usec * 1000);
38
- *
39
- * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
40
- *
41
- * FILETIME ft;
42
- * GetSystemTimeAsFileTime(&ft);
43
- * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
44
- *
45
- * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
46
- * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
47
- * Timestamp timestamp;
48
- * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
49
- * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
50
- *
51
- * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
52
- *
53
- * long millis = System.currentTimeMillis();
54
- *
55
- * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
56
- * .setNanos((int) ((millis % 1000) * 1000000)).build();
57
- *
58
- *
59
- * Example 5: Compute Timestamp from Java `Instant.now()`.
60
- *
61
- * Instant now = Instant.now();
62
- *
63
- * Timestamp timestamp =
64
- * Timestamp.newBuilder().setSeconds(now.getEpochSecond())
65
- * .setNanos(now.getNano()).build();
66
- *
67
- *
68
- * Example 6: Compute Timestamp from current time in Python.
69
- *
70
- * timestamp = Timestamp()
71
- * timestamp.GetCurrentTime()
72
- *
73
- * # JSON Mapping
74
- *
75
- * In JSON format, the Timestamp type is encoded as a string in the
76
- * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
77
- * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
78
- * where {year} is always expressed using four digits while {month}, {day},
79
- * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
80
- * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
81
- * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
82
- * is required. A proto3 JSON serializer should always use UTC (as indicated by
83
- * "Z") when printing the Timestamp type and a proto3 JSON parser should be
84
- * able to accept both UTC and other timezones (as indicated by an offset).
85
- *
86
- * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
87
- * 01:30 UTC on January 15, 2017.
88
- *
89
- * In JavaScript, one can convert a Date object to this format using the
90
- * standard
91
- * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
92
- * method. In Python, a standard `datetime.datetime` object can be converted
93
- * to this format using
94
- * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
95
- * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
96
- * the Joda Time's [`ISODateTimeFormat.dateTime()`](
97
- * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
98
- * ) to obtain a formatter capable of generating timestamps in this format.
99
- */
100
- export interface Timestamp {
101
- /**
102
- * Represents seconds of UTC time since Unix epoch
103
- * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
104
- * 9999-12-31T23:59:59Z inclusive.
105
- */
106
- seconds: number;
107
- /**
108
- * Non-negative fractions of a second at nanosecond resolution. Negative
109
- * second values with fractions must still have non-negative nanos values
110
- * that count forward in time. Must be from 0 to 999,999,999
111
- * inclusive.
112
- */
113
- nanos: number;
114
- }
115
-
116
- const baseTimestamp: object = { seconds: 0, nanos: 0 };
117
-
118
- export const Timestamp = {
119
- encode(
120
- message: Timestamp,
121
- writer: _m0.Writer = _m0.Writer.create()
122
- ): _m0.Writer {
123
- if (message.seconds !== 0) {
124
- writer.uint32(8).int64(message.seconds);
125
- }
126
- if (message.nanos !== 0) {
127
- writer.uint32(16).int32(message.nanos);
128
- }
129
- return writer;
130
- },
131
-
132
- decode(input: _m0.Reader | Uint8Array, length?: number): Timestamp {
133
- const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
134
- let end = length === undefined ? reader.len : reader.pos + length;
135
- const message = { ...baseTimestamp } as Timestamp;
136
- while (reader.pos < end) {
137
- const tag = reader.uint32();
138
- switch (tag >>> 3) {
139
- case 1:
140
- message.seconds = longToNumber(reader.int64() as Long);
141
- break;
142
- case 2:
143
- message.nanos = reader.int32();
144
- break;
145
- default:
146
- reader.skipType(tag & 7);
147
- break;
148
- }
149
- }
150
- return message;
151
- },
152
-
153
- fromJSON(object: any): Timestamp {
154
- const message = { ...baseTimestamp } as Timestamp;
155
- if (object.seconds !== undefined && object.seconds !== null) {
156
- message.seconds = Number(object.seconds);
157
- } else {
158
- message.seconds = 0;
159
- }
160
- if (object.nanos !== undefined && object.nanos !== null) {
161
- message.nanos = Number(object.nanos);
162
- } else {
163
- message.nanos = 0;
164
- }
165
- return message;
166
- },
167
-
168
- toJSON(message: Timestamp): unknown {
169
- const obj: any = {};
170
- message.seconds !== undefined && (obj.seconds = message.seconds);
171
- message.nanos !== undefined && (obj.nanos = message.nanos);
172
- return obj;
173
- },
174
-
175
- fromPartial(object: DeepPartial<Timestamp>): Timestamp {
176
- const message = { ...baseTimestamp } as Timestamp;
177
- message.seconds = object.seconds ?? 0;
178
- message.nanos = object.nanos ?? 0;
179
- return message;
180
- },
181
- };
182
-
183
- declare var self: any | undefined;
184
- declare var window: any | undefined;
185
- declare var global: any | undefined;
186
- var globalThis: any = (() => {
187
- if (typeof globalThis !== "undefined") return globalThis;
188
- if (typeof self !== "undefined") return self;
189
- if (typeof window !== "undefined") return window;
190
- if (typeof global !== "undefined") return global;
191
- throw "Unable to locate global object";
192
- })();
193
-
194
- type Builtin =
195
- | Date
196
- | Function
197
- | Uint8Array
198
- | string
199
- | number
200
- | boolean
201
- | undefined;
202
- export type DeepPartial<T> = T extends Builtin
203
- ? T
204
- : T extends Array<infer U>
205
- ? Array<DeepPartial<U>>
206
- : T extends ReadonlyArray<infer U>
207
- ? ReadonlyArray<DeepPartial<U>>
208
- : T extends {}
209
- ? { [K in keyof T]?: DeepPartial<T[K]> }
210
- : Partial<T>;
211
-
212
- function longToNumber(long: Long): number {
213
- if (long.gt(Number.MAX_SAFE_INTEGER)) {
214
- throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
215
- }
216
- return long.toNumber();
217
- }
218
-
219
- if (_m0.util.Long !== Long) {
220
- _m0.util.Long = Long as any;
221
- _m0.configure();
222
- }