openvibers/openvibe.live Commits
Go-live fan-out to Network uses Live's service token (network.notifications.push) with the internal key as fallback
Changes
@@@ -18,7 +18,7 @@ const CLIENT_SECRET = process.env.OV_OAUTH_CLIENT_SECRET || '';const PAUSE_MS = 5 * 60 * 1000;// Network routes that accept a service token (OpenVibe.Network server/internal/routes.js TOKEN_ROUTES).--const TOKEN_PATHS = new Set(['/internal/coins/credit', '/internal/coins/debit', '/internal/coins/transfer', '/internal/notifications/push', '/internal/notifications/push-bulk']);++const TOKEN_PATHS = new Set(['/internal/coins/credit', '/internal/coins/debit', '/internal/coins/transfer', '/internal/notifications/push', '/internal/notifications/push-bulk', '/internal/events/stream-live']);const _clients = new Map();/** One cached client-credentials token client per audience (openvibe.network, openvibe.community, ...). */@@@ -56,12 +56,15 @@ function notifyFollowersGoLive(streamer, stream, { force = false } = {}) {follower_network_ids: followerNetworkIds,};-- if (!INTERNAL_API_KEY) { _fallback(streamer, stream, followerNetworkIds); return; }-- fetch(`${OV_NETWORK_INTERNAL_URL}/internal/events/stream-live`, {++ if (!INTERNAL_API_KEY && !process.env.OV_OAUTH_CLIENT_SECRET) { _fallback(streamer, stream, followerNetworkIds); return; }++ // Service token (network.notifications.push) when Network grants it, the internal key otherwise.++ const principal = require('../net/network-principal');++ principal.headersFor('/internal/events/stream-live').then((auth) => fetch(`${OV_NETWORK_INTERNAL_URL}/internal/events/stream-live`, {method: 'POST',-- headers: { 'Content-Type': 'application/json', 'X-Internal-Key': INTERNAL_API_KEY },++ headers: { 'Content-Type': 'application/json', ...auth },body: JSON.stringify(payload),-- }).then(async (r) => {++ })).then(async (r) => {++ if (r.status === 401) principal.tokenRejected('stream-live');if (r.ok) {let d = null; try { d = await r.json(); } catch { /* */ }if (d && d.skipped) { console.log(`[GoLive] ${streamer.username}: network skipped announcement (${d.reason}${d.next_allowed_at ? `, next ${d.next_allowed_at}` : ''})`); return; }
@@ -18,7 +18,7 @@ const CLIENT_SECRET = process.env.OV_OAUTH_CLIENT_SECRET || '';
@@ -18,7 +18,7 @@ const CLIENT_SECRET = process.env.OV_OAUTH_CLIENT_SECRET || '';
const PAUSE_MS = 5 * 60 * 1000;
const PAUSE_MS = 5 * 60 * 1000;
// Network routes that accept a service token (OpenVibe.Network server/internal/routes.js TOKEN_ROUTES).
// Network routes that accept a service token (OpenVibe.Network server/internal/routes.js TOKEN_ROUTES).
-const TOKEN_PATHS = new Set(['/internal/coins/credit', '/internal/coins/debit', '/internal/coins/transfer', '/internal/notifications/push', '/internal/notifications/push-bulk']);
+const TOKEN_PATHS = new Set(['/internal/coins/credit', '/internal/coins/debit', '/internal/coins/transfer', '/internal/notifications/push', '/internal/notifications/push-bulk', '/internal/events/stream-live']);
const _clients = new Map();
const _clients = new Map();
/** One cached client-credentials token client per audience (openvibe.network, openvibe.community, ...). */
/** One cached client-credentials token client per audience (openvibe.network, openvibe.community, ...). */
@@ -56,12 +56,15 @@ function notifyFollowersGoLive(streamer, stream, { force = false } = {}) {
@@ -56,12 +56,15 @@ function notifyFollowersGoLive(streamer, stream, { force = false } = {}) {
follower_network_ids: followerNetworkIds,
follower_network_ids: followerNetworkIds,
};
};
- if (!INTERNAL_API_KEY) { _fallback(streamer, stream, followerNetworkIds); return; }
- fetch(`${OV_NETWORK_INTERNAL_URL}/internal/events/stream-live`, {
+ if (!INTERNAL_API_KEY && !process.env.OV_OAUTH_CLIENT_SECRET) { _fallback(streamer, stream, followerNetworkIds); return; }
+ // Service token (network.notifications.push) when Network grants it, the internal key otherwise.
+ const principal = require('../net/network-principal');
+ principal.headersFor('/internal/events/stream-live').then((auth) => fetch(`${OV_NETWORK_INTERNAL_URL}/internal/events/stream-live`, {
method: 'POST',
method: 'POST',
- headers: { 'Content-Type': 'application/json', 'X-Internal-Key': INTERNAL_API_KEY },
+ headers: { 'Content-Type': 'application/json', ...auth },
body: JSON.stringify(payload),
body: JSON.stringify(payload),
- }).then(async (r) => {
+ })).then(async (r) => {
+ if (r.status === 401) principal.tokenRejected('stream-live');
if (r.ok) {
if (r.ok) {
let d = null; try { d = await r.json(); } catch { /* */ }
let d = null; try { d = await r.json(); } catch { /* */ }
if (d && d.skipped) { console.log(`[GoLive] ${streamer.username}: network skipped announcement (${d.reason}${d.next_allowed_at ? `, next ${d.next_allowed_at}` : ''})`); return; }
if (d && d.skipped) { console.log(`[GoLive] ${streamer.username}: network skipped announcement (${d.reason}${d.next_allowed_at ? `, next ${d.next_allowed_at}` : ''})`); return; }