@pbvision/partner-sdk 0.1.18 → 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.
- package/README.md +19 -0
- package/package.json +1 -1
- package/src/index.js +42 -0
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)
|
|
@@ -342,6 +343,24 @@ shows a page for installing it.
|
|
|
342
343
|
**Testing.** Links from the test server (`useProdServer: false`) start with
|
|
343
344
|
`pbvision://record` and need a development build of the PB Vision app.
|
|
344
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
|
+
|
|
345
364
|
### Video Editors and Viewers
|
|
346
365
|
|
|
347
366
|
Editors can tag themselves and friends in the video. Viewers have read-only
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -359,6 +359,48 @@ export class PBVision {
|
|
|
359
359
|
return { vid, uid, url: `${this.recordUrl}?${query}` }
|
|
360
360
|
}
|
|
361
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
|
+
|
|
362
404
|
/**
|
|
363
405
|
* Upload a video for processing by the AI.
|
|
364
406
|
*
|