feat: 添加获取 token 逻辑
parent
be552b8c11
commit
b7eab7c290
|
@ -1,5 +1,5 @@
|
||||||
const app = getApp()
|
|
||||||
const Utils = require('../../utils/util.js')
|
const Utils = require('../../utils/util.js')
|
||||||
|
const { APPID, setToken } = require("../../utils/config.js");
|
||||||
|
|
||||||
// pages/index/index.js.js
|
// pages/index/index.js.js
|
||||||
Page({
|
Page({
|
||||||
|
@ -29,6 +29,26 @@ Page({
|
||||||
userInfo: userInfo
|
userInfo: userInfo
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wx.request({
|
||||||
|
url: 'https://finogeeks-tools.finogeeks.club/test-report/agora/token',
|
||||||
|
method: 'post',
|
||||||
|
data: {
|
||||||
|
appId: APPID,
|
||||||
|
channel: 'finclip'
|
||||||
|
},
|
||||||
|
success(res) {
|
||||||
|
if (res.statusCode === 200 && res.data.token) {
|
||||||
|
setToken(res.data.token)
|
||||||
|
} else {
|
||||||
|
wx.showToast({
|
||||||
|
title: `获取 token 失败`,
|
||||||
|
icon: 'none',
|
||||||
|
duration: 5000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,4 +154,4 @@ Page({
|
||||||
let value = e.detail.value;
|
let value = e.detail.value;
|
||||||
this.channel = value;
|
this.channel = value;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,11 +4,10 @@ const Utils = require('../../utils/util.js')
|
||||||
// 微信平台 SDK
|
// 微信平台 SDK
|
||||||
// const AgoraMiniappSDK = require("../../lib/mini-app-sdk-production.js");
|
// const AgoraMiniappSDK = require("../../lib/mini-app-sdk-production.js");
|
||||||
// 凡泰平台 SDK
|
// 凡泰平台 SDK
|
||||||
const AgoraMiniappSDK = require("../../lib/finclip-agora-client-sdk.js");
|
const AgoraMiniappSDK = require("../../lib/finclip-agora-client-sdk");
|
||||||
const max_user = 10;
|
const max_user = 10;
|
||||||
const Layouter = require("../../utils/layout.js");
|
const Layouter = require("../../utils/layout.js");
|
||||||
const APPID = require("../../utils/config.js").APPID;
|
const { APPID, getToken } = require("../../utils/config.js");
|
||||||
const TOKEN = require("../../utils/config.js").TOKEN;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* log relevant, remove these part and relevant code if not needed
|
* log relevant, remove these part and relevant code if not needed
|
||||||
|
@ -558,13 +557,10 @@ Page({
|
||||||
let client = {}
|
let client = {}
|
||||||
if (this.testEnv) {
|
if (this.testEnv) {
|
||||||
client = new AgoraMiniappSDK.Client({
|
client = new AgoraMiniappSDK.Client({
|
||||||
debug: true,
|
|
||||||
servers: ["wss://miniapp.agoraio.cn/120-131-14-112/api"]
|
servers: ["wss://miniapp.agoraio.cn/120-131-14-112/api"]
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
client = new AgoraMiniappSDK.Client({
|
client = new AgoraMiniappSDK.Client()
|
||||||
debug: true
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
//subscribe stream events
|
//subscribe stream events
|
||||||
this.subscribeEvents(client);
|
this.subscribeEvents(client);
|
||||||
|
@ -576,8 +572,7 @@ Page({
|
||||||
this.client = client;
|
this.client = client;
|
||||||
client.init(APPID, () => {
|
client.init(APPID, () => {
|
||||||
Utils.log(`client init success`);
|
Utils.log(`client init success`);
|
||||||
// pass key instead of undefined if certificate is enabled
|
client.join(getToken(), channel, uid, () => {
|
||||||
client.join(TOKEN, channel, uid, () => {
|
|
||||||
client.setRole(this.role);
|
client.setRole(this.role);
|
||||||
Utils.log(`client join channel success`);
|
Utils.log(`client join channel success`);
|
||||||
//and get my stream publish url
|
//and get my stream publish url
|
||||||
|
@ -629,7 +624,7 @@ Page({
|
||||||
Utils.log(`client init success`);
|
Utils.log(`client init success`);
|
||||||
// pass key instead of undefined if certificate is enabled
|
// pass key instead of undefined if certificate is enabled
|
||||||
Utils.log(`rejoin with uids: ${JSON.stringify(uids)}`);
|
Utils.log(`rejoin with uids: ${JSON.stringify(uids)}`);
|
||||||
client.rejoin(TOKEN, channel, uid, uids, () => {
|
client.rejoin(getToken(), channel, uid, uids, () => {
|
||||||
Utils.log(`client join channel success`);
|
Utils.log(`client join channel success`);
|
||||||
if (this.isBroadcaster()) {
|
if (this.isBroadcaster()) {
|
||||||
client.publish(url => {
|
client.publish(url => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const APPID = "1fa54c6d47074eea98833162a292497a";
|
const APPID = "1fa54c6d47074eea98833162a292497a";
|
||||||
const TOKEN = "";
|
let token = '';
|
||||||
|
|
||||||
if(APPID === ""){
|
if(APPID === ""){
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
|
@ -11,5 +11,10 @@ if(APPID === ""){
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
APPID: APPID,
|
APPID: APPID,
|
||||||
TOKEN: TOKEN
|
getToken() {
|
||||||
|
return token;
|
||||||
|
},
|
||||||
|
setToken(val) {
|
||||||
|
token = val;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue