@pbvision/partner-sdk 0.1.17 → 0.1.19

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 (3) hide show
  1. package/README.md +24 -2
  2. package/package.json +1 -1
  3. package/src/index.js +76 -5
package/README.md CHANGED
@@ -19,6 +19,7 @@ standard length game, so we'll notify your servers when the results are ready.
19
19
  - [Auto-tagging players](#auto-tagging-players)
20
20
  - [Folders](#folders)
21
21
  - [Recording with the PB Vision app](#recording-with-the-pb-vision-app)
22
+ - [Reporting a game's score](#reporting-a-games-score)
22
23
  - [Video Editors and Viewers](#video-editors-and-viewers)
23
24
  - [After Video Processing is Done](#after-video-processing-is-done)
24
25
  - [Callback Data](#callback-data)
@@ -316,12 +317,15 @@ person recording can't change either. Ask for 4K with `resolution: '4k'` or
316
317
  60 FPS with `fps: 60`; with `mayChangeResolution: true` or `mayChangeFPS: true`
317
318
  the person recording may choose lower settings. Phones step down to what they
318
319
  support, and recorders don't need a PB Vision subscription. 4K requires your
319
- partner account to have 4K enabled.
320
+ partner account to have 4K enabled, since PB Vision doesn't analyze video above
321
+ 1080p without it. `getMyPartnerAccountInfo()` says whether yours does, and
322
+ without it `makeRecordingLink()` refuses `resolution: '4k'`.
320
323
 
321
324
  ```javascript
325
+ const { is4K } = await pbv.getMyPartnerAccountInfo();
322
326
  const { url } = await pbv.makeRecordingLink({
323
327
  fid,
324
- resolution: '4k', // '1080p' (default) or '4k'
328
+ resolution: is4K ? '4k' : '1080p', // '1080p' (default) or '4k'
325
329
  fps: 60, // 30 (default) or 60
326
330
  mayChangeResolution: true, // default false
327
331
  mayChangeFPS: false // default false
@@ -339,6 +343,24 @@ shows a page for installing it.
339
343
  **Testing.** Links from the test server (`useProdServer: false`) start with
340
344
  `pbvision://record` and need a development build of the PB Vision app.
341
345
 
346
+ ### Reporting a game's score
347
+
348
+ If you know a game's final score, report it with `setGameScore()` and PB
349
+ Vision shows it with the game. Name each team by its role at the game's first
350
+ serve, as in [`playersForTagging`](#auto-tagging-players): the team that served
351
+ the first point, and the team that received it. Give the video by its `vid` or
352
+ by the `nonce` you made it with.
353
+
354
+ ```javascript
355
+ await pbv.setGameScore({ nonce: `${eventId}-${gameId}`, server: 11, receiver: 7 });
356
+ ```
357
+
358
+ You can report before the video is processed, or even recorded: the game gets
359
+ the score when processing finishes, and the response's `applied` says whether
360
+ it has it yet. Report again to correct a score; the latest report wins. Each
361
+ team's result is its points, or `'won'` or `'lost'` if that is all you know.
362
+ The score is for a video of one game.
363
+
342
364
  ### Video Editors and Viewers
343
365
 
344
366
  Editors can tag themselves and friends in the video. Viewers have read-only
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pbvision/partner-sdk",
3
3
  "description": "SDK for interacting with the PB Vision pickleball AI engine.",
4
- "version": "0.1.17",
4
+ "version": "0.1.19",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "engines": {
package/src/index.js CHANGED
@@ -68,6 +68,26 @@ export class PBVision {
68
68
  this.isDev = config === ENVIRONMENTS.test
69
69
  }
70
70
 
71
+ /**
72
+ * @typedef {Object} PartnerAccountInfo
73
+ * @property {boolean} is4K whether your partner account may upload video
74
+ * above 1080p. Without 4K, PB Vision does not analyze such a video.
75
+ */
76
+
77
+ /**
78
+ * Tells you what your partner account may do, e.g. whether to offer 4K.
79
+ *
80
+ * @returns {PartnerAccountInfo}
81
+ */
82
+ async getMyPartnerAccountInfo () {
83
+ const resp = await this.__callAPI('about', {})
84
+ const { is4K } = JSON.parse(resp)
85
+ if (is4K) {
86
+ this.__is4K = true
87
+ }
88
+ return { is4K }
89
+ }
90
+
71
91
  /**
72
92
  * Tells PB Vision to make an HTTP POST request your URL after each of your
73
93
  * videos is done processing.
@@ -274,9 +294,10 @@ export class PBVision {
274
294
  * By default the app records at 1080p and 30 FPS, and the person recording
275
295
  * can't change either. A phone that can't record what the link asks for
276
296
  * steps down to the best quality it supports. The link's settings apply
277
- * regardless of the recorder's own PB Vision subscription, but 4K requires
278
- * your partner account to have 4K enabled; otherwise PB Vision rejects the
279
- * upload.
297
+ * regardless of the recorder's own PB Vision subscription. 4K requires your
298
+ * partner account to have 4K enabled (see getMyPartnerAccountInfo()), so
299
+ * without it this refuses a 4K link rather than make a video PB Vision
300
+ * won't analyze.
280
301
  *
281
302
  * Each link is for one recording: only the first upload to its video
282
303
  * counts, so make a new link for each game. If several people may ask for
@@ -293,8 +314,9 @@ export class PBVision {
293
314
  * @param {RecordingLinkOptions} [options]
294
315
  * @returns {RecordingLink}
295
316
  * @throws {Error} if gameStartEpoch is given, a camera setting is invalid,
296
- * or PB Vision doesn't make the video (e.g. because the account paying for
297
- * it can't pay for it)
317
+ * 4K is asked for and your partner account doesn't have 4K, or PB Vision
318
+ * doesn't make the video (e.g. because the account paying for it can't
319
+ * pay for it)
298
320
  */
299
321
  async makeRecordingLink ({
300
322
  resolution = '1080p', fps = 30, mayChangeResolution = false, mayChangeFPS = false,
@@ -308,6 +330,13 @@ export class PBVision {
308
330
  assert(typeof mayChangeResolution === 'boolean', 'mayChangeResolution must be a boolean')
309
331
  assert(typeof mayChangeFPS === 'boolean', 'mayChangeFPS must be a boolean')
310
332
 
333
+ // checked before making the video, so a 4K link that PB Vision wouldn't
334
+ // analyze never gets one; only a yes is remembered, so an account that
335
+ // gets 4K later can ask for it without a new PBVision
336
+ if (resolution === '4k' && !this.__is4K && !(await this.getMyPartnerAccountInfo()).is4K) {
337
+ throw new Error('your partner account does not have 4K enabled, so PB Vision would not analyze a 4K recording; ask for 1080p, or ask PB Vision to enable 4K')
338
+ }
339
+
311
340
  const { vid, uid, hasCredits } = await this.makeVideoId({
312
341
  fileExt: 'mp4', userEmails, name, desc, facility, court, fid, playersForTagging, nonce })
313
342
  if (hasCredits === false) {
@@ -330,6 +359,48 @@ export class PBVision {
330
359
  return { vid, uid, url: `${this.recordUrl}?${query}` }
331
360
  }
332
361
 
362
+ /**
363
+ * One team's result in a game: the points it scored, `'won'` or `'lost'`
364
+ * when that is all you know, or `null` when you don't know it.
365
+ *
366
+ * @typedef {number|'won'|'lost'|null} TeamResult
367
+ */
368
+
369
+ /**
370
+ * @typedef {Object} SetGameScoreResponse
371
+ * @property {string} vid the video
372
+ * @property {boolean} applied whether the game has the score yet; false
373
+ * while the video awaits processing, which gives the game the score when
374
+ * it finishes
375
+ */
376
+
377
+ /**
378
+ * Reports the final score of a game you recorded, for a video of one game
379
+ * that your partner account owns. Name each team by its role at the game's
380
+ * first serve, as playersForTagging names the players: the team that
381
+ * served the first point, and the team that received it. You can report
382
+ * before the video is processed, or even recorded. Report again to correct
383
+ * it: the latest report wins.
384
+ *
385
+ * @param {Object} score
386
+ * @param {string} [score.vid] the video; give this or nonce
387
+ * @param {string} [score.nonce] the nonce you made the video with; give
388
+ * this or vid
389
+ * @param {TeamResult} score.server the result of the team that served the
390
+ * game's first point
391
+ * @param {TeamResult} score.receiver the result of the team that received
392
+ * it
393
+ * @returns {SetGameScoreResponse}
394
+ */
395
+ async setGameScore ({ vid, nonce, server, receiver }) {
396
+ assert((vid === undefined) !== (nonce === undefined), 'give either vid or nonce')
397
+ const isResult = x => x === null || x === 'won' || x === 'lost' || (Number.isInteger(x) && x >= 0)
398
+ assert(isResult(server) && isResult(receiver),
399
+ 'each team\'s result must be its points, \'won\', \'lost\' or null')
400
+ const resp = await this.__callAPI('video/score/set', { vid, nonce, server, receiver })
401
+ return JSON.parse(resp)
402
+ }
403
+
333
404
  /**
334
405
  * Upload a video for processing by the AI.
335
406
  *